probe modify

This commit is contained in:
insanity 2017-08-22 18:40:39 +09:00
parent fbfbdaede5
commit b2fb18cd26
7 changed files with 94 additions and 3 deletions

View File

@ -7,6 +7,7 @@ import signUpReducer from '@overflow/member/redux/reducer/signUp';
import readAllProbeReducer from '@overflow/probe/redux/reducer/readAllByDomain'; import readAllProbeReducer from '@overflow/probe/redux/reducer/readAllByDomain';
import readProbeReducer from '@overflow/probe/redux/reducer/read'; import readProbeReducer from '@overflow/probe/redux/reducer/read';
import hostReadByProbeReducer from '@overflow/probe/redux/reducer/host_read_by_probe'; import hostReadByProbeReducer from '@overflow/probe/redux/reducer/host_read_by_probe';
import modifyProbeReducer from '@overflow/probe/redux/reducer/modify';
import readNoAuthProbeReducer from '@overflow/noauthprobe/redux/reducer/read_all_by_domain'; import readNoAuthProbeReducer from '@overflow/noauthprobe/redux/reducer/read_all_by_domain';
import noauthAcceptReducer from '@overflow/noauthprobe/redux/reducer/accept'; import noauthAcceptReducer from '@overflow/noauthprobe/redux/reducer/accept';
@ -89,6 +90,7 @@ const reduxConfig: ReduxConfig = {
hostReadByProbeReducer, hostReadByProbeReducer,
noauthAcceptReducer, noauthAcceptReducer,
noauthDenyReducer, noauthDenyReducer,
modifyProbeReducer,
], ],
sagaWatchers: [ sagaWatchers: [
AsyncRequest, AsyncRequest,

View File

@ -8,6 +8,7 @@ import { push as routerPush } from 'react-router-redux';
import Probe from '@overflow/probe/api/model/Probe'; import Probe from '@overflow/probe/api/model/Probe';
import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest'; import * as asyncRequestActions from '@overflow/commons/redux/action/asyncRequest';
import * as probeReadActions from '../redux/action/read'; import * as probeReadActions from '../redux/action/read';
import * as probeModifyActions from '../redux/action/modify';
export function mapStateToProps(state: any, props: any): ProbeDetailStateProps { export function mapStateToProps(state: any, props: any): ProbeDetailStateProps {
return { return {
@ -24,6 +25,9 @@ export function mapDispatchToProps(dispatch: Dispatch<any>): ProbeDetailDispatch
onDiscoveryClick: (id: string) => { onDiscoveryClick: (id: string) => {
dispatch(routerPush(id + '/ targets')); dispatch(routerPush(id + '/ targets'));
}, },
onModify: (probe: Probe) => {
dispatch(asyncRequestActions.request('ProbeService', 'modify', probeModifyActions.REQUEST, JSON.stringify(probe)));
},
}; };
} }

View File

@ -6,6 +6,10 @@ import {
Segment, Segment,
Header, Header,
Container, Container,
Input,
InputOnChangeData,
Loader,
Dimmer,
} from 'semantic-ui-react'; } from 'semantic-ui-react';
import Probe from '@overflow/probe/api/model/Probe'; import Probe from '@overflow/probe/api/model/Probe';
import { Discovery } from '@overflow/discovery/react/components/Discovery'; import { Discovery } from '@overflow/discovery/react/components/Discovery';
@ -19,12 +23,15 @@ export interface StateProps {
export interface DispatchProps { export interface DispatchProps {
onRead?(id: string): void; onRead?(id: string): void;
onDiscoveryClick?(id:string):void; onDiscoveryClick?(id: string): void;
onModify?(probe: Probe): void;
} }
export type Props = StateProps & DispatchProps; export type Props = StateProps & DispatchProps;
export interface State { export interface State {
name: string;
desc: string;
} }
@ -33,6 +40,8 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
constructor(props: Props, context: State) { constructor(props: Props, context: State) {
super(props, context); super(props, context);
this.state = { this.state = {
name: undefined,
desc: undefined,
}; };
} }
@ -55,6 +64,19 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
} }
} }
public handleNameModify = () => {
const p: Probe = this.props.probe;
p.displayName = this.state.name;
this.props.onModify(p);
}
public handleDescModify = () => {
let p: Probe = this.props.probe;
p.description = this.state.desc;
this.props.onModify(p);
}
public render(): JSX.Element { public render(): JSX.Element {
if (this.props.probe === undefined) { if (this.props.probe === undefined) {
return null; return null;
@ -67,7 +89,13 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Name</Header> <Header size='small'>Name</Header>
</Table.Cell> </Table.Cell>
<Table.Cell>{this.props.probe.displayName}</Table.Cell> <Table.Cell>
<Input action={{ color: 'teal', icon: 'edit', onClick: this.handleNameModify.bind(this) }}
defaultValue={this.props.probe.displayName} size='small' onChange={
(event: React.SyntheticEvent<HTMLInputElement>, data: InputOnChangeData) => {
this.setState({ name: data.value });
}} />
</Table.Cell>
</Table.Row> </Table.Row>
<Table.Row> <Table.Row>
<Table.Cell collapsing> <Table.Cell collapsing>
@ -103,7 +131,13 @@ export class ProbeDetailInfo extends React.Component<Props, State> {
<Table.Cell collapsing> <Table.Cell collapsing>
<Header size='small'>Description</Header> <Header size='small'>Description</Header>
</Table.Cell> </Table.Cell>
<Table.Cell>{this.props.probe.description}</Table.Cell> <Table.Cell>
<Input action={{ color: 'teal', icon: 'edit', onClick: this.handleDescModify }}
defaultValue={this.props.probe.description} size='small' onChange={
(event: React.SyntheticEvent<HTMLInputElement>, data: InputOnChangeData) => {
this.setState({ desc: data.value });
}} />
</Table.Cell>
</Table.Row> </Table.Row>
</Table.Body> </Table.Body>
</Table> </Table>

View File

@ -0,0 +1,7 @@
export type REQUEST = '@overflow/probe/modify/REQUEST';
export type REQUEST_SUCCESS = '@overflow/probe/modify/REQUEST/SUCCESS';
export type REQUEST_FAILURE = '@overflow/probe/modify/REQUEST/FAILURE';
export const REQUEST: REQUEST = '@overflow/probe/modify/REQUEST';
export const REQUEST_SUCCESS: REQUEST_SUCCESS = '@overflow/probe/modify/REQUEST/SUCCESS';
export const REQUEST_FAILURE: REQUEST_FAILURE = '@overflow/probe/modify/REQUEST/FAILURE';

View File

@ -0,0 +1,7 @@
import Probe from '../../api/model/Probe';
interface ModifyPayload {
probe: Probe;
}
export default ModifyPayload;

View File

@ -0,0 +1,24 @@
import Action from '@overflow/commons/redux/Action';
import { ReducersMapObject } from 'redux';
import Probe from '@overflow/probe/api/model/Probe';
import * as ModifyActionTypes from '../action/modify';
import ModifyState, { defaultState as modifyDefaultState } from '../state/Modify';
const reducer: ReducersMapObject = {
[ModifyActionTypes.REQUEST_SUCCESS]:
(state: ModifyState = modifyDefaultState, action: Action<Probe>):
ModifyState => {
return {
...state,
probe: <Probe>action.payload,
};
},
[ModifyActionTypes.REQUEST_FAILURE]:
(state: ModifyState = modifyDefaultState, action: Action<Error>):
ModifyState => {
return state;
},
};
export default reducer;

View File

@ -0,0 +1,13 @@
import Probe from '../../api/model/Probe';
export interface State {
readonly probe?: Probe;
readonly error?: Error;
}
export const defaultState: State = {
probe: undefined,
error: undefined,
};
export default State;