-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[webui] format code by eslint and prettier #2744
Changes from 4 commits
2de9dfc
91a1591
089c849
bb524eb
fc1eea8
7d772a4
865b22c
96d1009
63973a4
82cc061
2544190
5e70a54
fa20bdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 4 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And I wonder why your files do not have trailing new line even though this is set to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but |
||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/build/** | ||
/scripts/** | ||
/src/serviceWorker.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
printWidth: 120, | ||
semi: true, | ||
trailingComma: 'none', | ||
bracketSpacing: true, | ||
eslintIntegration: true, | ||
singleQuote: true, | ||
jsxSingleQuote: true | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ 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); | ||
this.state = { | ||
|
@@ -41,7 +41,7 @@ class App extends React.Component<{}, AppState> { | |
this.setState(state => ({ experimentUpdateBroadcast: state.experimentUpdateBroadcast + 1 })); | ||
this.setState(state => ({ trialsUpdateBroadcast: state.trialsUpdateBroadcast + 1 })); | ||
this.timerId = window.setTimeout(this.refresh, this.state.interval * 1000); | ||
this.setState({ metricGraphMode: (EXPERIMENT.optimizeMode === 'minimize' ? 'min' : 'max') }); | ||
this.setState({ metricGraphMode: EXPERIMENT.optimizeMode === 'minimize' ? 'min' : 'max' }); | ||
// final result is legal | ||
// get a succeed trial,see final result data's format | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
|
@@ -60,18 +60,18 @@ class App extends React.Component<{}, AppState> { | |
// 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.' | ||
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) { | ||
return; | ||
|
@@ -82,31 +82,37 @@ class App extends React.Component<{}, AppState> { | |
this.firstLoad = true; | ||
this.refresh(); | ||
}); | ||
|
||
} | ||
}; | ||
|
||
// TODO: use local storage | ||
changeColumn = (columnList: string[]): void => { | ||
this.setState({ columnList: columnList }); | ||
} | ||
}; | ||
|
||
changeMetricGraphMode = (val: 'max' | 'min'): void => { | ||
this.setState({ metricGraphMode: val }); | ||
} | ||
}; | ||
|
||
// overview best trial module | ||
changeEntries = (entries: string): void => { | ||
this.setState({ bestTrialEntries: entries }); | ||
} | ||
}; | ||
|
||
render(): React.ReactNode { | ||
const { interval, columnList, experimentUpdateBroadcast, trialsUpdateBroadcast, | ||
metricGraphMode, isillegalFinal, expWarningMessage, bestTrialEntries | ||
const { | ||
interval, | ||
columnList, | ||
experimentUpdateBroadcast, | ||
trialsUpdateBroadcast, | ||
metricGraphMode, | ||
isillegalFinal, | ||
expWarningMessage, | ||
bestTrialEntries | ||
} = this.state; | ||
if (experimentUpdateBroadcast === 0 || trialsUpdateBroadcast === 0) { | ||
return null; // TODO: render a loading page | ||
return null; // TODO: render a loading page | ||
} | ||
|
||
const errorList = [ | ||
{ errorWhere: TRIALS.jobListError(), errorMessage: TRIALS.getJobErrorMessage() }, | ||
{ errorWhere: EXPERIMENT.experimentError(), errorMessage: EXPERIMENT.getExperimentMessage() }, | ||
|
@@ -117,39 +123,43 @@ class App extends React.Component<{}, AppState> { | |
]; | ||
|
||
const reactPropsChildren = React.Children.map(this.props.children, child => | ||
React.cloneElement( | ||
child as React.ReactElement<any>, { | ||
React.cloneElement(child as React.ReactElement<any>, { | ||
interval, | ||
columnList, changeColumn: this.changeColumn, | ||
columnList, | ||
changeColumn: this.changeColumn, | ||
experimentUpdateBroadcast, | ||
trialsUpdateBroadcast, | ||
metricGraphMode, changeMetricGraphMode: this.changeMetricGraphMode, | ||
bestTrialEntries, changeEntries: this.changeEntries | ||
metricGraphMode, | ||
changeMetricGraphMode: this.changeMetricGraphMode, | ||
bestTrialEntries, | ||
changeEntries: this.changeEntries | ||
}) | ||
); | ||
|
||
return ( | ||
<Stack className="nni" style={{ minHeight: window.innerHeight }}> | ||
<div className="header"> | ||
<div className="headerCon"> | ||
<Stack className='nni' style={{ minHeight: window.innerHeight }}> | ||
<div className='header'> | ||
<div className='headerCon'> | ||
<NavCon changeInterval={this.changeInterval} refreshFunction={this.lastRefresh} /> | ||
</div> | ||
</div> | ||
<Stack className="contentBox"> | ||
<Stack className="content"> | ||
<Stack className='contentBox'> | ||
<Stack className='content'> | ||
{/* if api has error field, show error message */} | ||
{ | ||
errorList.map((item, key) => { | ||
return ( | ||
item.errorWhere && <div key={key} className="warning"> | ||
<MessageInfo info={item.errorMessage} typeInfo="error" /> | ||
{errorList.map((item, key) => { | ||
return ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think so. We can use arrow function rules to standardize it. |
||
item.errorWhere && ( | ||
<div key={key} className='warning'> | ||
<MessageInfo info={item.errorMessage} typeInfo='error' /> | ||
</div> | ||
); | ||
}) | ||
} | ||
{isillegalFinal && <div className="warning"> | ||
<MessageInfo info={expWarningMessage} typeInfo="warning" /> | ||
</div>} | ||
) | ||
); | ||
})} | ||
{isillegalFinal && ( | ||
<div className='warning'> | ||
<MessageInfo info={expWarningMessage} typeInfo='warning' /> | ||
</div> | ||
)} | ||
{reactPropsChildren} | ||
</Stack> | ||
</Stack> | ||
|
@@ -158,7 +168,6 @@ class App extends React.Component<{}, AppState> { | |
} | ||
|
||
private refresh = async (): Promise<void> => { | ||
|
||
// resolve this question: 10s -> 20s, page refresh twice. | ||
// only refresh this page after clicking the refresh options | ||
if (this.firstLoad !== true) { | ||
|
@@ -169,7 +178,6 @@ class App extends React.Component<{}, AppState> { | |
if (trialsUpdated) { | ||
this.setState(state => ({ trialsUpdateBroadcast: state.trialsUpdateBroadcast + 1 })); | ||
} | ||
|
||
} else { | ||
this.firstLoad = false; | ||
} | ||
|
@@ -183,8 +191,7 @@ class App extends React.Component<{}, AppState> { | |
} | ||
|
||
this.timerId = window.setTimeout(this.refresh, this.state.interval * 1000); | ||
|
||
} | ||
}; | ||
|
||
public async lastRefresh(): Promise<void> { | ||
await EXPERIMENT.update(); | ||
|
@@ -195,5 +202,3 @@ class App extends React.Component<{}, AppState> { | |
} | ||
|
||
export default App; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,23 @@ interface CheckBoxItems { | |
onChange: () => void; | ||
} | ||
class ChangeColumnComponent extends React.Component<ChangeColumnProps, ChangeColumnState> { | ||
|
||
constructor(props: ChangeColumnProps) { | ||
super(props); | ||
this.state = { userSelectColumnList: this.props.selectedColumn, originSelectColumnList: this.props.selectedColumn }; | ||
this.state = { | ||
userSelectColumnList: this.props.selectedColumn, | ||
originSelectColumnList: this.props.selectedColumn | ||
}; | ||
} | ||
|
||
makeChangeHandler = (label: string): any => { | ||
return (ev: any, checked: boolean): void => this.onCheckboxChange(ev, label, checked); | ||
} | ||
}; | ||
|
||
onCheckboxChange = (ev: React.FormEvent<HTMLElement | HTMLInputElement> | undefined, label: string, val?: boolean, ): void => { | ||
onCheckboxChange = ( | ||
ev: React.FormEvent<HTMLElement | HTMLInputElement> | undefined, | ||
label: string, | ||
val?: boolean | ||
): void => { | ||
const source: string[] = JSON.parse(JSON.stringify(this.state.userSelectColumnList)); | ||
if (val === true) { | ||
if (!source.includes(label)) { | ||
|
@@ -41,7 +47,7 @@ class ChangeColumnComponent extends React.Component<ChangeColumnProps, ChangeCol | |
} else { | ||
if (source.includes(label)) { | ||
// remove from source | ||
const result = source.filter((item) => item !== label); | ||
const result = source.filter(item => item !== label); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is less clear to human. It's hard to figure out associative order at first glance to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alwaysParens: |
||
this.setState(() => ({ userSelectColumnList: result })); | ||
} | ||
} | ||
|
@@ -88,11 +94,11 @@ class ChangeColumnComponent extends React.Component<ChangeColumnProps, ChangeCol | |
} | ||
this.props.changeColumn(sortColumn); | ||
this.hideDialog(); // hide dialog | ||
} | ||
}; | ||
|
||
hideDialog = (): void => { | ||
this.props.hideShowColumnDialog(); | ||
} | ||
}; | ||
|
||
// user exit dialog | ||
cancelOption = (): void => { | ||
|
@@ -101,7 +107,7 @@ class ChangeColumnComponent extends React.Component<ChangeColumnProps, ChangeCol | |
this.setState({ userSelectColumnList: originSelectColumnList }, () => { | ||
this.hideDialog(); | ||
}); | ||
} | ||
}; | ||
|
||
render(): React.ReactNode { | ||
const { showColumn, isHideDialog } = this.props; | ||
|
@@ -129,14 +135,14 @@ class ChangeColumnComponent extends React.Component<ChangeColumnProps, ChangeCol | |
styles: { main: { maxWidth: 450 } } | ||
}} | ||
> | ||
<div className="columns-height"> | ||
<div className='columns-height'> | ||
{renderOptions.map(item => { | ||
return <Checkbox key={item.label} {...item} styles={{ root: { marginBottom: 8 } }} /> | ||
return <Checkbox key={item.label} {...item} styles={{ root: { marginBottom: 8 } }} />; | ||
})} | ||
</div> | ||
<DialogFooter> | ||
<PrimaryButton text="Save" onClick={this.saveUserSelectColumn} /> | ||
<DefaultButton text="Cancel" onClick={this.cancelOption} /> | ||
<PrimaryButton text='Save' onClick={this.saveUserSelectColumn} /> | ||
<DefaultButton text='Cancel' onClick={this.cancelOption} /> | ||
</DialogFooter> | ||
</Dialog> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this file used by a specific text editor? If yes it should not be committed to code tree.