"vscode:/vscode.git/clone" did not exist on "0ffcfdf474d34858ce5641c11c0b5559861d188b"
OpenRow.tsx 6.49 KB
Newer Older
Lijiao's avatar
Lijiao committed
1
import * as React from 'react';
2
import * as copy from 'copy-to-clipboard';
3
import { Stack, PrimaryButton, Pivot, PivotItem } from '@fluentui/react';
4
import { Trial } from '../../static/model/trial';
5
import { MANAGER_IP } from '../../static/const';
6
7
8
9
import { EXPERIMENT, TRIALS } from '../../static/datamodel';
import JSONTree from 'react-json-tree';
import PaiTrialLog from '../public-child/PaiTrialLog';
import TrialLog from '../public-child/TrialLog';
10
import MessageInfo from '../modals/MessageInfo';
11
import '../../static/style/overview/overview.scss';
12
import '../../static/style/copyParameter.scss';
13
import '../../static/style/openRow.scss';
Lijiao's avatar
Lijiao committed
14
15

interface OpenRowProps {
16
    trialId: string;
Lijiao's avatar
Lijiao committed
17
18
}

Lijiao's avatar
Lijiao committed
19
interface OpenRowState {
20
21
22
    typeInfo: string;
    info: string;
    isHidenInfo: boolean;
Lijiao's avatar
Lijiao committed
23
24
25
}

class OpenRow extends React.Component<OpenRowProps, OpenRowState> {
Lijiao's avatar
Lijiao committed
26
27
    constructor(props: OpenRowProps) {
        super(props);
Lijiao's avatar
Lijiao committed
28
        this.state = {
29
30
31
            typeInfo: '',
            info: '',
            isHidenInfo: true
Lijiao's avatar
Lijiao committed
32
        };
33
34
    }

35
36
    hideMessageInfo = (): void => {
        this.setState(() => ({ isHidenInfo: true }));
37
    };
Lijiao's avatar
Lijiao committed
38

39
40
41
    /**
     * info: message content
     * typeInfo: message type: success | error...
42
     * continuousTime: show time, 2000ms
43
44
45
46
     */
    getCopyStatus = (info: string, typeInfo: string): void => {
        this.setState(() => ({ info, typeInfo, isHidenInfo: false }));
        setTimeout(this.hideMessageInfo, 2000);
47
    };
Lijiao's avatar
Lijiao committed
48

49
50
51
52
53
    copyParams = (trial: Trial): void => {
        // get copy parameters
        const params = JSON.stringify(trial.description.parameters, null, 4);
        if (copy.default(params)) {
            this.getCopyStatus('Success copy parameters to clipboard in form of python dict !', 'success');
54
        } else {
55
            this.getCopyStatus('Failed !', 'error');
56
        }
57
    };
58

59
60
    openTrialLog = (type: string): void => {
        window.open(`${MANAGER_IP}/trial-log/${this.props.trialId}/${type}`);
61
    };
62

Lijiao's avatar
Lijiao committed
63
    render(): React.ReactNode {
64
        const { isHidenInfo, typeInfo, info } = this.state;
65
66
        const trialId = this.props.trialId;
        const trial = TRIALS.getTrial(trialId);
67
        const logPathRow = trial.info.logPath || "This trial's log path is not available.";
Lijiao's avatar
Lijiao committed
68
        return (
69
70
            <Stack className='openRow'>
                <Stack className='openRowContent'>
71
                    <Pivot>
72
73
74
75
76
77
78
79
80
81
                        <PivotItem headerText='Parameters' key='1' itemIcon='TestParameter'>
                            {trial.info.hyperParameters !== undefined ? (
                                <Stack id='description'>
                                    <Stack className='bgHyper'>
                                        <JSONTree
                                            hideRoot={true}
                                            shouldExpandNode={(): boolean => true} // default expandNode
                                            getItemString={(): null => null} // remove the {} items
                                            data={trial.description.parameters}
                                        />
82
                                    </Stack>
83
84
85
86
87
88
89
90
                                    <Stack horizontal className='copy'>
                                        <PrimaryButton
                                            onClick={this.copyParams.bind(this, trial)}
                                            text='Copy as json'
                                            styles={{ root: { width: 128, marginRight: 10 } }}
                                        />
                                        {/* copy success | failed message info */}
                                        {!isHidenInfo && <MessageInfo typeInfo={typeInfo} info={info} />}
91
                                    </Stack>
92
93
94
95
96
97
98
                                </Stack>
                            ) : (
                                <Stack className='logpath'>
                                    <span className='logName'>Error: </span>
                                    <span className='error'>{`This trial's parameters are not available.'`}</span>
                                </Stack>
                            )}
99
                        </PivotItem>
100
                        <PivotItem headerText='Log' key='2' itemIcon='M365InvoicingLogo'>
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
                            {
                                // FIXME: this should not be handled in web UI side
                                EXPERIMENT.trainingServicePlatform !== 'local' ? (
                                    <PaiTrialLog
                                        logStr={logPathRow}
                                        id={trialId}
                                        logCollection={EXPERIMENT.logCollectionEnabled}
                                    />
                                ) : (
                                    <div>
                                        <TrialLog logStr={logPathRow} id={trialId} />
                                        {/* view each trial log in drawer*/}
                                        <div id='trialog'>
                                            <div className='copy' style={{ marginTop: 15 }}>
                                                <PrimaryButton
                                                    onClick={this.openTrialLog.bind(this, 'TRIAL_LOG')}
                                                    text='View trial log'
                                                />
                                                <PrimaryButton
                                                    onClick={this.openTrialLog.bind(this, 'TRIAL_ERROR')}
                                                    text='View trial error'
                                                    styles={{ root: { marginLeft: 15 } }}
                                                />
                                                <PrimaryButton
                                                    onClick={this.openTrialLog.bind(this, 'TRIAL_STDOUT')}
                                                    text='View trial stdout'
                                                    styles={{ root: { marginLeft: 15 } }}
                                                />
                                            </div>
130
131
                                        </div>
                                    </div>
132
133
                                )
                            }
134
135
                        </PivotItem>
                    </Pivot>
136
                </Stack>
137
            </Stack>
Lijiao's avatar
Lijiao committed
138
139
140
141
        );
    }
}

142
export default OpenRow;