This commit is contained in:
insanity 2017-08-25 12:22:54 +09:00
parent 639b803b47
commit 33d0b896aa
2 changed files with 18 additions and 82 deletions

View File

@ -11,7 +11,7 @@ class HistoryList extends React.Component<RouteComponentProps<object>, object> {
public render(): JSX.Element {
return (
<div>
<HistoryListContainer params={this.props.match.path}/>
<HistoryListContainer params={this.props.match.url}/>
</div>
);
}

View File

@ -50,7 +50,7 @@ export class HistoryList extends React.Component<Props, State> {
id: 1,
};
this.props.onReadAllProbeByDomain(domain);
this.props.onReadAllMetaHistoryType();
// this.props.onReadAllMetaHistoryType();
if (this.props.path === '/histories') {
this.setState({
@ -80,11 +80,11 @@ export class HistoryList extends React.Component<Props, State> {
}
public getTypedHistory(pageNo: number): void {
let url = this.props.path.split('/');
let probe: Probe = {
id: this.selectedProbeId,
id: url[2],
};
let type = this.props.path.split('/')[1];
this.props.onReadAllByProbeAndType(probe, this.getMetaType(type), String(pageNo), String(this.countPerPage));
this.props.onReadAllByProbeAndType(probe, this.getMetaType(url[1]), String(pageNo), String(this.countPerPage));
}
public getMetaType(typeStr: string): MetaHistoryType {
@ -136,20 +136,20 @@ export class HistoryList extends React.Component<Props, State> {
{this.props.histories && this.props.histories.content ?
this.props.histories.content.map((history: History, index: number) => (
<Table.Row key={index} >
<Table.Cell textAlign={'center'} collapsing>{history.id}</Table.Cell>
<Table.Cell textAlign={'center'} collapsing>
<Table.Cell textAlign={'center'}>{history.id}</Table.Cell>
<Table.Cell >
{history.probe.displayName}
</Table.Cell>
<Table.Cell textAlign={'center'} collapsing>
<Table.Cell textAlign={'center'}>
{history.type.name}
</Table.Cell>
<Table.Cell>
{history.message}
</Table.Cell>
<Table.Cell collapsing>
<Table.Cell>
{history.createDate}
</Table.Cell>
<Table.Cell collapsing>
<Table.Cell>
{history.member.name}
</Table.Cell>
</Table.Row>
@ -166,11 +166,12 @@ export class HistoryList extends React.Component<Props, State> {
</Container>
);
let filter = <HistoryFilter probes={this.props.probes}
onProbeChange={this.handleProbeChange}
historyTypes={this.props.historyTypes}
onTypeChange={this.handleTypeChange}
/>;
let filter = null;
if (!this.state.isTypedHistory) {
filter = <HistoryFilter probes={this.props.probes}
onProbeChange={this.handleProbeChange}
/>;
}
return (
<ListContainer
filter={filter}
@ -180,46 +181,11 @@ export class HistoryList extends React.Component<Props, State> {
);
}
// todo. refactoring
private handleProbeChange = (probeId: number) => {
this.selectedProbeId = probeId;
this.getHistoryByFilter();
}
// todo. refactoring
private handleTypeChange = (typeId: number) => {
this.selectedTypeId = typeId;
this.getHistoryByFilter();
}
// todo. refactoring
private getHistoryByFilter = () => {
if (this.selectedProbeId === 0) {
// readAllByDomain or readAllByDomainAndType
const domain: Domain = {
id: 1,
};
if (this.selectedTypeId === 0) {
this.props.onReadAllByDomain(domain, String(0), String(this.countPerPage));
} else {
const type: MetaHistoryType = {
id: this.selectedTypeId,
};
this.props.onReadAllByDomainAndType(domain, type, String(0), String(this.countPerPage));
}
} else {
// readAllByProbe or readAllByProbeAndType
const probe: Probe = {
id: this.selectedProbeId,
};
if (this.selectedTypeId === 0) {
this.props.onReadAllByProbe(probe, String(0), String(this.countPerPage));
} else {
const type: MetaHistoryType = {
id: this.selectedTypeId,
};
this.props.onReadAllByProbeAndType(probe, type, String(0), String(this.countPerPage));
}
}
this.getAllHistory(0);
}
}
@ -227,14 +193,11 @@ export class HistoryList extends React.Component<Props, State> {
export interface FilterProps {
probes: Probe[];
historyTypes: MetaHistoryType[];
onProbeChange(probeId: number): void;
onTypeChange(typeId: number): void;
}
export interface FilterState {
selectedProbeId: number;
selectedTypeId: number;
}
import { Dropdown, Form, Radio } from 'semantic-ui-react';
@ -245,7 +208,6 @@ export class HistoryFilter extends React.Component<FilterProps, FilterState> {
super(props, context);
this.state = {
selectedProbeId: 0,
selectedTypeId: 0,
};
}
@ -265,36 +227,10 @@ export class HistoryFilter extends React.Component<FilterProps, FilterState> {
this.props.onProbeChange(data.value);
}} />
</Form.Field>
<Form.Field>Type</Form.Field>
{this.renderTypesRadio()}
</Form>
);
}
private renderTypesRadio = (): JSX.Element[] => {
if (this.props.historyTypes === undefined) {
return null;
}
return this.props.historyTypes.map((type: MetaHistoryType, index: number) => (
<Form.Field key={index}>
<Radio
slider
label={type.name}
name='historyType'
value={type.id}
checked={this.state.selectedTypeId === type.id}
onChange={this.handleTypeChange}
/>
</Form.Field>
));
}
private handleTypeChange = (e: React.SyntheticEvent<HTMLInputElement>, data: any) => {
this.setState({ selectedTypeId: data.value });
this.props.onTypeChange(data.value);
}
private getOptions(): Array<object> {
let res = new Array;
let all = {