TrialConfigPanel.tsx 5.2 KB
Newer Older
1
2
3
4
5
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';
6
7
import { AppContext } from '../../../App';
import { convertDuration, convertTimeAsUnit } from '../../../static/function';
8
9
10
11
12
13
14
15
16
17
18
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;
19
    innerWidth: number;
20
21
22
23
24
25
26
}

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

        this.state = {
27
28
            panelInnerHeight: window.innerHeight,
            innerWidth: window.innerWidth
29
30
31
        };
    }

32
33
34
35
    // use arrow function for change window size met error: this.setState is not a function
    setLogDrawerHeight = (): void => {
        this.setState(() => ({ panelInnerHeight: window.innerHeight, innerWidth: window.innerWidth }));
    };
36
37
38
39
40
41
42
43
44
45
46

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

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

    render(): React.ReactNode {
        const { hideConfigPanel, activeTab } = this.props;
47
        const { panelInnerHeight, innerWidth } = this.state;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        // [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);
65
66
67

        const prettyWidth = innerWidth > 1400 ? 100 : 60;

68
        return (
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
105
106
107
108
109
110
111
112
            <AppContext.Consumer>
                {(value): React.ReactNode => {
                    const unit = value.maxDurationUnit;
                    profile.params.maxExecDuration = `${convertTimeAsUnit(
                        unit,
                        profile.params.maxExecDuration
                    )}${unit}`;
                    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, prettyWidth, 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>
113
                                </div>
114
115
116
117
118
119
                                <PrimaryButton text='Close' className='configClose' onClick={hideConfigPanel} />
                            </Panel>
                        </Stack>
                    );
                }}
            </AppContext.Consumer>
120
121
122
123
124
        );
    }
}

export default TrialConfigPanel;