Nav.tsx 7.85 KB
Newer Older
1
2
import * as React from 'react';
import axios from 'axios';
3
4
import { Stack, StackItem, CommandBarButton, IContextualMenuProps } from '@fluentui/react';
import { Link } from 'react-router-dom';
Lijiaoa's avatar
Lijiaoa committed
5
import { MANAGER_IP, WEBUIDOC } from '@static/const';
Lijiaoa's avatar
Lijiaoa committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import ExperimentSummaryPanel from './slideNav/ExperimentSummaryPanel';
import { OVERVIEWTABS, DETAILTABS, NNILOGO } from './slideNav/NNItabs';
import { EXPERIMENT } from '@static/datamodel';
import { gap15, stackStyle } from '@components/fluent/ChildrenGap';
import {
    infoIconAbout,
    timeIcon,
    disableUpdates,
    requency,
    closeTimer,
    ChevronRightMed
} from '@components/fluent/Icon';
import '@style/nav/nav.scss';
import '@style/icon.scss';
20
import { ErrorMessage } from '@components/nav/ErrorMessage';
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

interface NavState {
    version: string;
    menuVisible: boolean;
    navBarVisible: boolean;
    isdisabledFresh: boolean;
    isvisibleExperimentDrawer: boolean;
    refreshText: string;
    refreshFrequency: number | string;
}

interface NavProps {
    changeInterval: (value: number) => void;
    refreshFunction: () => void;
}

class NavCon extends React.Component<NavProps, NavState> {
    constructor(props: NavProps) {
        super(props);
        this.state = {
            version: '',
            menuVisible: false,
            navBarVisible: false,
            isdisabledFresh: false,
            isvisibleExperimentDrawer: false,
            refreshText: 'Auto refresh',
            refreshFrequency: 10
        };
    }

    // to see & download experiment parameters
    showExpcontent = (): void => {
        this.setState({ isvisibleExperimentDrawer: true });
54
    };
55
56
57
58

    // close download experiment parameters drawer
    closeExpDrawer = (): void => {
        this.setState({ isvisibleExperimentDrawer: false });
59
    };
60
61
62
63

    getNNIversion = (): void => {
        axios(`${MANAGER_IP}/version`, {
            method: 'GET'
64
65
        }).then(res => {
            if (res.status === 200) {
66
67
68
69
70
71
                let formatVersion = res.data;
                // 2.0 will get 2.0.0 by node, so delete .0 to get real version
                if (formatVersion.endsWith('.0')) {
                    formatVersion = formatVersion.slice(0, -2);
                }
                this.setState({ version: formatVersion });
72
73
74
            }
        });
    };
75
76
77
78
79

    openGithub = (): void => {
        const { version } = this.state;
        const feed = `https://github.com/Microsoft/nni/issues/new?labels=${version}`;
        window.open(feed);
80
    };
81
82
83

    openDocs = (): void => {
        window.open(WEBUIDOC);
84
    };
85

86
    openGithubNNI = (): void => {
87
        const { version } = this.state;
88
89
90
91
92
93
        // 999.0.0-developing
        let formatVersion = `v${version}`;
        if (version === '999.0.0-developing') {
            formatVersion = 'master';
        }
        const nniLink = `https://github.com/Microsoft/nni/tree/${formatVersion}`;
94
        window.open(nniLink);
95
    };
96
97
98
99
100
101
102

    getInterval = (num: number): void => {
        this.props.changeInterval(num); // notice parent component
        this.setState(() => ({
            refreshFrequency: num === 0 ? '' : num,
            refreshText: num === 0 ? 'Disable auto' : 'Auto refresh'
        }));
103
    };
104
105
106
107
108
109

    componentDidMount(): void {
        this.getNNIversion();
    }

    render(): React.ReactNode {
110
        const { isvisibleExperimentDrawer, version, refreshText, refreshFrequency } = this.state;
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
        const aboutProps: IContextualMenuProps = {
            items: [
                {
                    key: 'feedback',
                    text: 'Feedback',
                    iconProps: { iconName: 'OfficeChat' },
                    onClick: this.openGithub
                },
                {
                    key: 'help',
                    text: 'Document',
                    iconProps: { iconName: 'TextDocument' },
                    onClick: this.openDocs
                },
                {
                    key: 'version',
                    text: `Version ${version}`,
                    iconProps: { iconName: 'VerifiedBrand' },
                    onClick: this.openGithubNNI
                }
            ]
        };
        return (
134
            <Stack horizontal className='nav'>
135
136
137
138
139
140
141
                <React.Fragment>
                    <StackItem grow={30} styles={{ root: { minWidth: 300, display: 'flex', verticalAlign: 'center' } }}>
                        <span className='desktop-logo'>{NNILOGO}</span>
                        <span className='left-right-margin'>{OVERVIEWTABS}</span>
                        <span>{DETAILTABS}</span>
                    </StackItem>
                    <StackItem grow={70} className='navOptions'>
Lijiaoa's avatar
Lijiaoa committed
142
                        <Stack horizontal horizontalAlign='end' tokens={gap15} styles={stackStyle}>
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
                            {/* refresh button danyi*/}
                            {/* TODO: fix bug */}
                            {/* <CommandBarButton
                                        iconProps={{ iconName: 'sync' }}
                                        text="Refresh"
                                        onClick={this.props.refreshFunction}
                                    /> */}
                            <div className='nav-refresh'>
                                <CommandBarButton
                                    iconProps={refreshFrequency === '' ? disableUpdates : timeIcon}
                                    text={refreshText}
                                    menuProps={this.refreshProps}
                                />
                                <div className='nav-refresh-num'>{refreshFrequency}</div>
                            </div>
158
                            <CommandBarButton
159
160
161
                                iconProps={{ iconName: 'ShowResults' }}
                                text='Experiment summary'
                                onClick={this.showExpcontent}
162
                            />
163
164
165
                            <CommandBarButton iconProps={infoIconAbout} text='About' menuProps={aboutProps} />
                            <Link to='/experiment' className='experiment'>
                                <div className='expNavTitle'>
166
                                    <span>All experiments</span>
167
168
169
170
171
172
173
                                    {ChevronRightMed}
                                </div>
                            </Link>
                        </Stack>
                    </StackItem>
                    {isvisibleExperimentDrawer && (
                        <ExperimentSummaryPanel
Lijiaoa's avatar
Lijiaoa committed
174
                            closeExpPanel={this.closeExpDrawer}
175
                            experimentProfile={EXPERIMENT.profile}
176
                        />
177
178
                    )}
                </React.Fragment>
179
180
                {/* experiment error model */}
                <ErrorMessage />
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
            </Stack>
        );
    }

    private refreshProps: IContextualMenuProps = {
        items: [
            {
                key: 'disableRefresh',
                text: 'Disable auto refresh',
                iconProps: closeTimer,
                onClick: this.getInterval.bind(this, 0)
            },
            {
                key: 'refresh10',
                text: 'Refresh every 10s',
                iconProps: requency,
                onClick: this.getInterval.bind(this, 10)
            },
            {
                key: 'refresh20',
                text: 'Refresh every 20s',
                iconProps: requency,
                onClick: this.getInterval.bind(this, 20)
            },
            {
                key: 'refresh30',
                text: 'Refresh every 30s',
                iconProps: requency,
                onClick: this.getInterval.bind(this, 30)
            },

            {
                key: 'refresh60',
                text: 'Refresh every 1min',
                iconProps: requency,
                onClick: this.getInterval.bind(this, 60)
217
            }
218
219
220
221
222
        ]
    };
}

export default NavCon;