Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 2488aa6

Browse files
authored
refactor experiment summary file(to fix componentWillReceiveProps waring) and click other areas to close panel (#2734)
1 parent 2d026a1 commit 2488aa6

File tree

5 files changed

+71
-58
lines changed

5 files changed

+71
-58
lines changed

src/webui/src/components/Modals/ExperimentDrawer.tsx renamed to src/webui/src/components/Modals/ExperimentPanel.tsx

+46-50
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import * as React from 'react';
2-
import axios from 'axios';
32
import { downFile } from '../../static/function';
43
import {
54
Stack, PrimaryButton, DefaultButton, Panel, StackItem, Pivot, PivotItem
65
} from 'office-ui-fabric-react';
7-
import { MANAGER_IP, DRAWEROPTION } from '../../static/const';
6+
import { DRAWEROPTION } from '../../static/const';
7+
import { EXPERIMENT, TRIALS } from '../../static/datamodel';
88
import MonacoEditor from 'react-monaco-editor';
99
import '../../static/style/logDrawer.scss';
10-
import { TrialManager } from '../../static/model/trialmanager';
1110

1211
interface ExpDrawerProps {
13-
isVisble: boolean;
1412
closeExpDrawer: () => void;
13+
experimentProfile: object;
1514
}
1615

1716
interface ExpDrawerState {
@@ -21,7 +20,9 @@ interface ExpDrawerState {
2120

2221
class ExperimentDrawer extends React.Component<ExpDrawerProps, ExpDrawerState> {
2322

24-
public _isCompareMount!: boolean;
23+
public _isExperimentMount!: boolean;
24+
private refreshId!: number | undefined;
25+
2526
constructor(props: ExpDrawerProps) {
2627
super(props);
2728

@@ -32,42 +33,40 @@ class ExperimentDrawer extends React.Component<ExpDrawerProps, ExpDrawerState> {
3233
}
3334

3435
getExperimentContent = (): void => {
35-
axios
36-
.all([
37-
axios.get(`${MANAGER_IP}/experiment`),
38-
axios.get(`${MANAGER_IP}/trial-jobs`),
39-
axios.get(`${MANAGER_IP}/metric-data`)
40-
])
41-
.then(axios.spread((resExperiment, resTrialJobs, resMetricData) => {
42-
if (resExperiment.status === 200 && resTrialJobs.status === 200 && resMetricData.status === 200) {
43-
if (resExperiment.data.params.searchSpace) {
44-
resExperiment.data.params.searchSpace = JSON.parse(resExperiment.data.params.searchSpace);
45-
}
46-
const trialMessagesArr = TrialManager.expandJobsToTrials(resTrialJobs.data);
47-
const interResultList = resMetricData.data;
48-
Object.keys(trialMessagesArr).map(item => {
49-
// not deal with trial's hyperParameters
50-
const trialId = trialMessagesArr[item].id;
51-
// add intermediate result message
52-
trialMessagesArr[item].intermediate = [];
53-
Object.keys(interResultList).map(key => {
54-
const interId = `${interResultList[key].trialJobId}-${interResultList[key].parameterId}`;
55-
if (trialId === interId) {
56-
trialMessagesArr[item].intermediate.push(interResultList[key]);
57-
}
58-
});
59-
});
60-
const result = {
61-
experimentParameters: resExperiment.data,
62-
trialMessage: trialMessagesArr
63-
};
64-
if (this._isCompareMount === true) {
65-
this.setState({ experiment: JSON.stringify(result, null, 4) });
66-
}
36+
const experimentData = JSON.parse(JSON.stringify(this.props.experimentProfile));
37+
if (experimentData.params.searchSpace) {
38+
experimentData.params.searchSpace = JSON.parse(experimentData.params.searchSpace);
39+
}
40+
const trialMessagesArr = TRIALS.getTrialJobList();
41+
const interResultList = TRIALS.getMetricsList();
42+
Object.keys(trialMessagesArr).map(item => {
43+
// not deal with trial's hyperParameters
44+
const trialId = trialMessagesArr[item].jobId;
45+
// add intermediate result message
46+
trialMessagesArr[item].intermediate = [];
47+
Object.keys(interResultList).map(key => {
48+
const interId = interResultList[key].trialJobId;
49+
if (trialId === interId) {
50+
trialMessagesArr[item].intermediate.push(interResultList[key]);
6751
}
68-
}));
69-
}
52+
});
53+
});
54+
const result = {
55+
experimentParameters: experimentData,
56+
trialMessage: trialMessagesArr
57+
};
58+
if (this._isExperimentMount === true) {
59+
this.setState({ experiment: JSON.stringify(result, null, 4) });
60+
}
7061

62+
if (['DONE', 'ERROR', 'STOPPED'].includes(EXPERIMENT.status)) {
63+
if(this.refreshId !== null || this.refreshId !== undefined){
64+
window.clearInterval(this.refreshId);
65+
}
66+
}
67+
68+
}
69+
7170
downExperimentParameters = (): void => {
7271
const { experiment } = this.state;
7372
downFile(experiment, 'experiment.json');
@@ -78,31 +77,28 @@ class ExperimentDrawer extends React.Component<ExpDrawerProps, ExpDrawerState> {
7877
}
7978

8079
componentDidMount(): void {
81-
this._isCompareMount = true;
80+
this._isExperimentMount = true;
8281
this.getExperimentContent();
82+
this.refreshId = window.setInterval(this.getExperimentContent, 10000);
8383
window.addEventListener('resize', this.onWindowResize);
8484
}
8585

86-
componentWillReceiveProps(nextProps: ExpDrawerProps): void {
87-
const { isVisble } = nextProps;
88-
if (isVisble === true) {
89-
this.getExperimentContent();
90-
}
91-
}
92-
9386
componentWillUnmount(): void {
94-
this._isCompareMount = false;
87+
this._isExperimentMount = false;
88+
window.clearTimeout(this.refreshId);
9589
window.removeEventListener('resize', this.onWindowResize);
9690
}
9791

9892
render(): React.ReactNode {
99-
const { isVisble, closeExpDrawer } = this.props;
93+
const { closeExpDrawer } = this.props;
10094
const { experiment, expDrawerHeight } = this.state;
10195
return (
10296
<Stack className="logDrawer">
10397
<Panel
104-
isOpen={isVisble}
98+
isOpen={true}
10599
hasCloseButton={false}
100+
isLightDismiss={true}
101+
onLightDismissClick={closeExpDrawer}
106102
styles={{ root: { height: expDrawerHeight, paddingTop: 15 } }}
107103
>
108104
<Pivot style={{ minHeight: 190 }} className="log-tab-body">

src/webui/src/components/Modals/LogDrawer.tsx renamed to src/webui/src/components/Modals/LogPanel.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class LogDrawer extends React.Component<LogDrawerProps, LogDrawerState> {
9292
isOpen={true}
9393
hasCloseButton={false}
9494
isFooterAtBottom={true}
95+
isLightDismiss={true}
96+
onLightDismissClick={closeDrawer}
9597
>
9698
<div className="log-tab-body">
9799
<Pivot

src/webui/src/components/NavCon.tsx

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
Stack, initializeIcons, StackItem, CommandBarButton,
66
IContextualMenuProps, IStackTokens, IStackStyles
77
} from 'office-ui-fabric-react';
8-
import LogDrawer from './Modals/LogDrawer';
9-
import ExperimentDrawer from './Modals/ExperimentDrawer';
8+
import LogPanel from './Modals/LogPanel';
9+
import ExperimentPanel from './Modals/ExperimentPanel';
1010
import {
1111
downLoadIcon, infoIconAbout,
1212
timeIcon, disableUpdates, requency, closeTimer
1313
} from './Buttons/Icon';
1414
import { OVERVIEWTABS, DETAILTABS, NNILOGO } from './stateless-component/NNItabs';
15+
import { EXPERIMENT } from '../static/datamodel';
1516
import '../static/style/nav/nav.scss';
1617
import '../static/style/icon.scss';
1718

@@ -97,9 +98,9 @@ class NavCon extends React.Component<NavProps, NavState> {
9798
openDocs = (): void => {
9899
window.open(WEBUIDOC);
99100
}
100-
101+
101102
openGithubNNI = (): void => {
102-
const {version} = this.state;
103+
const { version } = this.state;
103104
const nniLink = `https://github.com/Microsoft/nni/tree/${version}`;
104105
window.open(nniLink);
105106
}
@@ -178,8 +179,8 @@ class NavCon extends React.Component<NavProps, NavState> {
178179
</Stack>
179180
</StackItem>
180181
{/* the drawer for dispatcher & nnimanager log message */}
181-
{isvisibleLogDrawer && <LogDrawer closeDrawer={this.closeLogDrawer} />}
182-
<ExperimentDrawer isVisble={isvisibleExperimentDrawer} closeExpDrawer={this.closeExpDrawer} />
182+
{isvisibleLogDrawer && <LogPanel closeDrawer={this.closeLogDrawer} />}
183+
{isvisibleExperimentDrawer && <ExperimentPanel closeExpDrawer={this.closeExpDrawer} experimentProfile={EXPERIMENT.profile} />}
183184
</Stack>
184185
);
185186
}

src/webui/src/components/overview/Progress.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { EXPERIMENT, TRIALS } from '../../static/datamodel';
99
import { convertTime } from '../../static/function';
1010
import ConcurrencyInput from './NumInput';
1111
import ProgressBar from './ProgressItem';
12-
import LogDrawer from '../Modals/LogDrawer';
12+
import LogDrawer from '../Modals/LogPanel';
1313
import MessageInfo from '../Modals/MessageInfo';
1414
import { infoIcon } from "../Buttons/Icon";
1515
import '../../static/style/progress.scss';

src/webui/src/static/model/trialmanager.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ class TrialManager {
4848
private latestMetricdataErrorMessage: string = ''; // metric-data-latest error message
4949
private isMetricdataRangeError: boolean = false; // metric-data-range api error filed
5050
private metricdataRangeErrorMessage: string = ''; // metric-data-latest error message
51+
private metricsList: Array<MetricDataRecord> = [];
52+
private trialJobList: Array<TrialJobInfo> = [];
53+
54+
public getMetricsList(): Array<MetricDataRecord> {
55+
return this.metricsList;
56+
}
57+
58+
public getTrialJobList(): Array<TrialJobInfo> {
59+
return this.trialJobList;
60+
}
5161

5262
public async init(): Promise<void> {
5363
while (!this.infoInitialized || !this.metricInitialized) {
@@ -230,6 +240,7 @@ class TrialManager {
230240
requestAxios(`${MANAGER_IP}/trial-jobs`)
231241
.then(data => {
232242
const newTrials = TrialManager.expandJobsToTrials(data as any);
243+
this.trialJobList = newTrials;
233244
for (const trialInfo of newTrials as TrialJobInfo[]) {
234245
if (this.trials.has(trialInfo.id)) {
235246
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -265,7 +276,10 @@ class TrialManager {
265276

266277
private async updateAllMetrics(): Promise<boolean> {
267278
return requestAxios(`${MANAGER_IP}/metric-data`)
268-
.then(data => this.doUpdateMetrics(data as any, false))
279+
.then(data => {
280+
this.metricsList = data;
281+
return this.doUpdateMetrics(data as any, false);
282+
})
269283
.catch(error => {
270284
this.isMetricdataError = true;
271285
this.MetricdataErrorMessage = `${error.message}`;

0 commit comments

Comments
 (0)