From 7f17ba7ee238516cd025031f31e39a1db8d89a9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CA=88=E1=B5=83=E1=B5=A2?= Date: Thu, 29 Aug 2019 21:29:34 -0700 Subject: [PATCH] removes unused state values and redundant presence checks (#8130) --- .../SqlLab/components/ScheduleQueryButton.jsx | 12 ++++++------ .../src/SqlLab/components/ShareSqlLabQuery.jsx | 10 ++++------ .../src/SqlLab/components/SqlEditorLeftBar.jsx | 18 +++++++----------- .../assets/src/components/ErrorBoundary.jsx | 11 +++++++---- .../components/gridComponents/Chart.jsx | 2 +- 5 files changed, 25 insertions(+), 28 deletions(-) diff --git a/superset/assets/src/SqlLab/components/ScheduleQueryButton.jsx b/superset/assets/src/SqlLab/components/ScheduleQueryButton.jsx index d8f82fba62..09a7ddb3b2 100644 --- a/superset/assets/src/SqlLab/components/ScheduleQueryButton.jsx +++ b/superset/assets/src/SqlLab/components/ScheduleQueryButton.jsx @@ -125,8 +125,8 @@ class ScheduleQueryButton extends React.PureComponent { onDescriptionChange(e) { this.setState({ description: e.target.value }); } - toggleSchedule(e) { - this.setState({ target: e.target, showSchedule: !this.state.showSchedule }); + toggleSchedule() { + this.setState({ showSchedule: !this.state.showSchedule }); } renderModalBody() { return ( @@ -170,9 +170,7 @@ class ScheduleQueryButton extends React.PureComponent { {this.props.scheduleQueryWarning && ( - - {this.props.scheduleQueryWarning} - + {this.props.scheduleQueryWarning} )} @@ -183,7 +181,9 @@ class ScheduleQueryButton extends React.PureComponent { return ( { this.saveModal = ref; }} + ref={(ref) => { + this.saveModal = ref; + }} modalTitle={t('Schedule Query')} modalBody={this.renderModalBody()} triggerNode={ diff --git a/superset/assets/src/SqlLab/components/ShareSqlLabQuery.jsx b/superset/assets/src/SqlLab/components/ShareSqlLabQuery.jsx index dce572ecea..176a4fc77d 100644 --- a/superset/assets/src/SqlLab/components/ShareSqlLabQuery.jsx +++ b/superset/assets/src/SqlLab/components/ShareSqlLabQuery.jsx @@ -43,7 +43,6 @@ class ShareSqlLabQuery extends React.Component { super(props); this.state = { shortUrl: t('Loading ...'), - showOverlay: false, }; this.getCopyUrl = this.getCopyUrl.bind(this); } @@ -57,11 +56,10 @@ class ShareSqlLabQuery extends React.Component { this.setState({ shortUrl }); }) .catch((response) => { - getClientErrorObject(response) - .then(({ error }) => { - this.props.addDangerToast(error); - this.setState({ shortUrl: t('Error') }); - }); + getClientErrorObject(response).then(({ error }) => { + this.props.addDangerToast(error); + this.setState({ shortUrl: t('Error') }); + }); }); } diff --git a/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx b/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx index bc61f83de7..bf7afff727 100644 --- a/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx +++ b/superset/assets/src/SqlLab/components/SqlEditorLeftBar.jsx @@ -42,12 +42,6 @@ const defaultProps = { export default class SqlEditorLeftBar extends React.PureComponent { constructor(props) { super(props); - this.state = { - schemaLoading: false, - schemaOptions: [], - tableLoading: false, - tableOptions: [], - }; this.resetState = this.resetState.bind(this); this.onSchemaChange = this.onSchemaChange.bind(this); this.onSchemasLoad = this.onSchemasLoad.bind(this); @@ -76,7 +70,10 @@ export default class SqlEditorLeftBar extends React.PureComponent { } dbMutator(data) { - const options = data.result.map(db => ({ value: db.id, label: db.database_name })); + const options = data.result.map(db => ({ + value: db.id, + label: db.database_name, + })); this.props.actions.setDatabases(data.result); if (data.result.length === 0) { this.props.actions.addDangerToast(t("It seems you don't have access to any database")); @@ -89,12 +86,10 @@ export default class SqlEditorLeftBar extends React.PureComponent { } changeTable(tableOpt) { if (!tableOpt) { - this.setState({ tableName: '' }); return; } const schemaName = tableOpt.value.schema; const tableName = tableOpt.value.table; - this.setState({ tableName }); this.props.actions.queryEditorSetSchema(this.props.queryEditor, schemaName); this.props.actions.addTable(this.props.queryEditor, tableName, schemaName); } @@ -129,10 +124,11 @@ export default class SqlEditorLeftBar extends React.PureComponent { ))} - {shouldShowReset && + {shouldShowReset && ( } + + )} ); } diff --git a/superset/assets/src/components/ErrorBoundary.jsx b/superset/assets/src/components/ErrorBoundary.jsx index 0f1605a027..926109486e 100644 --- a/superset/assets/src/components/ErrorBoundary.jsx +++ b/superset/assets/src/components/ErrorBoundary.jsx @@ -45,14 +45,17 @@ export default class ErrorBoundary extends React.Component { render() { const { error, info } = this.state; if (error) { - const firstLine = error ? error.toString() : null; + const firstLine = error.toString(); const message = ( - {t('Unexpected error')}{firstLine ? `: ${firstLine}` : ''} - ); + {t('Unexpected error')} + {firstLine ? `: ${firstLine}` : ''} + + ); if (this.props.showMessage) { return ( - ); + + ); } return null; } diff --git a/superset/assets/src/dashboard/components/gridComponents/Chart.jsx b/superset/assets/src/dashboard/components/gridComponents/Chart.jsx index 61412f3e30..330910bd2c 100644 --- a/superset/assets/src/dashboard/components/gridComponents/Chart.jsx +++ b/superset/assets/src/dashboard/components/gridComponents/Chart.jsx @@ -225,7 +225,7 @@ class Chart extends React.Component { const { queryResponse, chartUpdateEndTime } = chart; const isCached = queryResponse && queryResponse.is_cached; const cachedDttm = queryResponse && queryResponse.cached_dttm; - const isOverflowable = OVERFLOWABLE_VIZ_TYPES.has(slice && slice.viz_type); + const isOverflowable = OVERFLOWABLE_VIZ_TYPES.has(slice.viz_type); return (