Unverified Commit 7d6b8b3b authored by Lijiaoa's avatar Lijiaoa Committed by GitHub
Browse files

Support multiple selection for filter status (manage all experiments page) (#3351)

parent 8c8db374
...@@ -23,7 +23,7 @@ interface ExpListState { ...@@ -23,7 +23,7 @@ interface ExpListState {
errorMessage: string; errorMessage: string;
hideFilter: boolean; hideFilter: boolean;
searchInputVal: string; searchInputVal: string;
selectedStatus: string; selectedStatus: string[];
selectedPlatform: string; selectedPlatform: string;
selectedStartDate?: Date; selectedStartDate?: Date;
selectedEndDate?: Date; selectedEndDate?: Date;
...@@ -42,7 +42,7 @@ class Experiment extends React.Component<{}, ExpListState> { ...@@ -42,7 +42,7 @@ class Experiment extends React.Component<{}, ExpListState> {
errorMessage: '', errorMessage: '',
hideFilter: true, hideFilter: true,
searchInputVal: '', searchInputVal: '',
selectedStatus: '', selectedStatus: [],
selectedPlatform: '', selectedPlatform: '',
source: [], // data in table source: [], // data in table
originExperimentList: [], // api /experiments-info originExperimentList: [], // api /experiments-info
...@@ -312,39 +312,28 @@ class Experiment extends React.Component<{}, ExpListState> { ...@@ -312,39 +312,28 @@ class Experiment extends React.Component<{}, ExpListState> {
*/ */
private commonSelectString = (data: AllExperimentList[], field: string): AllExperimentList[] => { private commonSelectString = (data: AllExperimentList[], field: string): AllExperimentList[] => {
const { selectedStatus, selectedPlatform, selectedStartDate, selectedEndDate } = this.state; const { selectedStatus, selectedPlatform, selectedStartDate, selectedEndDate } = this.state;
const hasStatus = selectedStatus === '' ? false : true;
const hasPlatform = selectedPlatform === '' ? false : true;
const hasStartDate = selectedStartDate === undefined ? false : true;
const hasEndDate = selectedEndDate === undefined ? false : true;
if (field === 'status') { if (field === 'status') {
if (hasPlatform) { data = filterByStatusOrPlatform(selectedPlatform, 'platform', data);
data = filterByStatusOrPlatform(selectedPlatform, 'platform', data);
}
} }
if (field === 'platform') { if (field === 'platform') {
if (hasStatus) { data = filterByStatusOrPlatform(selectedStatus, 'status', data);
data = filterByStatusOrPlatform(selectedStatus, 'status', data);
}
} }
if (field === '') { if (field === '') {
if (hasPlatform) { data = Array.from(
data = filterByStatusOrPlatform(selectedPlatform, 'platform', data); new Set([
} ...filterByStatusOrPlatform(selectedPlatform, 'platform', data),
if (hasStatus) { ...filterByStatusOrPlatform(selectedStatus, 'status', data)
data = filterByStatusOrPlatform(selectedStatus, 'status', data); ])
} );
} }
if (hasStartDate) { data = data.filter(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion item =>
data = data.filter(temp => compareDate(new Date(temp.startTime), selectedStartDate!)); (selectedStartDate === undefined || compareDate(new Date(item.startTime), selectedStartDate)) &&
} (selectedEndDate === undefined || compareDate(new Date(item.endTime), selectedEndDate))
if (hasEndDate) { );
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
data = data.filter(temp => compareDate(new Date(temp.endTime), selectedEndDate!));
}
return data; return data;
}; };
...@@ -352,10 +341,16 @@ class Experiment extends React.Component<{}, ExpListState> { ...@@ -352,10 +341,16 @@ class Experiment extends React.Component<{}, ExpListState> {
// status platform startTime endTime // status platform startTime endTime
private selectStatus = (_event: React.FormEvent<HTMLDivElement>, item: any): void => { private selectStatus = (_event: React.FormEvent<HTMLDivElement>, item: any): void => {
if (item !== undefined) { if (item !== undefined) {
const { searchSource, sortInfo } = this.state; const { searchSource, sortInfo, selectedStatus } = this.state;
let result = filterByStatusOrPlatform(item.key, 'status', searchSource); const newSelectedStatus = item.selected
? [...selectedStatus, item.key as string]
: selectedStatus.filter(key => key !== item.key);
let result = filterByStatusOrPlatform(newSelectedStatus, 'status', searchSource);
result = this.commonSelectString(result, 'status'); result = this.commonSelectString(result, 'status');
this.setState({ selectedStatus: item.key, source: getSortedSource(result, sortInfo) }); this.setState({
selectedStatus: newSelectedStatus,
source: getSortedSource(result, sortInfo)
});
} }
}; };
...@@ -378,41 +373,30 @@ class Experiment extends React.Component<{}, ExpListState> { ...@@ -378,41 +373,30 @@ class Experiment extends React.Component<{}, ExpListState> {
searchSource, searchSource,
sortInfo sortInfo
} = this.state; } = this.state;
const hasStatus = selectedStatus === '' ? false : true;
const hasPlatform = selectedPlatform === '' ? false : true; const hasPlatform = selectedPlatform === '' ? false : true;
const hasStartDate = selectedStartDate === undefined ? false : true;
const hasEndDate = selectedEndDate === undefined ? false : true; // filter status, platform
let result; let result = filterByStatusOrPlatform(selectedStatus, 'status', searchSource);
if (hasPlatform) {
result = result.filter(temp => temp.platform === selectedPlatform);
}
if (type === 'start') { if (type === 'start') {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion result = result.filter(
result = searchSource.filter(item => compareDate(new Date(item.startTime), date)); item =>
if (hasStatus) { compareDate(new Date(item.startTime), date) &&
result = result.filter(temp => temp.status === selectedStatus); (selectedEndDate === undefined || compareDate(new Date(item.endTime), selectedEndDate))
} );
if (hasPlatform) {
result = result.filter(temp => temp.platform === selectedPlatform);
}
if (hasEndDate) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
result = result.filter(temp => compareDate(new Date(temp.endTime), selectedEndDate!));
}
this.setState(() => ({ this.setState(() => ({
source: getSortedSource(result, sortInfo), source: getSortedSource(result, sortInfo),
selectedStartDate: date selectedStartDate: date
})); }));
} else { } else {
result = searchSource.filter(item => compareDate(new Date(item.endTime), date)); result = result.filter(
item =>
if (hasStatus) { compareDate(new Date(item.endTime), date) &&
result = result.filter(temp => temp.status === selectedStatus); (selectedStartDate === undefined || compareDate(new Date(item.startTime), selectedStartDate))
} );
if (hasPlatform) {
result = result.filter(temp => temp.platform === selectedPlatform);
}
if (hasStartDate) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
result = result.filter(temp => compareDate(new Date(temp.startTime), selectedStartDate!));
}
this.setState(() => ({ this.setState(() => ({
source: getSortedSource(result, sortInfo), source: getSortedSource(result, sortInfo),
selectedEndDate: date selectedEndDate: date
...@@ -434,7 +418,7 @@ class Experiment extends React.Component<{}, ExpListState> { ...@@ -434,7 +418,7 @@ class Experiment extends React.Component<{}, ExpListState> {
); );
this.setState(() => ({ this.setState(() => ({
source: getSortedSource(result, sortInfo), source: getSortedSource(result, sortInfo),
selectedStatus: '', selectedStatus: [],
selectedPlatform: '', selectedPlatform: '',
selectedStartDate: undefined, selectedStartDate: undefined,
selectedEndDate: undefined selectedEndDate: undefined
......
...@@ -5,7 +5,7 @@ import { fillOptions } from './expFunction'; ...@@ -5,7 +5,7 @@ import { fillOptions } from './expFunction';
interface FilterBtnsProps { interface FilterBtnsProps {
platform: string[]; platform: string[];
selectedStatus: string; selectedStatus: string[];
selectedPlatform: string; selectedPlatform: string;
selectedStartDate: Date; selectedStartDate: Date;
selectedEndDate: Date; selectedEndDate: Date;
...@@ -37,7 +37,8 @@ class FilterBtns extends React.Component<FilterBtnsProps, {}> { ...@@ -37,7 +37,8 @@ class FilterBtns extends React.Component<FilterBtnsProps, {}> {
<React.Fragment> <React.Fragment>
<Dropdown <Dropdown
label='Status' label='Status'
selectedKey={selectedStatus} selectedKeys={selectedStatus}
multiSelect
onChange={selectStatus.bind(this)} onChange={selectStatus.bind(this)}
placeholder='Select an option' placeholder='Select an option'
options={fillOptions(EXPERIMENTSTATUS)} options={fillOptions(EXPERIMENTSTATUS)}
......
...@@ -15,8 +15,20 @@ function compareDate(date1: Date, date2: Date): boolean { ...@@ -15,8 +15,20 @@ function compareDate(date1: Date, date2: Date): boolean {
return false; return false;
} }
const filterByStatusOrPlatform = (val: string, type: string, data: AllExperimentList[]): AllExperimentList[] => { const filterByStatusOrPlatform = (
return data.filter(temp => temp[type] === val); val: string | string[],
type: string,
data: AllExperimentList[]
): AllExperimentList[] => {
if (typeof val === 'string' && val !== '') {
return data.filter(temp => temp[type] === val);
}
if (Array.isArray(val) && val.length !== 0) {
return data.filter(temp => val.includes(temp[type]));
}
return data;
}; };
function fillOptions(arr: string[]): any { function fillOptions(arr: string[]): any {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment