diff --git a/superset-frontend/.eslintrc.js b/superset-frontend/.eslintrc.js index 714ce6ebd5b3..aec82af44245 100644 --- a/superset-frontend/.eslintrc.js +++ b/superset-frontend/.eslintrc.js @@ -146,6 +146,7 @@ module.exports = { 'no-unused-vars': 0, 'padded-blocks': 0, 'prefer-arrow-callback': 0, + 'prefer-object-spread': 1, 'prefer-template': 0, 'react/forbid-prop-types': 0, 'react/jsx-filename-extension': [1, { extensions: ['.jsx', '.tsx'] }], diff --git a/superset-frontend/spec/javascripts/components/AlteredSliceTag_spec.jsx b/superset-frontend/spec/javascripts/components/AlteredSliceTag_spec.jsx index 63902ab574c4..f3ea8a254a02 100644 --- a/superset-frontend/spec/javascripts/components/AlteredSliceTag_spec.jsx +++ b/superset-frontend/spec/javascripts/components/AlteredSliceTag_spec.jsx @@ -116,7 +116,7 @@ describe('AlteredSliceTag', () => { let props; beforeEach(() => { - props = Object.assign({}, defaultProps); + props = { ...defaultProps }; wrapper = shallow(); }); @@ -140,8 +140,8 @@ describe('AlteredSliceTag', () => { it('sets new diffs when receiving new props', () => { const newProps = { - currentFormData: Object.assign({}, props.currentFormData), - origFormData: Object.assign({}, props.origFormData), + currentFormData: { ...props.currentFormData }, + origFormData: { ...props.origFormData }, }; newProps.currentFormData.beta = 10; wrapper = shallow(); diff --git a/superset-frontend/spec/javascripts/components/Checkbox_spec.jsx b/superset-frontend/spec/javascripts/components/Checkbox_spec.jsx index 6a8573eca6c1..5f6fb697c9a6 100644 --- a/superset-frontend/spec/javascripts/components/Checkbox_spec.jsx +++ b/superset-frontend/spec/javascripts/components/Checkbox_spec.jsx @@ -30,7 +30,7 @@ describe('Checkbox', () => { let wrapper; const factory = o => { - const props = Object.assign({}, defaultProps, o); + const props = { ...defaultProps, ...o }; return shallow(); }; beforeEach(() => { diff --git a/superset-frontend/spec/javascripts/components/ColumnOption_spec.jsx b/superset-frontend/spec/javascripts/components/ColumnOption_spec.jsx index 26650da62cbc..cbca4f768c28 100644 --- a/superset-frontend/spec/javascripts/components/ColumnOption_spec.jsx +++ b/superset-frontend/spec/javascripts/components/ColumnOption_spec.jsx @@ -39,7 +39,7 @@ describe('ColumnOption', () => { const factory = o => ; beforeEach(() => { wrapper = shallow(factory(defaultProps)); - props = Object.assign({}, defaultProps); + props = { ...defaultProps }; }); it('is a valid element', () => { expect(React.isValidElement()).toBe(true); diff --git a/superset-frontend/spec/javascripts/components/MetricOption_spec.jsx b/superset-frontend/spec/javascripts/components/MetricOption_spec.jsx index cd9c0e8de60e..1583f7ec3db8 100644 --- a/superset-frontend/spec/javascripts/components/MetricOption_spec.jsx +++ b/superset-frontend/spec/javascripts/components/MetricOption_spec.jsx @@ -40,7 +40,7 @@ describe('MetricOption', () => { const factory = o => ; beforeEach(() => { wrapper = shallow(factory(defaultProps)); - props = Object.assign({}, defaultProps); + props = { ...defaultProps }; }); it('is a valid element', () => { expect(React.isValidElement()).toBe(true); diff --git a/superset-frontend/spec/javascripts/components/OnPasteSelect_spec.jsx b/superset-frontend/spec/javascripts/components/OnPasteSelect_spec.jsx index c5f5742799c8..5bc6cb4d5ccf 100644 --- a/superset-frontend/spec/javascripts/components/OnPasteSelect_spec.jsx +++ b/superset-frontend/spec/javascripts/components/OnPasteSelect_spec.jsx @@ -54,9 +54,9 @@ describe('OnPasteSelect', () => { let evt; let expected; beforeEach(() => { - props = Object.assign({}, defaultProps); + props = { ...defaultProps }; wrapper = shallow(); - evt = Object.assign({}, defaultEvt); + evt = { ...defaultEvt }; }); it('renders the supplied selectWrap component', () => { diff --git a/superset-frontend/spec/javascripts/components/OptionDescription_spec.jsx b/superset-frontend/spec/javascripts/components/OptionDescription_spec.jsx index 5c0cd08d87a6..d3584cd5bf2e 100644 --- a/superset-frontend/spec/javascripts/components/OptionDescription_spec.jsx +++ b/superset-frontend/spec/javascripts/components/OptionDescription_spec.jsx @@ -34,7 +34,7 @@ describe('OptionDescription', () => { let props; beforeEach(() => { - props = { option: Object.assign({}, defaultProps.option) }; + props = { option: { ...defaultProps.option } }; wrapper = shallow(); }); diff --git a/superset-frontend/spec/javascripts/components/PopoverSection_spec.jsx b/superset-frontend/spec/javascripts/components/PopoverSection_spec.jsx index 28fda4ded79f..dce656ec2821 100644 --- a/superset-frontend/spec/javascripts/components/PopoverSection_spec.jsx +++ b/superset-frontend/spec/javascripts/components/PopoverSection_spec.jsx @@ -32,7 +32,7 @@ describe('PopoverSection', () => { let wrapper; const factory = overrideProps => { - const props = Object.assign({}, defaultProps, overrideProps || {}); + const props = { ...defaultProps, ...(overrideProps || {}) }; return shallow(); }; beforeEach(() => { diff --git a/superset-frontend/spec/javascripts/components/VirtualizedRendererWrap_spec.jsx b/superset-frontend/spec/javascripts/components/VirtualizedRendererWrap_spec.jsx index fdb7c4ca9cbb..2e467aa86f5e 100644 --- a/superset-frontend/spec/javascripts/components/VirtualizedRendererWrap_spec.jsx +++ b/superset-frontend/spec/javascripts/components/VirtualizedRendererWrap_spec.jsx @@ -48,7 +48,7 @@ describe('VirtualizedRendererWrap', () => { let props; beforeEach(() => { wrapper = shallow(); - props = Object.assign({}, defaultProps); + props = { ...defaultProps }; }); it('uses the provided renderer', () => { diff --git a/superset-frontend/spec/javascripts/explore/components/TextArea_spec.jsx b/superset-frontend/spec/javascripts/explore/components/TextArea_spec.jsx index 1911c6acb282..1a18691e616a 100644 --- a/superset-frontend/spec/javascripts/explore/components/TextArea_spec.jsx +++ b/superset-frontend/spec/javascripts/explore/components/TextArea_spec.jsx @@ -48,7 +48,7 @@ describe('SelectControl', () => { }); it('renders a AceEditor when language is specified', () => { - const props = Object.assign({}, defaultProps); + const props = { ...defaultProps }; props.language = 'markdown'; wrapper = shallow(); expect(wrapper.find(FormControl)).toHaveLength(0); diff --git a/superset-frontend/spec/javascripts/profile/fixtures.jsx b/superset-frontend/spec/javascripts/profile/fixtures.jsx index 2b378c5adb72..cd434248cbb6 100644 --- a/superset-frontend/spec/javascripts/profile/fixtures.jsx +++ b/superset-frontend/spec/javascripts/profile/fixtures.jsx @@ -43,4 +43,4 @@ export const user = { database_access: ['db1', 'db2', 'db3'], }, }; -export const userNoPerms = Object.assign({}, user, { permissions: {} }); +export const userNoPerms = { ...user, permissions: {} }; diff --git a/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx b/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx index 803083ef209a..886459ad7aa3 100644 --- a/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx +++ b/superset-frontend/spec/javascripts/sqllab/ResultSet_spec.jsx @@ -38,15 +38,9 @@ describe('ResultSet', () => { query: queries[0], height: 0, }; - const stoppedQueryProps = Object.assign({}, mockedProps, { - query: stoppedQuery, - }); - const runningQueryProps = Object.assign({}, mockedProps, { - query: runningQuery, - }); - const cachedQueryProps = Object.assign({}, mockedProps, { - query: cachedQuery, - }); + const stoppedQueryProps = { ...mockedProps, query: stoppedQuery }; + const runningQueryProps = { ...mockedProps, query: runningQuery }; + const cachedQueryProps = { ...mockedProps, query: cachedQuery }; const newProps = { query: { cached: false, @@ -94,11 +88,12 @@ describe('ResultSet', () => { }); it('should render empty results', () => { const wrapper = shallow(); - const emptyResults = Object.assign({}, queries[0], { + const emptyResults = { + ...queries[0], results: { data: [], }, - }); + }; wrapper.setProps({ query: emptyResults }); expect(wrapper.find(FilterableTable)).toHaveLength(0); expect(wrapper.find(Alert)).toHaveLength(1); diff --git a/superset-frontend/spec/javascripts/sqllab/TabbedSqlEditors_spec.jsx b/superset-frontend/spec/javascripts/sqllab/TabbedSqlEditors_spec.jsx index eed1dd921c2e..cac5bdbe5bda 100644 --- a/superset-frontend/spec/javascripts/sqllab/TabbedSqlEditors_spec.jsx +++ b/superset-frontend/spec/javascripts/sqllab/TabbedSqlEditors_spec.jsx @@ -37,10 +37,7 @@ describe('TabbedSqlEditors', () => { const tabHistory = ['dfsadfs', 'newEditorId']; const tables = [ - Object.assign({}, table, { - dataPreviewQueryId: 'B1-VQU1zW', - queryEditorId: 'newEditorId', - }), + { ...table, dataPreviewQueryId: 'B1-VQU1zW', queryEditorId: 'newEditorId' }, ]; const queryEditors = [ diff --git a/superset-frontend/spec/javascripts/sqllab/fixtures.js b/superset-frontend/spec/javascripts/sqllab/fixtures.js index 7d68c32d9547..c6de52812612 100644 --- a/superset-frontend/spec/javascripts/sqllab/fixtures.js +++ b/superset-frontend/spec/javascripts/sqllab/fixtures.js @@ -19,7 +19,7 @@ import sinon from 'sinon'; import * as actions from '../../../src/SqlLab/actions/sqlLab'; -export const mockedActions = sinon.stub(Object.assign({}, actions)); +export const mockedActions = sinon.stub({ ...actions }); export const alert = { bsStyle: 'danger', msg: 'Ooops', id: 'lksvmcx32' }; export const table = { @@ -388,7 +388,7 @@ export const runningQuery = { state: 'running', startDttm: Date.now() - 500, }; -export const cachedQuery = Object.assign({}, queries[0], { cached: true }); +export const cachedQuery = { ...queries[0], cached: true }; export const initialState = { sqlLab: { diff --git a/superset-frontend/spec/javascripts/sqllab/reducers/sqlLab_spec.js b/superset-frontend/spec/javascripts/sqllab/reducers/sqlLab_spec.js index 87a0deb3213f..8a821bbcafb1 100644 --- a/superset-frontend/spec/javascripts/sqllab/reducers/sqlLab_spec.js +++ b/superset-frontend/spec/javascripts/sqllab/reducers/sqlLab_spec.js @@ -141,7 +141,7 @@ describe('sqlLabReducer', () => { let newState; let newTable; beforeEach(() => { - newTable = Object.assign({}, table); + newTable = { ...table }; const action = { type: actions.MERGE_TABLE, table: newTable, diff --git a/superset-frontend/src/SqlLab/components/QueryTable.jsx b/superset-frontend/src/SqlLab/components/QueryTable.jsx index 472a5a2a924e..111567119c72 100644 --- a/superset-frontend/src/SqlLab/components/QueryTable.jsx +++ b/superset-frontend/src/SqlLab/components/QueryTable.jsx @@ -94,7 +94,7 @@ class QueryTable extends React.PureComponent { render() { const data = this.props.queries .map(query => { - const q = Object.assign({}, query); + const q = { ...query }; if (q.endDttm) { q.duration = fDuration(q.startDttm, q.endDttm); } diff --git a/superset-frontend/src/SqlLab/reducers/sqlLab.js b/superset-frontend/src/SqlLab/reducers/sqlLab.js index d751917e9f4e..3dbd45fe079f 100644 --- a/superset-frontend/src/SqlLab/reducers/sqlLab.js +++ b/superset-frontend/src/SqlLab/reducers/sqlLab.js @@ -36,7 +36,7 @@ export default function sqlLabReducer(state = {}, action) { [actions.ADD_QUERY_EDITOR]() { const tabHistory = state.tabHistory.slice(); tabHistory.push(action.queryEditor.id); - const newState = Object.assign({}, state, { tabHistory }); + const newState = { ...state, tabHistory }; return addToArr(newState, 'queryEditors', action.queryEditor); }, [actions.QUERY_EDITOR_SAVED]() { @@ -102,19 +102,19 @@ export default function sqlLabReducer(state = {}, action) { table => table.queryEditorId !== action.queryEditor.id, ); - newState = Object.assign({}, newState, { tabHistory, tables, queries }); + newState = { ...newState, tabHistory, tables, queries }; return newState; }, [actions.REMOVE_QUERY]() { - const newQueries = Object.assign({}, state.queries); + const newQueries = { ...state.queries }; delete newQueries[action.query.id]; - return Object.assign({}, state, { queries: newQueries }); + return { ...state, queries: newQueries }; }, [actions.RESET_STATE]() { - return Object.assign({}, getInitialState()); + return { ...getInitialState() }; }, [actions.MERGE_TABLE]() { - const at = Object.assign({}, action.table); + const at = { ...action.table }; let existingTable; state.tables.forEach(xt => { if ( @@ -146,32 +146,31 @@ export default function sqlLabReducer(state = {}, action) { return alterInArr(state, 'tables', action.table, { expanded: true }); }, [actions.REMOVE_DATA_PREVIEW]() { - const queries = Object.assign({}, state.queries); + const queries = { ...state.queries }; delete queries[action.table.dataPreviewQueryId]; const newState = alterInArr(state, 'tables', action.table, { dataPreviewQueryId: null, }); - return Object.assign({}, newState, { queries }); + return { ...newState, queries }; }, [actions.CHANGE_DATA_PREVIEW_ID]() { - const queries = Object.assign({}, state.queries); + const queries = { ...state.queries }; delete queries[action.oldQueryId]; const newTables = []; state.tables.forEach(xt => { if (xt.dataPreviewQueryId === action.oldQueryId) { - newTables.push( - Object.assign({}, xt, { dataPreviewQueryId: action.newQuery.id }), - ); + newTables.push({ ...xt, dataPreviewQueryId: action.newQuery.id }); } else { newTables.push(xt); } }); - return Object.assign({}, state, { + return { + ...state, queries, tables: newTables, activeSouthPaneTab: action.newQuery.id, - }); + }; }, [actions.COLLAPSE_TABLE]() { return alterInArr(state, 'tables', action.table, { expanded: false }); @@ -180,7 +179,7 @@ export default function sqlLabReducer(state = {}, action) { return removeFromArr(state, 'tables', action.table); }, [actions.START_QUERY_VALIDATION]() { - let newState = Object.assign({}, state); + let newState = { ...state }; const sqlEditor = { id: action.query.sqlEditorId }; newState = alterInArr(newState, 'queryEditors', sqlEditor, { validationResult: { @@ -204,7 +203,7 @@ export default function sqlLabReducer(state = {}, action) { return state; } // Otherwise, persist the results on the queryEditor state - let newState = Object.assign({}, state); + let newState = { ...state }; const sqlEditor = { id: action.query.sqlEditorId }; newState = alterInArr(newState, 'queryEditors', sqlEditor, { validationResult: { @@ -228,7 +227,7 @@ export default function sqlLabReducer(state = {}, action) { return state; } // Otherwise, persist the results on the queryEditor state - let newState = Object.assign({}, state); + let newState = { ...state }; const sqlEditor = { id: action.query.sqlEditorId }; newState = alterInArr(newState, 'queryEditors', sqlEditor, { validationResult: { @@ -247,7 +246,7 @@ export default function sqlLabReducer(state = {}, action) { return newState; }, [actions.COST_ESTIMATE_STARTED]() { - let newState = Object.assign({}, state); + let newState = { ...state }; const sqlEditor = { id: action.query.sqlEditorId }; newState = alterInArr(newState, 'queryEditors', sqlEditor, { queryCostEstimate: { @@ -259,7 +258,7 @@ export default function sqlLabReducer(state = {}, action) { return newState; }, [actions.COST_ESTIMATE_RETURNED]() { - let newState = Object.assign({}, state); + let newState = { ...state }; const sqlEditor = { id: action.query.sqlEditorId }; newState = alterInArr(newState, 'queryEditors', sqlEditor, { queryCostEstimate: { @@ -271,7 +270,7 @@ export default function sqlLabReducer(state = {}, action) { return newState; }, [actions.COST_ESTIMATE_FAILED]() { - let newState = Object.assign({}, state); + let newState = { ...state }; const sqlEditor = { id: action.query.sqlEditorId }; newState = alterInArr(newState, 'queryEditors', sqlEditor, { queryCostEstimate: { @@ -283,23 +282,18 @@ export default function sqlLabReducer(state = {}, action) { return newState; }, [actions.START_QUERY]() { - let newState = Object.assign({}, state); + let newState = { ...state }; if (action.query.sqlEditorId) { const qe = getFromArr(state.queryEditors, action.query.sqlEditorId); if (qe.latestQueryId && state.queries[qe.latestQueryId]) { - const newResults = Object.assign( - {}, - state.queries[qe.latestQueryId].results, - { - data: [], - query: null, - }, - ); - const q = Object.assign({}, state.queries[qe.latestQueryId], { - results: newResults, - }); - const queries = Object.assign({}, state.queries, { [q.id]: q }); - newState = Object.assign({}, state, { queries }); + const newResults = { + ...state.queries[qe.latestQueryId].results, + data: [], + query: null, + }; + const q = { ...state.queries[qe.latestQueryId], results: newResults }; + const queries = { ...state.queries, [q.id]: q }; + newState = { ...state, queries }; } } else { newState.activeSouthPaneTab = action.query.id; @@ -317,7 +311,7 @@ export default function sqlLabReducer(state = {}, action) { }); }, [actions.CLEAR_QUERY_RESULTS]() { - const newResults = Object.assign({}, action.query.results); + const newResults = { ...action.query.results }; newResults.data = []; return alterInObject(state, 'queries', action.query, { results: newResults, @@ -365,7 +359,7 @@ export default function sqlLabReducer(state = {}, action) { ) { const tabHistory = state.tabHistory.slice(); tabHistory.push(action.queryEditor.id); - return Object.assign({}, state, { tabHistory }); + return { ...state, tabHistory }; } return state; }, @@ -378,7 +372,7 @@ export default function sqlLabReducer(state = {}, action) { return extendArr(state, 'tables', action.tables); }, [actions.SET_ACTIVE_SOUTHPANE_TAB]() { - return Object.assign({}, state, { activeSouthPaneTab: action.tabId }); + return { ...state, activeSouthPaneTab: action.tabId }; }, [actions.MIGRATE_QUERY_EDITOR]() { // remove migrated query editor from localStorage @@ -421,7 +415,7 @@ export default function sqlLabReducer(state = {}, action) { tabId => tabId !== action.oldId, ); tabHistory.push(action.newId); - return Object.assign({}, state, { tabHistory }); + return { ...state, tabHistory }; }, [actions.MIGRATE_QUERY]() { const query = { @@ -429,8 +423,8 @@ export default function sqlLabReducer(state = {}, action) { // point query to migrated query editor sqlEditorId: action.queryEditorId, }; - const queries = Object.assign({}, state.queries, { [query.id]: query }); - return Object.assign({}, state, { queries }); + const queries = { ...state.queries, [query.id]: query }; + return { ...state, queries }; }, [actions.QUERY_EDITOR_SETDB]() { return alterInArr(state, 'queryEditors', action.queryEditor, { @@ -493,10 +487,10 @@ export default function sqlLabReducer(state = {}, action) { action.databases.forEach(db => { databases[db.id] = db; }); - return Object.assign({}, state, { databases }); + return { ...state, databases }; }, [actions.REFRESH_QUERIES]() { - let newQueries = Object.assign({}, state.queries); + let newQueries = { ...state.queries }; // Fetch the updates to the queries present in the store. let change = false; let queriesLastUpdate = state.queriesLastUpdate; @@ -510,39 +504,31 @@ export default function sqlLabReducer(state = {}, action) { if (changedQuery.changedOn > queriesLastUpdate) { queriesLastUpdate = changedQuery.changedOn; } - newQueries[id] = Object.assign({}, state.queries[id], changedQuery); + newQueries[id] = { ...state.queries[id], ...changedQuery }; change = true; } } if (!change) { newQueries = state.queries; } - return Object.assign({}, state, { - queries: newQueries, - queriesLastUpdate, - }); + return { ...state, queries: newQueries, queriesLastUpdate }; }, [actions.SET_USER_OFFLINE]() { - return Object.assign({}, state, { offline: action.offline }); + return { ...state, offline: action.offline }; }, [actions.CREATE_DATASOURCE_STARTED]() { - return Object.assign({}, state, { - isDatasourceLoading: true, - errorMessage: null, - }); + return { ...state, isDatasourceLoading: true, errorMessage: null }; }, [actions.CREATE_DATASOURCE_SUCCESS]() { - return Object.assign({}, state, { + return { + ...state, isDatasourceLoading: false, errorMessage: null, datasource: action.datasource, - }); + }; }, [actions.CREATE_DATASOURCE_FAILED]() { - return Object.assign({}, state, { - isDatasourceLoading: false, - errorMessage: action.err, - }); + return { ...state, isDatasourceLoading: false, errorMessage: action.err }; }, }; if (action.type in actionHandlers) { diff --git a/superset-frontend/src/components/Button.jsx b/superset-frontend/src/components/Button.jsx index 43fe49bb85ab..80be8498c6e2 100644 --- a/superset-frontend/src/components/Button.jsx +++ b/superset-frontend/src/components/Button.jsx @@ -42,7 +42,7 @@ const defaultProps = { const BUTTON_WRAPPER_STYLE = { display: 'inline-block', cursor: 'not-allowed' }; export default function Button(props) { - const buttonProps = Object.assign({}, props); + const buttonProps = { ...props }; const tooltip = props.tooltip; const placement = props.placement; delete buttonProps.tooltip; diff --git a/superset-frontend/src/components/VictoryTheme.js b/superset-frontend/src/components/VictoryTheme.js index 54031a96e535..b673119eb6ec 100644 --- a/superset-frontend/src/components/VictoryTheme.js +++ b/superset-frontend/src/components/VictoryTheme.js @@ -65,116 +65,93 @@ const strokeLinejoin = 'round'; // Create the theme const theme = { - area: assign( - { - style: { - data: { - fill: charcoal, - }, - labels: baseLabelStyles, + area: { + style: { + data: { + fill: charcoal, }, + labels: baseLabelStyles, }, - baseProps, - ), - axis: assign( - { - style: { - axis: { - fill: 'none', - stroke: AXIS_LINE_GRAY, - strokeWidth: 1, - strokeLinecap, - strokeLinejoin, - }, - axisLabel: assign({}, baseLabelStyles, { - padding: 25, - }), - grid: { - fill: 'none', - stroke: 'transparent', - }, - ticks: { - fill: 'none', - padding: 10, - size: 1, - stroke: 'transparent', - }, - tickLabels: baseLabelStyles, + ...baseProps, + }, + axis: { + style: { + axis: { + fill: 'none', + stroke: AXIS_LINE_GRAY, + strokeWidth: 1, + strokeLinecap, + strokeLinejoin, }, - }, - baseProps, - ), - bar: assign( - { - style: { - data: { - fill: A11Y_BABU, - padding: 10, - stroke: 'transparent', - strokeWidth: 0, - width: 8, - }, - labels: baseLabelStyles, + axisLabel: { ...baseLabelStyles, padding: 25 }, + grid: { + fill: 'none', + stroke: 'transparent', + }, + ticks: { + fill: 'none', + padding: 10, + size: 1, + stroke: 'transparent', }, + tickLabels: baseLabelStyles, }, - baseProps, - ), - candlestick: assign( - { - style: { - data: { - stroke: A11Y_BABU, - strokeWidth: 1, - }, - labels: assign({}, baseLabelStyles, { - padding: 25, - textAnchor: 'end', - }), + ...baseProps, + }, + bar: { + style: { + data: { + fill: A11Y_BABU, + padding: 10, + stroke: 'transparent', + strokeWidth: 0, + width: 8, }, - candleColors: { - positive: '#ffffff', - negative: charcoal, + labels: baseLabelStyles, + }, + ...baseProps, + }, + candlestick: { + style: { + data: { + stroke: A11Y_BABU, + strokeWidth: 1, }, + labels: { ...baseLabelStyles, padding: 25, textAnchor: 'end' }, }, - baseProps, - ), + candleColors: { + positive: '#ffffff', + negative: charcoal, + }, + ...baseProps, + }, chart: baseProps, - errorbar: assign( - { - style: { - data: { - fill: 'none', - stroke: charcoal, - strokeWidth: 2, - }, - labels: assign({}, baseLabelStyles, { - textAnchor: 'start', - }), + errorbar: { + style: { + data: { + fill: 'none', + stroke: charcoal, + strokeWidth: 2, }, + labels: { ...baseLabelStyles, textAnchor: 'start' }, }, - baseProps, - ), - group: assign( - { - colorScale: colors, - }, - baseProps, - ), - line: assign( - { - style: { - data: { - fill: 'none', - stroke: A11Y_BABU, - strokeWidth: 2, - }, - labels: assign({}, baseLabelStyles, { - textAnchor: 'start', - }), + ...baseProps, + }, + group: { + colorScale: colors, + ...baseProps, + }, + line: { + style: { + data: { + fill: 'none', + stroke: A11Y_BABU, + strokeWidth: 2, }, + labels: { ...baseLabelStyles, textAnchor: 'start' }, }, - baseProps, - ), + ...baseProps, + }, pie: { style: { data: { @@ -182,37 +159,28 @@ const theme = { stroke: 'none', strokeWidth: 1, }, - labels: assign({}, baseLabelStyles, { - padding: 200, - textAnchor: 'middle', - }), + labels: { ...baseLabelStyles, padding: 200, textAnchor: 'middle' }, }, colorScale: colors, width: 400, height: 400, padding: 50, }, - scatter: assign( - { - style: { - data: { - fill: charcoal, - stroke: 'transparent', - strokeWidth: 0, - }, - labels: assign({}, baseLabelStyles, { - textAnchor: 'middle', - }), + scatter: { + style: { + data: { + fill: charcoal, + stroke: 'transparent', + strokeWidth: 0, }, + labels: { ...baseLabelStyles, textAnchor: 'middle' }, }, - baseProps, - ), - stack: assign( - { - colorScale: colors, - }, - baseProps, - ), + ...baseProps, + }, + stack: { + colorScale: colors, + ...baseProps, + }, }; export default theme; diff --git a/superset-frontend/src/explore/components/ControlPanelsContainer.jsx b/superset-frontend/src/explore/components/ControlPanelsContainer.jsx index 2e0affdc3a16..ccfbaacbda6a 100644 --- a/superset-frontend/src/explore/components/ControlPanelsContainer.jsx +++ b/superset-frontend/src/explore/components/ControlPanelsContainer.jsx @@ -75,11 +75,10 @@ class ControlPanelsContainer extends React.Component { } // Applying mapStateToProps if needed if (mapF) { - return Object.assign( - {}, - control, - mapF(this.props.exploreState, control, this.props.actions), - ); + return { + ...control, + ...mapF(this.props.exploreState, control, this.props.actions), + }; } return control; } diff --git a/superset-frontend/src/explore/components/ExploreViewContainer.jsx b/superset-frontend/src/explore/components/ExploreViewContainer.jsx index 4cde0286e00e..88c121c9503c 100644 --- a/superset-frontend/src/explore/components/ExploreViewContainer.jsx +++ b/superset-frontend/src/explore/components/ExploreViewContainer.jsx @@ -418,13 +418,12 @@ function mapStateToProps(state) { } function mapDispatchToProps(dispatch) { - const actions = Object.assign( - {}, - exploreActions, - saveModalActions, - chartActions, - logActions, - ); + const actions = { + ...exploreActions, + ...saveModalActions, + ...chartActions, + ...logActions, + }; return { actions: bindActionCreators(actions, dispatch), }; diff --git a/superset-frontend/src/explore/components/controls/ColorPickerControl.jsx b/superset-frontend/src/explore/components/controls/ColorPickerControl.jsx index 58a1b1cf6843..9356a06b6b18 100644 --- a/superset-frontend/src/explore/components/controls/ColorPickerControl.jsx +++ b/superset-frontend/src/explore/components/controls/ColorPickerControl.jsx @@ -88,9 +88,10 @@ export default class ColorPickerControl extends React.Component { } render() { const c = this.props.value || { r: 0, g: 0, b: 0, a: 0 }; - const colStyle = Object.assign({}, styles.color, { + const colStyle = { + ...styles.color, background: `rgba(${c.r}, ${c.g}, ${c.b}, ${c.a})`, - }); + }; return (
diff --git a/superset-frontend/src/explore/controls.jsx b/superset-frontend/src/explore/controls.jsx index b61626453f9c..c4e8ea571051 100644 --- a/superset-frontend/src/explore/controls.jsx +++ b/superset-frontend/src/explore/controls.jsx @@ -513,10 +513,11 @@ export const controls = { default: null, }, - columns: Object.assign({}, groupByControl, { + columns: { + ...groupByControl, label: t('Columns'), description: t('One or many controls to pivot as columns'), - }), + }, all_columns: { type: 'SelectControl', diff --git a/superset-frontend/src/explore/reducers/exploreReducer.js b/superset-frontend/src/explore/reducers/exploreReducer.js index 9d68510cdebf..df9b63d57ed4 100644 --- a/superset-frontend/src/explore/reducers/exploreReducer.js +++ b/superset-frontend/src/explore/reducers/exploreReducer.js @@ -131,9 +131,7 @@ export default function exploreReducer(state = {}, action) { }; }, [actions.UPDATE_CHART_TITLE]() { - const updatedSlice = Object.assign({}, state.slice, { - slice_name: action.slice_name, - }); + const updatedSlice = { ...state.slice, slice_name: action.slice_name }; return { ...state, slice: updatedSlice, diff --git a/superset-frontend/src/explore/reducers/saveModalReducer.js b/superset-frontend/src/explore/reducers/saveModalReducer.js index a73633fe26be..eee419799118 100644 --- a/superset-frontend/src/explore/reducers/saveModalReducer.js +++ b/superset-frontend/src/explore/reducers/saveModalReducer.js @@ -22,23 +22,22 @@ import * as actions from '../actions/saveModalActions'; export default function saveModalReducer(state = {}, action) { const actionHandlers = { [actions.FETCH_DASHBOARDS_SUCCEEDED]() { - return Object.assign({}, state, { dashboards: action.choices }); + return { ...state, dashboards: action.choices }; }, [actions.FETCH_DASHBOARDS_FAILED]() { - return Object.assign({}, state, { + return { + ...state, saveModalAlert: `fetching dashboards failed for ${action.userId}`, - }); + }; }, [actions.SAVE_SLICE_FAILED]() { - return Object.assign({}, state, { - saveModalAlert: 'Failed to save slice', - }); + return { ...state, saveModalAlert: 'Failed to save slice' }; }, [actions.SAVE_SLICE_SUCCESS](data) { - return Object.assign({}, state, { data }); + return { ...state, data }; }, [actions.REMOVE_SAVE_MODAL_ALERT]() { - return Object.assign({}, state, { saveModalAlert: null }); + return { ...state, saveModalAlert: null }; }, }; diff --git a/superset-frontend/src/explore/store.js b/superset-frontend/src/explore/store.js index 793a31bc80ea..92cd4f7bacb1 100644 --- a/superset-frontend/src/explore/store.js +++ b/superset-frontend/src/explore/store.js @@ -41,7 +41,7 @@ export function getControlsState(state, inputFormData) { * */ // Getting a list of active control names for the current viz - const formData = Object.assign({}, inputFormData); + const formData = { ...inputFormData }; const vizType = formData.viz_type || 'table'; handleDeprecatedControls(formData); @@ -80,7 +80,7 @@ export function applyDefaultFormData(inputFormData) { return formData; } -const defaultControls = Object.assign({}, controls); +const defaultControls = { ...controls }; Object.keys(controls).forEach(f => { defaultControls[f].value = controls[f].default; }); diff --git a/superset-frontend/src/reduxUtils.js b/superset-frontend/src/reduxUtils.js index 7190372f3404..8538f25cec74 100644 --- a/superset-frontend/src/reduxUtils.js +++ b/superset-frontend/src/reduxUtils.js @@ -22,20 +22,20 @@ import persistState from 'redux-localstorage'; import { isEqual } from 'lodash'; export function addToObject(state, arrKey, obj) { - const newObject = Object.assign({}, state[arrKey]); - const copiedObject = Object.assign({}, obj); + const newObject = { ...state[arrKey] }; + const copiedObject = { ...obj }; if (!copiedObject.id) { copiedObject.id = shortid.generate(); } newObject[copiedObject.id] = copiedObject; - return Object.assign({}, state, { [arrKey]: newObject }); + return { ...state, [arrKey]: newObject }; } export function alterInObject(state, arrKey, obj, alterations) { - const newObject = Object.assign({}, state[arrKey]); - newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations); - return Object.assign({}, state, { [arrKey]: newObject }); + const newObject = { ...state[arrKey] }; + newObject[obj.id] = { ...newObject[obj.id], ...alterations }; + return { ...state, [arrKey]: newObject }; } export function alterInArr(state, arrKey, obj, alterations, idKey = 'id') { @@ -44,12 +44,12 @@ export function alterInArr(state, arrKey, obj, alterations, idKey = 'id') { const newArr = []; state[arrKey].forEach(arrItem => { if (obj[idKey] === arrItem[idKey]) { - newArr.push(Object.assign({}, arrItem, alterations)); + newArr.push({ ...arrItem, ...alterations }); } else { newArr.push(arrItem); } }); - return Object.assign({}, state, { [arrKey]: newArr }); + return { ...state, [arrKey]: newArr }; } export function removeFromArr(state, arrKey, obj, idKey = 'id') { @@ -59,7 +59,7 @@ export function removeFromArr(state, arrKey, obj, idKey = 'id') { newArr.push(arrItem); } }); - return Object.assign({}, state, { [arrKey]: newArr }); + return { ...state, [arrKey]: newArr }; } export function getFromArr(arr, id) { @@ -73,7 +73,7 @@ export function getFromArr(arr, id) { } export function addToArr(state, arrKey, obj, prepend = false) { - const newObj = Object.assign({}, obj); + const newObj = { ...obj }; if (!newObj.id) { newObj.id = shortid.generate(); } @@ -83,7 +83,7 @@ export function addToArr(state, arrKey, obj, prepend = false) { } else { newState[arrKey] = [...state[arrKey], newObj]; } - return Object.assign({}, state, newState); + return { ...state, ...newState }; } export function extendArr(state, arrKey, obj, prepend = false) { @@ -100,7 +100,7 @@ export function extendArr(state, arrKey, obj, prepend = false) { } else { newState[arrKey] = [...state[arrKey], ...newObj]; } - return Object.assign({}, state, newState); + return { ...state, ...newState }; } export function initEnhancer(persist = true, persistConfig = {}) { diff --git a/superset-frontend/src/utils/reducerUtils.js b/superset-frontend/src/utils/reducerUtils.js index 1059fe958d9b..7e550a5853cb 100644 --- a/superset-frontend/src/utils/reducerUtils.js +++ b/superset-frontend/src/utils/reducerUtils.js @@ -19,20 +19,20 @@ import shortid from 'shortid'; export function addToObject(state, arrKey, obj) { - const newObject = Object.assign({}, state[arrKey]); - const copiedObject = Object.assign({}, obj); + const newObject = { ...state[arrKey] }; + const copiedObject = { ...obj }; if (!copiedObject.id) { copiedObject.id = shortid.generate(); } newObject[copiedObject.id] = copiedObject; - return Object.assign({}, state, { [arrKey]: newObject }); + return { ...state, [arrKey]: newObject }; } export function alterInObject(state, arrKey, obj, alterations) { - const newObject = Object.assign({}, state[arrKey]); - newObject[obj.id] = Object.assign({}, newObject[obj.id], alterations); - return Object.assign({}, state, { [arrKey]: newObject }); + const newObject = { ...state[arrKey] }; + newObject[obj.id] = { ...newObject[obj.id], ...alterations }; + return { ...state, [arrKey]: newObject }; } export function alterInArr(state, arrKey, obj, alterations) { @@ -42,12 +42,12 @@ export function alterInArr(state, arrKey, obj, alterations) { const newArr = []; state[arrKey].forEach(arrItem => { if (obj[idKey] === arrItem[idKey]) { - newArr.push(Object.assign({}, arrItem, alterations)); + newArr.push({ ...arrItem, ...alterations }); } else { newArr.push(arrItem); } }); - return Object.assign({}, state, { [arrKey]: newArr }); + return { ...state, [arrKey]: newArr }; } export function removeFromArr(state, arrKey, obj, idKey = 'id') { @@ -57,15 +57,15 @@ export function removeFromArr(state, arrKey, obj, idKey = 'id') { newArr.push(arrItem); } }); - return Object.assign({}, state, { [arrKey]: newArr }); + return { ...state, [arrKey]: newArr }; } export function addToArr(state, arrKey, obj) { - const newObj = Object.assign({}, obj); + const newObj = { ...obj }; if (!newObj.id) { newObj.id = shortid.generate(); } const newState = {}; newState[arrKey] = [...state[arrKey], newObj]; - return Object.assign({}, state, newState); + return { ...state, ...newState }; } diff --git a/superset-frontend/src/visualizations/FilterBox/FilterBox.jsx b/superset-frontend/src/visualizations/FilterBox/FilterBox.jsx index 036465c66e25..61974eaf698b 100644 --- a/superset-frontend/src/visualizations/FilterBox/FilterBox.jsx +++ b/superset-frontend/src/visualizations/FilterBox/FilterBox.jsx @@ -120,14 +120,15 @@ class FilterBox extends React.Component { getControlData(controlName) { const { selectedValues } = this.state; - const control = Object.assign({}, controls[controlName], { + const control = { + ...controls[controlName], name: controlName, key: `control-${controlName}`, value: selectedValues[TIME_FILTER_MAP[controlName]], actions: { setControlValue: this.changeFilter }, - }); + }; const mapFunc = control.mapStateToProps; - return mapFunc ? Object.assign({}, control, mapFunc(this.props)) : control; + return mapFunc ? { ...control, ...mapFunc(this.props) } : control; } clickApply() {