TrialConfigPanel.tsx 3.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import * as React from 'react';
import { Stack, Panel, Pivot, PivotItem, PrimaryButton } from '@fluentui/react';
import { EXPERIMENT } from '../../../static/datamodel';
import MonacoEditor from 'react-monaco-editor';
import { MONACO } from '../../../static/const';
import { convertDuration } from '../../../static/function';
import { prettyStringify } from '../../../static/json_util';
import lodash from 'lodash';
import '../../../static/style/logDrawer.scss';

interface LogDrawerProps {
    hideConfigPanel: () => void;
    activeTab?: string;
}

interface LogDrawerState {
    panelInnerHeight: number;
}

class TrialConfigPanel extends React.Component<LogDrawerProps, LogDrawerState> {
    constructor(props: LogDrawerProps) {
        super(props);

        this.state = {
            panelInnerHeight: window.innerHeight
        };
    }

    setLogDrawerHeight(): void {
        this.setState(() => ({ panelInnerHeight: window.innerHeight }));
    }

    async componentDidMount(): Promise<void> {
        window.addEventListener('resize', this.setLogDrawerHeight);
    }

    componentWillUnmount(): void {
        window.removeEventListener('resize', this.setLogDrawerHeight);
    }

    render(): React.ReactNode {
        const { hideConfigPanel, activeTab } = this.props;
        const { panelInnerHeight } = this.state;
        // [marginTop 16px] + [Search space 46px] +
        // button[height: 32px, marginTop: 45px, marginBottom: 25px] + [padding-bottom: 20px]
        const monacoEditorHeight = panelInnerHeight - 184;
        const blacklist = [
            'id',
            'logDir',
            'startTime',
            'endTime',
            'experimentName',
            'searchSpace',
            'trainingServicePlatform'
        ];
        const filter = (key: string, val: any): any => {
            return blacklist.includes(key) ? undefined : val;
        };
        const profile = lodash.cloneDeep(EXPERIMENT.profile);
        profile.execDuration = convertDuration(profile.execDuration);
        profile.params.maxExecDuration = convertDuration(profile.params.maxExecDuration);
        const showProfile = JSON.stringify(profile, filter, 2);
        return (
            <Stack>
                <Panel
                    isOpen={true}
                    hasCloseButton={false}
                    isFooterAtBottom={true}
                    isLightDismiss={true}
                    onLightDismissClick={hideConfigPanel}
                >
                    <div className='log-tab-body'>
                        <Pivot initialSelectedKey={activeTab} style={{ minHeight: 190, paddingTop: '16px' }}>
                            <PivotItem headerText='Search space' itemKey='search space'>
                                <MonacoEditor
                                    height={monacoEditorHeight}
                                    language='json'
                                    theme='vs-light'
                                    value={prettyStringify(EXPERIMENT.searchSpace, 300, 2)}
                                    options={MONACO}
                                />
                            </PivotItem>
                            <PivotItem headerText='Config' itemKey='config'>
                                <div className='profile'>
                                    <MonacoEditor
                                        width='100%'
                                        height={monacoEditorHeight}
                                        language='json'
                                        theme='vs-light'
                                        value={showProfile}
                                        options={MONACO}
                                    />
                                </div>
                            </PivotItem>
                        </Pivot>
                    </div>
                    <PrimaryButton text='Close' className='configClose' onClick={hideConfigPanel} />
                </Panel>
            </Stack>
        );
    }
}

export default TrialConfigPanel;