From 22e651c51593cad89e44b00a47346e7a2a368f4e Mon Sep 17 00:00:00 2001 From: Sebastien Jourdain Date: Tue, 15 Mar 2016 12:07:56 -0600 Subject: [PATCH 1/2] fix(ESLint): Fix various linting issue --- .eslintrc.js | 15 ++---- src/network/TaskflowManager/index.js | 6 +-- src/network/remoteClient/Project.js | 7 +-- src/network/remoteClient/Simulation.js | 7 +-- src/pages/Preferences/Cluster/ClusterForm.js | 8 +-- src/pages/Project/All/index.js | 13 ++--- src/pages/Project/Edit/index.js | 8 +-- src/pages/Project/New/index.js | 8 +-- src/pages/Project/View/index.js | 19 +++---- src/pages/Simulation/Edit/index.js | 8 +-- src/pages/Simulation/New/index.js | 8 +-- src/panels/IconActionList/index.js | 2 +- src/panels/ItemEditor/index.js | 18 +++---- src/panels/JobMonitor/index.js | 11 +++-- src/panels/SchedulerConfig/index.js | 49 +++++++++++++++++++ src/panels/Toolbar/index.js | 16 +++--- src/tools/visualizer/index.js | 8 +-- .../common/steps/Simulation/View/index.js | 8 +-- .../common/steps/Visualization/Start/index.js | 11 +++-- src/workflows/pyfr/pyfr-exec/index.js | 2 +- .../components/steps/Input/index.js | 2 +- .../steps/Visualization/View/index.js | 8 +-- 22 files changed, 146 insertions(+), 96 deletions(-) create mode 100644 src/panels/SchedulerConfig/index.js diff --git a/.eslintrc.js b/.eslintrc.js index 8968b6e7..b26ce353 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,24 +1,15 @@ module.exports = { extends: 'airbnb', rules: { - 'array-bracket-spacing': 0, - 'guard-for-in': 0, 'max-len': [1, 160, 4, {"ignoreUrls": true}], - 'no-alert': 0, 'no-console': 0, - 'no-multi-spaces': 0, + 'no-multi-spaces': [2, { exceptions: { "ImportDeclaration": true } }], 'no-nested-ternary': 0, - 'no-param-reassign': 0, - 'no-throw-literal': 0, + 'no-param-reassign': [2, { props: false }], 'no-unused-vars': [2, { args: 'none' }], 'no-var': 0, - 'react/jsx-closing-bracket-location': 1, - 'react/jsx-indent-props': 1, - 'react/jsx-space-before-closing': 1, + 'one-var': 0, 'react/no-is-mounted': 1, 'react/prefer-es6-class': 0, - 'react/sort-comp': 0, - 'spaced-comment': 1, - 'one-var': 0, } }; diff --git a/src/network/TaskflowManager/index.js b/src/network/TaskflowManager/index.js index c39ea369..b93ef114 100644 --- a/src/network/TaskflowManager/index.js +++ b/src/network/TaskflowManager/index.js @@ -102,9 +102,9 @@ client.onEvent((resp) => { // if nothing was updated check the endpoints for new items. if (!obj) { // Let's refresh all taskflows - for (const taskflowId in taskflows) { - updateTaskFlow(taskflowId); - } + Object.keys(taskflows).forEach(id => { + updateTaskFlow(id); + }); } }); diff --git a/src/network/remoteClient/Project.js b/src/network/remoteClient/Project.js index bd4275b1..dd2b692b 100644 --- a/src/network/remoteClient/Project.js +++ b/src/network/remoteClient/Project.js @@ -31,7 +31,8 @@ function createItemForProject(project, name, file) { }); } -export function saveProject(project, attachments) { +export function saveProject(project_, attachments) { + var project = project_; if (!project._id) { let folder; let outputFolder; @@ -72,9 +73,9 @@ export function saveProject(project, attachments) { .then((resp) => { if (attachments) { const promises = []; - for (const file in attachments) { + Object.keys(attachments).forEach(file => { promises.push(createItemForProject(project, file, attachments[file])); - } + }); promises.push(project); return Promise.all(promises); } diff --git a/src/network/remoteClient/Simulation.js b/src/network/remoteClient/Simulation.js index 014a2465..96109a5f 100644 --- a/src/network/remoteClient/Simulation.js +++ b/src/network/remoteClient/Simulation.js @@ -47,7 +47,8 @@ export function addEmptyFileForSimulation(simulation, name) { // if there's not a sim.id, create a sim with two folders input and output // otherwise update simulation -export function saveSimulation(simulation, attachments) { +export function saveSimulation(simulation_, attachments) { + var simulation = simulation_; if (!simulation._id) { let folder; let outputFolder; @@ -88,9 +89,9 @@ export function saveSimulation(simulation, attachments) { .then((resp) => { if (attachments) { const promises = []; - for (const file in attachments) { + Object.keys(attachments).forEach(file => { promises.push(createItemForSimulation(simulation, file, attachments[file])); - } + }); promises.push(simulation); return Promise.all(promises); } diff --git a/src/pages/Preferences/Cluster/ClusterForm.js b/src/pages/Preferences/Cluster/ClusterForm.js index eaf7ed5e..2a609edc 100644 --- a/src/pages/Preferences/Cluster/ClusterForm.js +++ b/src/pages/Preferences/Cluster/ClusterForm.js @@ -12,20 +12,20 @@ const preventDefault = (e) => { e.preventDefault(); }; const allConfigs = {}; const wfNames = []; -for (const wfName in Workflows) { +Object.keys(Workflows).forEach(wfName => { const wf = Workflows[wfName]; allConfigs[wfName] = {}; let foundConfig = false; if (wf.config && wf.config.cluster) { - for (const propKey in wf.config.cluster) { + Object.keys(wf.config.cluster).forEach(propKey => { allConfigs[wfName][propKey] = wf.config.cluster[propKey]; foundConfig = true; - } + }); } if (foundConfig) { wfNames.push(wfName); } -} +}); export default React.createClass({ diff --git a/src/pages/Project/All/index.js b/src/pages/Project/All/index.js index 03c73da9..9ed170bd 100644 --- a/src/pages/Project/All/index.js +++ b/src/pages/Project/All/index.js @@ -28,12 +28,6 @@ export default React.createClass({ this.updateProjectList(); }, - updateProjectList() { - client.listProjects() - .then(resp => this.setState({ projects: resp.data })) - .catch(err => console.log('Error Project/All', err)); - }, - onAction(action, selectedItems) { if (selectedItems) { this[action](selectedItems); @@ -42,6 +36,12 @@ export default React.createClass({ } }, + updateProjectList() { + client.listProjects() + .then(resp => this.setState({ projects: resp.data })) + .catch(err => console.log('Error Project/All', err)); + }, + addItem() { const filter = ''; this.context.router.replace({ @@ -52,6 +52,7 @@ export default React.createClass({ }, deleteItems(items) { + /* eslint-disable no-alert */ if (!confirm(`Are you sure you want to delete ${items.length === 1 ? 'this' : 'these'} ${items.length} project${items.length === 1 ? '' : 's'}?`)) { return; } diff --git a/src/pages/Project/Edit/index.js b/src/pages/Project/Edit/index.js index 002f832a..0a1c7107 100644 --- a/src/pages/Project/Edit/index.js +++ b/src/pages/Project/Edit/index.js @@ -34,16 +34,16 @@ export default React.createClass({ } }, + onAction(action, data, attachement) { + this[action](data, attachement); + }, + updateState(id = this.props.params.id) { client.getProject(id) .then(resp => this.setState({ project: resp.data })) .catch(err => console.log('Error: Project/Edit-get', err)); }, - onAction(action, data, attachement) { - this[action](data, attachement); - }, - editProject(data, attachement) { const project = merge(this.state.project, data); client.saveProject(project) diff --git a/src/pages/Project/New/index.js b/src/pages/Project/New/index.js index 452bb811..18460a2c 100644 --- a/src/pages/Project/New/index.js +++ b/src/pages/Project/New/index.js @@ -26,6 +26,10 @@ export default React.createClass({ }; }, + onAction(action, data, attachements) { + this[action](data, attachements); + }, + updateForm(e) { var key = e.target.dataset.name, value = e.target.value; @@ -33,10 +37,6 @@ export default React.createClass({ this.setState({ [key]: value }); }, - onAction(action, data, attachements) { - this[action](data, attachements); - }, - newProject(data, attachements) { const { name, description } = data, type = this.state.type, diff --git a/src/pages/Project/View/index.js b/src/pages/Project/View/index.js index a54653bb..b2a39a39 100644 --- a/src/pages/Project/View/index.js +++ b/src/pages/Project/View/index.js @@ -36,6 +36,14 @@ export default React.createClass({ } }, + onAction(action, selectedItems) { + if (selectedItems) { + this[action](selectedItems); + } else { + this[action](); + } + }, + updateState(id = this.props.params.id) { client.getProject(id) .then(resp => this.setState({ project: resp.data })) @@ -52,19 +60,12 @@ export default React.createClass({ }); }, - onAction(action, selectedItems) { - if (selectedItems) { - this[action](selectedItems); - } else { - this[action](); - } - }, - addItem() { this.context.router.replace(`/New/Simulation/${this.props.params.id}`); }, deleteItems(items) { + /* eslint-disable no-alert */ if (!confirm(`Are you sure you want to delete ${items.length === 1 ? 'this' : 'these'} ${items.length} simulation${items.length === 1 ? '' : 's'}?`)) { return; } @@ -81,7 +82,7 @@ export default React.createClass({ return ( { @@ -54,10 +58,6 @@ export default React.createClass({ }); }, - onAction(action, data, attachement) { - this[action](data, attachement); - }, - saveSimulation(data) { const simulation = merge(this.state.simulation, data); diff --git a/src/pages/Simulation/New/index.js b/src/pages/Simulation/New/index.js index 3cd944c3..98e2aaf3 100644 --- a/src/pages/Simulation/New/index.js +++ b/src/pages/Simulation/New/index.js @@ -34,6 +34,10 @@ export default React.createClass({ } }, + onAction(action, data, attachements) { + this[action](data, attachements); + }, + updateProject(id = this.props.params.projectId) { client.getProject(id) .then(resp => this.setState({ project: resp.data, error: false })) @@ -44,10 +48,6 @@ export default React.createClass({ }); }, - onAction(action, data, attachements) { - this[action](data, attachements); - }, - newSimulation(data, attachements) { const { name, description } = data, projectId = this.props.params.projectId, diff --git a/src/panels/IconActionList/index.js b/src/panels/IconActionList/index.js index a96af5a7..d7761451 100644 --- a/src/panels/IconActionList/index.js +++ b/src/panels/IconActionList/index.js @@ -32,7 +32,7 @@ export default React.createClass({ key={action.name} data-action={action.name} onClick={this.onAction} - className={ [ style.actionButton, action.icon ].join(' ') } + className={ [style.actionButton, action.icon].join(' ') } > )} ); diff --git a/src/panels/ItemEditor/index.js b/src/panels/ItemEditor/index.js index a466a8fe..df4a2fa1 100644 --- a/src/panels/ItemEditor/index.js +++ b/src/panels/ItemEditor/index.js @@ -48,9 +48,9 @@ const FileUploadEntry = React.createClass({ if (this.props.owner && this.props.postProcess) { this.props.postProcess(file) .then(metadata => { - for (const key in metadata) { + Object.keys(metadata).forEach(key => { this.props.owner().addMetadata(key, metadata[key]); - } + }); }); } }, @@ -148,6 +148,12 @@ export default React.createClass({ }; }, + onAction(action) { + if (this.props.onAction) { + this.props.onAction(action, this.state, this.attachement); + } + }, + addAttachement(name, file) { const attachement = this.attachement || {}; attachement[name] = file; @@ -167,17 +173,11 @@ export default React.createClass({ this.setState({ [key]: value }); }, - onAction(action) { - if (this.props.onAction) { - this.props.onAction(action, this.state, this.attachement); - } - }, - render() { return (
diff --git a/src/panels/JobMonitor/index.js b/src/panels/JobMonitor/index.js index 5da8d4df..5de462a3 100644 --- a/src/panels/JobMonitor/index.js +++ b/src/panels/JobMonitor/index.js @@ -56,7 +56,7 @@ export default React.createClass({ {this.state.jobs.map(job =>
{job.name} -
{job.status}
+
{job.status}
)}
@@ -74,7 +74,7 @@ export default React.createClass({ return (
{task.name.split('.').pop()} -
{task.status}
+
{task.status}
); } return ( @@ -87,13 +87,14 @@ export default React.createClass({
                             { // reduce log array to a string with formatted entries
                               task.log.reduce((prevVal, entry, index) => {
-                                prevVal += `[${formatTime(entry.created)}] ${entry.levelname}: ${entry.msg}\n`;
+                                var content = prevVal;
+                                content += `[${formatTime(entry.created)}] ${entry.levelname}: ${entry.msg}\n`;
 
                                 if (entry.exc_info) {
-                                  prevVal += entry.exc_info.join('\n');
+                                  content += entry.exc_info.join('\n');
                                 }
 
-                                return prevVal;
+                                return content;
                               }, '')
                             }
                           
diff --git a/src/panels/SchedulerConfig/index.js b/src/panels/SchedulerConfig/index.js new file mode 100644 index 00000000..cc8696dd --- /dev/null +++ b/src/panels/SchedulerConfig/index.js @@ -0,0 +1,49 @@ +import React from 'react'; +import deepEquals from 'mout/src/lang/deepEquals'; + +import style from 'HPCCloudStyle/ItemEditor.mcss'; + +export default React.createClass({ + + displayName: 'SchedulerConfig', + + propTypes: { + config: React.PropTypes.object, + onChange: React.PropTypes.func, + }, + + getInitialState() { + return { + config: this.props.config || {}, + }; + }, + + componentWillReceiveProps(nextProps) { + const config = nextProps.config, + oldConfig = this.props.config; + + if (!deepEquals(config, oldConfig)) { + this.setState({ config }); + } + }, + + render() { + return ( +
+
+ + +
+
); + }, +}); diff --git a/src/panels/Toolbar/index.js b/src/panels/Toolbar/index.js index a1c2dc07..1062f01a 100644 --- a/src/panels/Toolbar/index.js +++ b/src/panels/Toolbar/index.js @@ -31,6 +31,13 @@ export default React.createClass({ }; }, + onAction(event) { + const action = event.target.dataset.action; + if (this.props.onAction) { + this.props.onAction(action); + } + }, + updateFilter(e) { const filter = e.target.value; @@ -41,13 +48,6 @@ export default React.createClass({ }); }, - onAction(event) { - const action = event.target.dataset.action; - if (this.props.onAction) { - this.props.onAction(action); - } - }, - render() { return (