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

[webui] refactor overview page #2924

Merged
merged 14 commits into from
Oct 12, 2020
4 changes: 2 additions & 2 deletions src/webui/src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
}

.content {
width: 89%;
min-width: 1024px;
width: 87%;
margin: 0 auto;
min-width: 1200px;
margin-top: 74px;
margin-bottom: 30px;
}
Expand Down
44 changes: 14 additions & 30 deletions src/webui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { COLUMN } from './static/const';
import { EXPERIMENT, TRIALS } from './static/datamodel';
import NavCon from './components/NavCon';
import MessageInfo from './components/modals/MessageInfo';
import { TrialConfigButton } from './components/public-child/config/TrialConfigButton';
import './App.scss';

interface AppState {
Expand All @@ -30,12 +31,13 @@ export const AppContext = React.createContext({
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
changeMetricGraphMode: (val: 'max' | 'min') => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
changeEntries: (val: string) => {}
changeEntries: (val: string) => {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think (_: string) => {} will suppress the warning.

Why no-empty-function is enabled? Doesn't make any sense to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me. And this rule is discussed result?

// eslint-disable-next-line @typescript-eslint/no-empty-function, @typescript-eslint/no-unused-vars
updateOverviewPage: () => {}
});

class App extends React.Component<{}, AppState> {
private timerId!: number | undefined;
private dataFormatimer!: number;
private firstLoad: boolean = false; // when click refresh selector options
constructor(props: {}) {
super(props);
Expand All @@ -60,35 +62,8 @@ class App extends React.Component<{}, AppState> {
metricGraphMode: EXPERIMENT.optimizeMode === 'minimize' ? 'min' : 'max'
}));
this.timerId = window.setTimeout(this.refresh, this.state.interval * 100);
// final result is legal
// get a succeed trial,see final result data's format
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.dataFormatimer = window.setInterval(this.getFinalDataFormat, this.state.interval * 1000);
}

getFinalDataFormat = (): void => {
for (let i = 0; this.state.isillegalFinal === false; i++) {
if (TRIALS.succeededTrials()[0] !== undefined && TRIALS.succeededTrials()[0].final !== undefined) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const oneSucceedTrial = JSON.parse(JSON.parse(TRIALS.succeededTrials()[0].final!.data));
if (typeof oneSucceedTrial === 'number' || oneSucceedTrial.hasOwnProperty('default')) {
window.clearInterval(this.dataFormatimer);
break;
} else {
// illegal final data
this.setState(() => ({
isillegalFinal: true,
expWarningMessage:
'WebUI support final result as number and dictornary includes default keys, your experiment final result is illegal, please check your data.'
}));
window.clearInterval(this.dataFormatimer);
}
} else {
break;
}
}
};

changeInterval = (interval: number): void => {
window.clearTimeout(this.timerId);
if (interval === 0) {
Expand Down Expand Up @@ -116,6 +91,12 @@ class App extends React.Component<{}, AppState> {
this.setState({ bestTrialEntries: entries });
};

updateOverviewPage = (): void => {
this.setState(state => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the parenthesis is not necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually needed.

experimentUpdateBroadcast: state.experimentUpdateBroadcast + 1
}));
};

shouldComponentUpdate(nextProps: any, nextState: AppState): boolean {
if (!(nextState.isUpdate || nextState.isUpdate === undefined)) {
nextState.isUpdate = true;
Expand Down Expand Up @@ -155,6 +136,8 @@ class App extends React.Component<{}, AppState> {
</div>
<Stack className='contentBox'>
<Stack className='content'>
{/* search space & config */}
<TrialConfigButton />
{/* if api has error field, show error message */}
{errorList.map(
(item, key) =>
Expand All @@ -179,7 +162,8 @@ class App extends React.Component<{}, AppState> {
metricGraphMode,
changeMetricGraphMode: this.changeMetricGraphMode,
bestTrialEntries,
changeEntries: this.changeEntries
changeEntries: this.changeEntries,
updateOverviewPage: this.updateOverviewPage
}}
>
{this.props.children}
Expand Down
Loading