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

update (#2440)


Co-authored-by: default avatarLijiao <15910218274@163.com>
parent 1e2a2e29
...@@ -39,6 +39,11 @@ interface TableListProps { ...@@ -39,6 +39,11 @@ interface TableListProps {
trialsUpdateBroadcast: number; trialsUpdateBroadcast: number;
} }
interface SortInfo {
field: string;
isDescend?: boolean;
}
interface TableListState { interface TableListState {
intermediateOption: object; intermediateOption: object;
modalVisible: boolean; modalVisible: boolean;
...@@ -60,9 +65,9 @@ interface TableListState { ...@@ -60,9 +65,9 @@ interface TableListState {
tableColumns: IColumn[]; tableColumns: IColumn[];
allColumnList: string[]; allColumnList: string[];
tableSourceForSort: Array<TableRecord>; tableSourceForSort: Array<TableRecord>;
sortMessage: SortInfo;
} }
class TableList extends React.Component<TableListProps, TableListState> { class TableList extends React.Component<TableListProps, TableListState> {
public intervalTrialLog = 10; public intervalTrialLog = 10;
...@@ -91,7 +96,8 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -91,7 +96,8 @@ class TableList extends React.Component<TableListProps, TableListState> {
modalIntermediateHeight: window.innerHeight, modalIntermediateHeight: window.innerHeight,
tableColumns: this.initTableColumnList(this.props.columnList), tableColumns: this.initTableColumnList(this.props.columnList),
allColumnList: this.getAllColumnKeys(), allColumnList: this.getAllColumnKeys(),
tableSourceForSort: this.props.tableSource tableSourceForSort: this.props.tableSource,
sortMessage: { field: '', isDescend: false }
}; };
} }
...@@ -114,19 +120,29 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -114,19 +120,29 @@ class TableList extends React.Component<TableListProps, TableListState> {
const newItems = this.copyAndSort(tableSource, currColumn.fieldName!, currColumn.isSortedDescending); const newItems = this.copyAndSort(tableSource, currColumn.fieldName!, currColumn.isSortedDescending);
this.setState({ this.setState({
tableColumns: newColumns, tableColumns: newColumns,
tableSourceForSort: newItems tableSourceForSort: newItems,
sortMessage: { field: getColumn.key, isDescend: currColumn.isSortedDescending }
}); });
}; };
private copyAndSort<T>(items: T[], columnKey: string, isSortedDescending?: boolean): T[] { private copyAndSort<T>(items: T[], columnKey: string, isSortedDescending?: boolean): any {
const key = columnKey as keyof T; const key = columnKey as keyof T;
return items.slice(0).sort((a: T, b: T) => ((isSortedDescending ? a[key] < b[key] : a[key] > b[key]) ? 1 : -1)); return items.slice(0).sort(function (a: T, b: T): any {
if (a[key] === undefined) {
return 1;
}
if (b[key] === undefined) {
return -1;
}
return (isSortedDescending ? a[key] < b[key] : a[key] > b[key]) ? 1 : -1;
});
} }
AccuracyColumnConfig: any = { AccuracyColumnConfig: any = {
name: 'Default metric', name: 'Default metric',
className: 'leftTitle', className: 'leftTitle',
key: 'accuracy', key: 'latestAccuracy',
fieldName: 'latestAccuracy', fieldName: 'latestAccuracy',
minWidth: 200, minWidth: 200,
maxWidth: 300, maxWidth: 300,
...@@ -143,7 +159,7 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -143,7 +159,7 @@ class TableList extends React.Component<TableListProps, TableListState> {
minWidth: 80, minWidth: 80,
maxWidth: 240, maxWidth: 240,
className: 'tableHead', className: 'tableHead',
data: 'string', data: 'number',
onColumnClick: this.onColumnClick, onColumnClick: this.onColumnClick,
}; };
...@@ -566,10 +582,21 @@ class TableList extends React.Component<TableListProps, TableListState> { ...@@ -566,10 +582,21 @@ class TableList extends React.Component<TableListProps, TableListState> {
const { intermediateKey, modalIntermediateWidth, modalIntermediateHeight, const { intermediateKey, modalIntermediateWidth, modalIntermediateHeight,
tableColumns, allColumnList, isShowColumn, modalVisible, tableColumns, allColumnList, isShowColumn, modalVisible,
selectRows, isShowCompareModal, intermediateOtherKeys, selectRows, isShowCompareModal, intermediateOtherKeys,
isShowCustomizedModal, copyTrialId, intermediateOption isShowCustomizedModal, copyTrialId, intermediateOption, sortMessage
} = this.state; } = this.state;
const { columnList } = this.props; const { columnList } = this.props;
const tableSource: Array<TableRecord> = JSON.parse(JSON.stringify(this.state.tableSourceForSort)); const tableSource: Array<TableRecord> = JSON.parse(JSON.stringify(this.state.tableSourceForSort));
if (sortMessage.field !== '') {
tableSource.sort(function (a, b): any {
if (a[sortMessage.field] === undefined) {
return 1;
}
if (b[sortMessage.field] === undefined) {
return -1;
}
return (sortMessage.isDescend ? a[sortMessage.field] < b[sortMessage.field] : a[sortMessage.field] > b[sortMessage.field]) ? 1 : -1;
});
}
return ( return (
<Stack> <Stack>
<div id="tableList"> <div id="tableList">
......
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