"benchmark/long_json_decode/bench_other.py" did not exist on "f6d40df0ee1e1fc53db3edc04bf90575f221cf23"
SuccessTable.tsx 5.81 KB
Newer Older
Lijiao's avatar
Lijiao committed
1
import * as React from 'react';
2
import { DetailsList, IDetailsListProps, IColumn } from '@fluentui/react';
3
import DefaultMetric from '../../public-child/DefaultMetric';
4
import Details from './Details';
5
6
7
8
9
10
import { convertDuration } from '../../../static/function';
import { TRIALS } from '../../../static/datamodel';
import { DETAILTABS } from '../../stateless-component/NNItabs';
import '../../../static/style/succTable.scss';
import '../../../static/style/tableStatus.css';
import '../../../static/style/openRow.scss';
Lijiao's avatar
Lijiao committed
11
12

interface SuccessTableProps {
13
    trialIds: string[];
Lijiao's avatar
Lijiao committed
14
15
}

16
17
18
interface SuccessTableState {
    columns: IColumn[];
    source: Array<any>;
19
    innerWidth: number;
20
}
Lijiao's avatar
Lijiao committed
21

22
class SuccessTable extends React.Component<SuccessTableProps, SuccessTableState> {
Lijiao's avatar
Lijiao committed
23
24
    constructor(props: SuccessTableProps) {
        super(props);
25
26
27
28
29
        this.state = {
            columns: this.columns,
            source: TRIALS.table(this.props.trialIds),
            innerWidth: window.innerWidth
        };
Lijiao's avatar
Lijiao committed
30
31
    }

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    private onRenderRow: IDetailsListProps['onRenderRow'] = props => {
        if (props) {
            return <Details detailsProps={props} />;
        }
        return null;
    };

    onColumnClick = (ev: React.MouseEvent<HTMLElement>, 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;
Lijiao's avatar
Lijiao committed
50
            }
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        });
        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
        const newItems = this.copyAndSort(source, currColumn.fieldName!, currColumn.isSortedDescending);
        this.setState({
            columns: newColumns,
            source: newItems
        });
    };

    private copyAndSort<T>(items: T[], columnKey: string, isSortedDescending?: boolean): 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));
    }

65
    tooltipStr = (
66
67
68
69
        <React.Fragment>
            The experiment is running, please wait for the final metric patiently. You could also find status of trial
            job with <span>{DETAILTABS}</span> button.
        </React.Fragment>
70
    );
71

72
73
74
75
76
    columns = [
        {
            name: 'Trial No.',
            key: 'sequenceId',
            fieldName: 'sequenceId', // required!
77
78
            minWidth: 50,
            maxWidth: 87,
79
            isResizable: true,
80
            data: 'number',
81
82
            onColumnClick: this.onColumnClick,
            onRender: (item: any): React.ReactNode => <div className='succeed-padding'>{item.sequenceId}</div>
83
84
        },
        {
85
86
87
            name: 'ID',
            key: 'id',
            fieldName: 'id',
88
89
            minWidth: 50,
            maxWidth: 87,
90
            isResizable: true,
91
92
            className: 'tableHead leftTitle',
            data: 'string',
93
94
            onColumnClick: this.onColumnClick,
            onRender: (item: any): React.ReactNode => <div className='succeed-padding'>{item.id}</div>
95
96
        },
        {
97
98
            name: 'Duration',
            key: 'duration',
99
100
            minWidth: 65,
            maxWidth: 150,
101
            isResizable: true,
102
103
104
            fieldName: 'duration',
            data: 'number',
            onColumnClick: this.onColumnClick,
105
            onRender: (item: any): React.ReactNode => (
106
                <div className='durationsty succeed-padding'>
107
108
109
110
111
                    <div>{convertDuration(item.duration)}</div>
                </div>
            )
        },
        {
112
113
            name: 'Status',
            key: 'status',
114
115
            minWidth: 80,
            maxWidth: 150,
116
            isResizable: true,
117
            fieldName: 'status',
118
119
120
            onRender: (item: any): React.ReactNode => (
                <div className={`${item.status} commonStyle succeed-padding`}>{item.status}</div>
            )
121
122
        },
        {
123
124
125
            name: 'Default metric',
            key: 'accuracy',
            fieldName: 'accuracy',
126
127
            minWidth: 100,
            maxWidth: 160,
128
            isResizable: true,
129
130
            data: 'number',
            onColumnClick: this.onColumnClick,
131
            onRender: (item: any): React.ReactNode => <DefaultMetric trialId={item.id} />
132
133
134
        }
    ];

135
136
137
138
139
140
141
142
143
144
145
    setInnerWidth = (): void => {
        this.setState(() => ({ innerWidth: window.innerWidth }));
    };

    componentDidMount(): void {
        window.addEventListener('resize', this.setInnerWidth);
    }
    componentWillUnmount(): void {
        window.removeEventListener('resize', this.setInnerWidth);
    }

146
    componentDidUpdate(prevProps: SuccessTableProps): void {
147
        if (this.props.trialIds !== prevProps.trialIds) {
148
149
150
            const { trialIds } = this.props;
            this.setState(() => ({ source: TRIALS.table(trialIds) }));
        }
Lijiaoa's avatar
Lijiaoa committed
151
152
    }

153
154
    render(): React.ReactNode {
        const { columns, source } = this.state;
155
        const isNoneData = source.length === 0 ? true : false;
156

Lijiao's avatar
Lijiao committed
157
        return (
158
            <div id='succTable'>
159
                <DetailsList
Lijiao's avatar
Lijiao committed
160
                    columns={columns}
161
                    items={source}
162
                    setKey='set'
163
164
165
                    compact={true}
                    onRenderRow={this.onRenderRow}
                    selectionMode={0} // close selector function
166
                    className='succTable'
Lijiao's avatar
Lijiao committed
167
                />
168
                {isNoneData && <div className='succTable-tooltip'>{this.tooltipStr}</div>}
169
            </div>
Lijiao's avatar
Lijiao committed
170
171
172
        );
    }
}
173
174

export default SuccessTable;