import * as React from 'react'; import { DetailsList, IDetailsListProps, IColumn, Icon, DetailsRow, IRenderFunction, IDetailsHeaderProps, Sticky, StickyPositionType, ScrollablePane, ScrollbarVisibility } from '@fluentui/react'; import DefaultMetric from '../../public-child/DefaultMetric'; import OpenRow from '../../public-child/OpenRow'; import { convertDuration, copyAndSort } from '../../../static/function'; import { TRIALS } from '../../../static/datamodel'; import { SortInfo } from '../../../static/interface'; import { DETAILTABS } from '../../stateless-component/NNItabs'; import '../../../static/style/succTable.scss'; import '../../../static/style/tableStatus.css'; import '../../../static/style/openRow.scss'; interface SuccessTableProps { trialIds: string[]; // eslint-disable-next-line @typescript-eslint/no-unused-vars updateOverviewPage: () => void; } interface SuccessTableState { columns: IColumn[]; source: Array; expandRowIdList: Set; sortInfo: SortInfo; } class SuccessTable extends React.Component { constructor(props: SuccessTableProps) { super(props); this.state = { columns: this.columns, source: TRIALS.table(this.props.trialIds), sortInfo: { field: '', isDescend: false }, expandRowIdList: new Set() // store expanded row's trial id }; } componentDidUpdate(prevProps: SuccessTableProps): void { if (this.props.trialIds !== prevProps.trialIds) { const { trialIds } = this.props; this.setState(() => ({ source: TRIALS.table(trialIds) })); } } render(): React.ReactNode { const { columns, source, sortInfo } = this.state; const keepSortedSource = copyAndSort(source, sortInfo.field, sortInfo.isDescend); const isNoneData = source.length === 0 ? true : false; return (
{isNoneData &&
{this.tooltipStr}
}
); } private onColumnClick = (_ev: React.MouseEvent, getColumn: IColumn): void => { const { columns, source } = this.state; const newColumns: IColumn[] = columns.slice(); const currColumn: IColumn = newColumns.filter(item => getColumn.key === item.key)[0]; newColumns.forEach((newCol: IColumn) => { if (newCol === currColumn) { currColumn.isSortedDescending = !currColumn.isSortedDescending; currColumn.isSorted = true; } else { newCol.isSorted = false; newCol.isSortedDescending = true; } }); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion const newItems = copyAndSort(source, currColumn.fieldName!, currColumn.isSortedDescending); this.setState({ columns: newColumns, source: newItems, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion sortInfo: { field: currColumn.fieldName!, isDescend: currColumn.isSortedDescending } }); }; private tooltipStr = ( The experiment is running, please wait for the final metric patiently. You could also find status of trial job with {DETAILTABS} button. ); private columns: IColumn[] = [ { key: '_expand', name: '', onRender: (item: any): any => ( ), fieldName: 'expand', isResizable: false, minWidth: 20, maxWidth: 20 }, { name: 'Trial No.', key: 'sequenceId', fieldName: 'sequenceId', // required! minWidth: 60, maxWidth: 100, isResizable: true, data: 'number', onColumnClick: this.onColumnClick, onRender: (item: any): React.ReactNode =>
{item.sequenceId}
}, { name: 'ID', key: 'id', fieldName: 'id', minWidth: 60, maxWidth: 90, isResizable: true, className: 'tableHead leftTitle', data: 'string', onColumnClick: this.onColumnClick, onRender: (item: any): React.ReactNode =>
{item.id}
}, { name: 'Duration', key: 'duration', minWidth: 80, maxWidth: 120, isResizable: true, fieldName: 'duration', data: 'number', onColumnClick: this.onColumnClick, onRender: (item: any): React.ReactNode => (
{convertDuration(item.duration)}
) }, { name: 'Status', key: 'status', minWidth: 88, maxWidth: 120, isResizable: true, fieldName: 'status', onRender: (item: any): React.ReactNode => (
{item.status}
) }, { name: 'Default metric', key: 'accuracy', fieldName: 'accuracy', minWidth: 100, maxWidth: 166, isResizable: true, data: 'number', onColumnClick: this.onColumnClick, onRender: (item: any): React.ReactNode => } ]; private onRenderDetailsHeader: IRenderFunction = (props, defaultRender) => { if (!props) { return null; } return ( {// eslint-disable-next-line @typescript-eslint/no-non-null-assertion defaultRender!({ ...props })} ); }; private onRenderRow: IDetailsListProps['onRenderRow'] = props => { const { expandRowIdList } = this.state; if (props) { return (
{Array.from(expandRowIdList).map( item => item === props.item.id && )}
); } return null; }; private expandTrialId = (_event: any, id: string): void => { const { expandRowIdList } = this.state; const { updateOverviewPage } = this.props; const copyExpandList = expandRowIdList; if (copyExpandList.has(id)) { copyExpandList.delete(id); } else { copyExpandList.add(id); } this.setState(() => ({ expandRowIdList: copyExpandList })); updateOverviewPage(); }; } export default SuccessTable;