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

[webui] format code by eslint and prettier #2744

Merged
merged 13 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/webui/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true
Copy link
Contributor

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.


[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
Copy link
Contributor

@liuzhe-lz liuzhe-lz Aug 12, 2020

Choose a reason for hiding this comment

The 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 true...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but .tsx .scss these files all have new line in last line.


[*.md]
trim_trailing_whitespace = false
3 changes: 3 additions & 0 deletions src/webui/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/**
/scripts/**
/src/serviceWorker.ts
12 changes: 9 additions & 3 deletions src/webui/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
"@typescript-eslint",
"eslint-plugin-prettier"
],
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
"plugin:@typescript-eslint/recommended",
"prettier/react",
"prettier"
],
"rules": {
"prettier/prettier": 2,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/consistent-type-assertions": 0,
"@typescript-eslint/no-inferrable-types": 0,
"no-inner-declarations": 0,
"@typescript-eslint/no-var-requires": 0,
"react/display-name": 0
"react/display-name": 0,
"no-empty": 2,
"no-multiple-empty-lines": [2, { "max": 1 }]
},
"settings": {
"react": {
Expand Down
5 changes: 4 additions & 1 deletion src/webui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.12.4",
"eslint-plugin-react-hooks": "^1.5.0",
"eslint-config-prettier": "^6.1.0",
"eslint-plugin-prettier": "^3.1.0",
"prettier": "^1.18.2",
"express": "^4.17.1",
"npx": "^10.2.0",
"typescript": "^3.8.0"
Expand Down Expand Up @@ -106,4 +109,4 @@
"resolutions": {
"npm": ">=6.14.4"
}
}
}
9 changes: 9 additions & 0 deletions src/webui/prettier.config.js
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
};
87 changes: 46 additions & 41 deletions src/webui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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() },
Expand All @@ -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 (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is return necessary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand All @@ -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) {
Expand All @@ -169,7 +178,6 @@ class App extends React.Component<{}, AppState> {
if (trialsUpdated) {
this.setState(state => ({ trialsUpdateBroadcast: state.trialsUpdateBroadcast + 1 }));
}

} else {
this.firstLoad = false;
}
Expand All @@ -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();
Expand All @@ -195,5 +202,3 @@ class App extends React.Component<{}, AppState> {
}

export default App;


20 changes: 16 additions & 4 deletions src/webui/src/components/Buttons/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ const downLoadIcon = { iconName: 'Download' };
const infoIconAbout = { iconName: 'info' };
const timeIcon = { iconName: 'ReminderTime' };
const disableUpdates = { iconName: 'DisableUpdates' };
const requency = { iconName: 'Timer' };
const requency = { iconName: 'Timer' };
const closeTimer = { iconName: 'Blocked2' };
const LineChart = <Icon iconName='LineChart' />;

export { infoIcon, warining, errorBadge, completed, blocked,
infoIconAbout, copy, tableListIcon, downLoadIcon, timeIcon,
disableUpdates, requency, closeTimer, LineChart
export {
infoIcon,
warining,
errorBadge,
completed,
blocked,
infoIconAbout,
copy,
tableListIcon,
downLoadIcon,
timeIcon,
disableUpdates,
requency,
closeTimer,
LineChart
};
2 changes: 1 addition & 1 deletion src/webui/src/components/Buttons/ModalTheme.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ const iconButtonStyles = mergeStyleSets({
}
});

export { contentStyles, iconButtonStyles };
export { contentStyles, iconButtonStyles };
30 changes: 18 additions & 12 deletions src/webui/src/components/Modals/ChangeColumnComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Copy link
Contributor

@liuzhe-lz liuzhe-lz Aug 10, 2020

Choose a reason for hiding this comment

The 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.
I personally prefer item => (item !== label), but according to line 44 of App.tsx maybe tslint doesn't like it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alwaysParens: avoid | always;
default val is avoid, not add () for arrow function.
So we change it to always?

this.setState(() => ({ userSelectColumnList: result }));
}
}
Expand Down Expand Up @@ -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 => {
Expand All @@ -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;
Expand Down Expand Up @@ -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>
Expand Down
Loading