import * as React from 'react'; import { Stack, DetailsList, IDetailsListProps, IColumn, Icon, DetailsRow, IRenderFunction, IDetailsHeaderProps, Sticky, StickyPositionType, ScrollablePane, ScrollbarVisibility } from '@fluentui/react'; import DefaultMetric from './DefaultMetric'; import OpenRow from '@components/common/OpenRow'; import CopyButton from '@components/common/CopyButton'; import { convertDuration, copyAndSort } from '@static/function'; import { TRIALS } from '@static/datamodel'; import { SortInfo } from '@static/interface'; import { DETAILTABS } from '@components/nav/slideNav/NNItabs'; import '@style/experiment/overview/succTable.scss'; import '@style/common/trialStatus.css'; import '@style/openRow.scss'; interface SuccessTableProps { trialIds: string[]; updateOverviewPage: () => void; expandRowIDs: Set; changeExpandRowIDs: Function; } interface SuccessTableState { columns: IColumn[]; source: Array; 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 } }; } 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: 80, isResizable: true, data: 'number', onColumnClick: this.onColumnClick, onRender: (item: any): React.ReactNode =>
{item.sequenceId}
}, { name: 'ID', key: 'id', fieldName: 'id', minWidth: 90, maxWidth: 100, isResizable: true, className: 'tableHead leftTitle', data: 'string', onColumnClick: this.onColumnClick, onRender: (item: any): React.ReactNode => (
{item.id}
) }, { name: 'Duration', key: 'duration', minWidth: 70, 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 { expandRowIDs } = this.props; if (props) { return (
{Array.from(expandRowIDs).map( item => item === props.item.id && )}
); } return null; }; private expandTrialId = (_event: any, id: string): void => { const { updateOverviewPage, changeExpandRowIDs } = this.props; changeExpandRowIDs(id); updateOverviewPage(); }; } export default SuccessTable;