NavCon.tsx 7.91 KB
Newer Older
1
2
3
4
import * as React from 'react';
import axios from 'axios';
import { WEBUIDOC, MANAGER_IP } from '../static/const';
import {
5
6
7
8
9
10
11
    Stack,
    initializeIcons,
    StackItem,
    CommandBarButton,
    IContextualMenuProps,
    IStackTokens,
    IStackStyles
12
13
14
} from '@fluentui/react';
import LogPanel from './modals/LogPanel';
import ExperimentPanel from './modals/ExperimentPanel';
15
import { downLoadIcon, infoIconAbout, timeIcon, disableUpdates, requency, closeTimer } from './buttons/Icon';
16
import { OVERVIEWTABS, DETAILTABS, NNILOGO } from './stateless-component/NNItabs';
17
import { EXPERIMENT } from '../static/datamodel';
18
19
20
21
22
23
24
25
26
import '../static/style/nav/nav.scss';
import '../static/style/icon.scss';

initializeIcons();
const stackTokens: IStackTokens = {
    childrenGap: 15
};
const stackStyle: IStackStyles = {
    root: {
27
28
29
30
        minWidth: 400,
        height: 56,
        display: 'flex',
        verticalAlign: 'center'
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
    }
};

interface NavState {
    version: string;
    menuVisible: boolean;
    navBarVisible: boolean;
    isdisabledFresh: boolean;
    isvisibleLogDrawer: 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,
            isvisibleLogDrawer: false, // download button (nnimanager·dispatcher) click -> drawer
            isvisibleExperimentDrawer: false,
            refreshText: 'Auto refresh',
            refreshFrequency: 10
        };
    }

    // to see & download experiment parameters
    showExpcontent = (): void => {
        this.setState({ isvisibleExperimentDrawer: true });
68
    };
69
70
71
72

    // to see & download dispatcher | nnimanager log
    showDispatcherLog = (): void => {
        this.setState({ isvisibleLogDrawer: true });
73
    };
74
75
76
77

    // close log drawer (nnimanager.dispatcher)
    closeLogDrawer = (): void => {
        this.setState({ isvisibleLogDrawer: false });
78
    };
79
80
81
82

    // close download experiment parameters drawer
    closeExpDrawer = (): void => {
        this.setState({ isvisibleExperimentDrawer: false });
83
    };
84
85
86
87

    getNNIversion = (): void => {
        axios(`${MANAGER_IP}/version`, {
            method: 'GET'
88
89
90
91
92
93
        }).then(res => {
            if (res.status === 200) {
                this.setState({ version: res.data });
            }
        });
    };
94
95
96
97
98

    openGithub = (): void => {
        const { version } = this.state;
        const feed = `https://github.com/Microsoft/nni/issues/new?labels=${version}`;
        window.open(feed);
99
    };
100
101
102

    openDocs = (): void => {
        window.open(WEBUIDOC);
103
    };
104

105
    openGithubNNI = (): void => {
106
        const { version } = this.state;
107
108
        const nniLink = `https://github.com/Microsoft/nni/tree/${version}`;
        window.open(nniLink);
109
    };
110
111
112
113
114
115
116

    getInterval = (num: number): void => {
        this.props.changeInterval(num); // notice parent component
        this.setState(() => ({
            refreshFrequency: num === 0 ? '' : num,
            refreshText: num === 0 ? 'Disable auto' : 'Auto refresh'
        }));
117
    };
118
119
120
121
122
123

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

    render(): React.ReactNode {
124
        const { isvisibleLogDrawer, isvisibleExperimentDrawer, version, refreshText, refreshFrequency } = this.state;
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
        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 (
148
            <Stack horizontal className='nav'>
149
                <StackItem grow={30} styles={{ root: { minWidth: 300, display: 'flex', verticalAlign: 'center' } }}>
150
151
                    <span className='desktop-logo'>{NNILOGO}</span>
                    <span className='left-right-margin'>{OVERVIEWTABS}</span>
152
153
                    <span>{DETAILTABS}</span>
                </StackItem>
154
155
                <StackItem grow={70} className='navOptions'>
                    <Stack horizontal horizontalAlign='end' tokens={stackTokens} styles={stackStyle}>
156
157
158
159
160
161
162
                        {/* refresh button danyi*/}
                        {/* TODO: fix bug */}
                        {/* <CommandBarButton
                            iconProps={{ iconName: 'sync' }}
                            text="Refresh"
                            onClick={this.props.refreshFunction}
                        /> */}
163
                        <div className='nav-refresh'>
164
165
166
167
168
                            <CommandBarButton
                                iconProps={refreshFrequency === '' ? disableUpdates : timeIcon}
                                text={refreshText}
                                menuProps={this.refreshProps}
                            />
169
                            <div className='nav-refresh-num'>{refreshFrequency}</div>
170
                        </div>
171
172
                        <CommandBarButton iconProps={downLoadIcon} text='Download' menuProps={this.menuProps} />
                        <CommandBarButton iconProps={infoIconAbout} text='About' menuProps={aboutProps} />
173
174
175
                    </Stack>
                </StackItem>
                {/* the drawer for dispatcher & nnimanager log message */}
176
                {isvisibleLogDrawer && <LogPanel closeDrawer={this.closeLogDrawer} />}
177
178
179
                {isvisibleExperimentDrawer && (
                    <ExperimentPanel closeExpDrawer={this.closeExpDrawer} experimentProfile={EXPERIMENT.profile} />
                )}
180
181
182
183
184
185
186
187
188
            </Stack>
        );
    }

    // view and download experiment [log & experiment result]
    private menuProps: IContextualMenuProps = {
        items: [
            {
                key: 'experiment',
189
                text: 'Experiment summary',
190
191
192
193
194
                iconProps: { iconName: 'ShowResults' },
                onClick: this.showExpcontent
            },
            {
                key: 'logfiles',
195
                text: 'Log files',
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
                iconProps: { iconName: 'FilePDB' },
                onClick: this.showDispatcherLog
            }
        ],
        directionalHintFixed: true
    };

    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)
235
            }
236
237
238
239
240
        ]
    };
}

export default NavCon;