Merge branch 'software-filter'

This commit is contained in:
Collin M. Barrett 2018-09-03 17:29:55 -05:00
commit 418945b60e

View file

@ -11,6 +11,8 @@ interface IHomeState {
loadingLists: boolean;
ruleCount: number;
loadingRuleCount: boolean;
software: ISoftwareDto[];
loadingSoftware: boolean;
pageSize: number;
}
@ -22,13 +24,15 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
loadingLists: true,
ruleCount: 0,
loadingRuleCount: true,
software: [],
loadingSoftware: true,
pageSize: 20
};
this.updatePageSize = this.updatePageSize.bind(this);
}
render() {
const contents = this.state.loadingLists || this.state.loadingRuleCount
const contents = this.state.loadingLists || this.state.loadingRuleCount || this.state.loadingSoftware
? <p>
<em>Loading...</em>
</p>
@ -59,6 +63,14 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
loadingRuleCount: false
});
});
fetch("https://filterlists.com/api/v1/software")
.then(response => response.json() as Promise<ISoftwareDto[]>)
.then(data => {
this.setState({
software: data,
loadingSoftware: false
});
});
}
updatePageSize() {
@ -91,6 +103,29 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
sortMethod: (a: any, b: any) => a.toUpperCase() > b.toUpperCase() ? 1 : -1,
Cell: (cell: any) => <h2 className="mb-0">{cell.value}</h2>
},
{
Header: "Software",
accessor: "softwareIds",
filterable: true,
filterMethod: (filter: any, row: any) => {
if (filter.value === "any") {
return true;
}
return row[filter.id].join(",").split(",").includes(filter.value);
},
Filter: ({ filter, onChange }) =>
<select
onChange={event => onChange(event.target.value)}
style={{ width: "100%" }}
value={filter ? filter.value : "all"}>
<option value="any">Any</option>
{state.software.map((e: any) => <option value={e.id}>{e.name}</option>)}
</select>,
Cell: () => null,
width: 100,
headerClassName: "d-none d-md-block",
className: "d-none d-md-block"
},
{
Header: "Tags",
accessor: "tags",
@ -116,7 +151,8 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
.includes(filter.value.toUpperCase()),
sortMethod: (a: any, b: any) => a.join().toUpperCase() > b.join().toUpperCase() ? 1 : -1,
Cell: (cell: any) => <div className="fl-tag-container">{cell.value.map(
(e: any) => <span className="badge badge-secondary" title={e.name}>{e.iso6391}</span>)}</div>,
(e: any) => <span className="badge badge-secondary" title={e.name}>{e.iso6391}</span>)
}</div>,
style: { whiteSpace: "inherit" },
width: 60,
headerClassName: "d-none d-md-block",
@ -168,10 +204,16 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
}
}
interface ISoftwareDto {
id: number;
name: string;
}
interface IListDto {
id: number;
name: string;
languages: IListLanguageDto[];
softwareIds: number[];
tags: IListTagDto[];
updatedDate: string;
}