From 4237c92cd560dd695f192ff6f713984ae9d99c6e Mon Sep 17 00:00:00 2001 From: Rui Zhao Date: Tue, 18 Oct 2022 17:01:59 -0700 Subject: [PATCH 1/9] Move dashboard auto refresh intervals options to config --- superset-frontend/src/configs.ts | 32 +++++++++++++++++++ .../components/RefreshIntervalModal.test.tsx | 18 +++++++++++ .../components/RefreshIntervalModal.tsx | 20 +++++------- superset/config.py | 13 ++++++++ superset/views/base.py | 1 + 5 files changed, 72 insertions(+), 12 deletions(-) create mode 100644 superset-frontend/src/configs.ts diff --git a/superset-frontend/src/configs.ts b/superset-frontend/src/configs.ts new file mode 100644 index 000000000000..1ee233a33352 --- /dev/null +++ b/superset-frontend/src/configs.ts @@ -0,0 +1,32 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +export function configs() { + // read superset config using multiple sources + // currently it only reads from bootstrap data + return configsFromBootstrapData(); +} + +function configsFromBootstrapData() { + // read config from bootstrap data + const container = document.getElementById('app'); + const bootstrapJson = container?.getAttribute('data-bootstrap') ?? '{}'; + const bootstrap = JSON.parse(bootstrapJson); + return bootstrap?.common?.conf; +} diff --git a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx index 9151275e800d..8c25f605c911 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx @@ -28,6 +28,24 @@ import HeaderActionsDropdown from 'src/dashboard/components/Header/HeaderActions import Alert from 'src/components/Alert'; import { supersetTheme, ThemeProvider } from '@superset-ui/core'; +jest.mock('src/configs', () => ({ + ...jest.requireActual('src/configs'), + configs: jest.fn(() => ({ + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + })), +})); + describe('RefreshIntervalModal - Enzyme', () => { const getMountWrapper = (props: any) => mount(, { diff --git a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx index 98b763ed859b..e5ae1005b899 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx @@ -25,19 +25,15 @@ import Button from 'src/components/Button'; import ModalTrigger, { ModalTriggerRef } from 'src/components/ModalTrigger'; import { FormLabel } from 'src/components/Form'; import { propertyComparator } from 'src/components/Select/utils'; +import { configs } from 'src/configs'; -export const options = [ - [0, t("Don't refresh")], - [10, t('10 seconds')], - [30, t('30 seconds')], - [60, t('1 minute')], - [300, t('5 minutes')], - [1800, t('30 minutes')], - [3600, t('1 hour')], - [21600, t('6 hours')], - [43200, t('12 hours')], - [86400, t('24 hours')], -].map(o => ({ value: o[0] as number, label: o[1] })); +const configValues = configs(); +export const options = configValues.DASHBOARD_AUTO_REFRESH_INTERVALS.map( + (o: any[]) => ({ + value: o[0] as number, + label: o[1], + }), +); const StyledModalTrigger = styled(ModalTrigger)` .ant-modal-body { diff --git a/superset/config.py b/superset/config.py index 64dc3baa125b..cb63b519bac9 100644 --- a/superset/config.py +++ b/superset/config.py @@ -761,6 +761,19 @@ def _try_json_readsha(filepath: str, length: int) -> Optional[str]: # Force refresh while auto-refresh in dashboard DASHBOARD_AUTO_REFRESH_MODE: Literal["fetch", "force"] = "force" +# Dashboard auto refresh intervals +DASHBOARD_AUTO_REFRESH_INTERVALS = [ + [0, "Don't refresh"], + [10, "10 seconds"], + [30, "30 seconds"], + [60, "1 minute"], + [300, "5 minutes"], + [1800, "30 minutes"], + [3600, "1 hour"], + [21600, "6 hours"], + [43200, "12 hours"], + [86400, "24 hours"], +] # Default celery config is to use SQLA as a broker, in a production setting # you'll want to use a proper broker as specified here: diff --git a/superset/views/base.py b/superset/views/base.py index cf7868eaf1c0..602e5fc31a75 100644 --- a/superset/views/base.py +++ b/superset/views/base.py @@ -103,6 +103,7 @@ "SQLALCHEMY_DISPLAY_TEXT", "GLOBAL_ASYNC_QUERIES_WEBSOCKET_URL", "DASHBOARD_AUTO_REFRESH_MODE", + "DASHBOARD_AUTO_REFRESH_INTERVALS", "DASHBOARD_VIRTUALIZATION", "SCHEDULED_QUERIES", "EXCEL_EXTENSIONS", From b1e1a1863b5b9999a3af9f72bc591a7416d38d01 Mon Sep 17 00:00:00 2001 From: Rui Zhao Date: Mon, 24 Oct 2022 16:43:55 -0700 Subject: [PATCH 2/9] Fix unit test depending on RefreshIntervalModal --- .../dashboard/components/Dashboard.test.jsx | 18 ++++++++++++++++++ .../DashboardBuilder/DashboardBuilder.test.tsx | 17 +++++++++++++++++ .../components/Header/Header.test.tsx | 18 ++++++++++++++++++ .../HeaderActionsDropdown.test.tsx | 18 ++++++++++++++++++ .../CRUD/dashboard/DashboardList.test.jsx | 18 ++++++++++++++++++ 5 files changed, 89 insertions(+) diff --git a/superset-frontend/src/dashboard/components/Dashboard.test.jsx b/superset-frontend/src/dashboard/components/Dashboard.test.jsx index 56a696f91314..467939b6711e 100644 --- a/superset-frontend/src/dashboard/components/Dashboard.test.jsx +++ b/superset-frontend/src/dashboard/components/Dashboard.test.jsx @@ -40,6 +40,24 @@ import dashboardState from 'spec/fixtures/mockDashboardState'; import { sliceEntitiesForChart as sliceEntities } from 'spec/fixtures/mockSliceEntities'; import { getAllActiveFilters } from 'src/dashboard/util/activeAllDashboardFilters'; +jest.mock('src/configs', () => ({ + ...jest.requireActual('src/configs'), + configs: jest.fn(() => ({ + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + })), +})); + describe('Dashboard', () => { const props = { actions: { diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 65969e2ca6d7..528b2171c50b 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -85,6 +85,23 @@ jest.mock('src/dashboard/components/nativeFilters/FilterBar', () => () => ( jest.mock('src/dashboard/containers/DashboardGrid', () => () => (
)); +jest.mock('src/configs', () => ({ + ...jest.requireActual('src/configs'), + configs: jest.fn(() => ({ + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + })), +})); describe('DashboardBuilder', () => { let favStarStub: jest.Mock; diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 2eb73091bcd8..4f717214257a 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -113,6 +113,24 @@ const redoProps = { fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {}); +jest.mock('src/configs', () => ({ + ...jest.requireActual('src/configs'), + configs: jest.fn(() => ({ + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + })), +})); + function setup(props: HeaderProps, initialState = {}) { return render(
diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx index eb3c6aeb4e97..26095c106280 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -26,6 +26,24 @@ import { HeaderDropdownProps } from 'src/dashboard/components/Header/types'; import injectCustomCss from 'src/dashboard/util/injectCustomCss'; import HeaderActionsDropdown from '.'; +jest.mock('src/configs', () => ({ + ...jest.requireActual('src/configs'), + configs: jest.fn(() => ({ + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + })), +})); + const createProps = () => ({ addSuccessToast: jest.fn(), addDangerToast: jest.fn(), diff --git a/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx b/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx index e42ba92ff292..0a3a3f29cab5 100644 --- a/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx +++ b/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx @@ -97,6 +97,24 @@ fetchMock.get(dashboardEndpoint, { global.URL.createObjectURL = jest.fn(); fetchMock.get('/thumbnail', { body: new Blob(), sendAsJson: false }); +jest.mock('src/configs', () => ({ + ...jest.requireActual('src/configs'), + configs: jest.fn(() => ({ + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + })), +})); + describe('DashboardList', () => { const isFeatureEnabledMock = jest .spyOn(featureFlags, 'isFeatureEnabled') From 976e34431d6c056b3ca88e619e3be34b4726b6fb Mon Sep 17 00:00:00 2001 From: Rui Zhao Date: Mon, 24 Oct 2022 16:57:17 -0700 Subject: [PATCH 3/9] Simplify mocks in non-RefreshIntervalModal tests --- .../src/dashboard/components/Dashboard.test.jsx | 8 -------- .../components/DashboardBuilder/DashboardBuilder.test.tsx | 8 -------- .../src/dashboard/components/Header/Header.test.tsx | 8 -------- .../HeaderActionsDropdown/HeaderActionsDropdown.test.tsx | 8 -------- .../src/views/CRUD/dashboard/DashboardList.test.jsx | 8 -------- 5 files changed, 40 deletions(-) diff --git a/superset-frontend/src/dashboard/components/Dashboard.test.jsx b/superset-frontend/src/dashboard/components/Dashboard.test.jsx index 467939b6711e..84ff84d45ca7 100644 --- a/superset-frontend/src/dashboard/components/Dashboard.test.jsx +++ b/superset-frontend/src/dashboard/components/Dashboard.test.jsx @@ -46,14 +46,6 @@ jest.mock('src/configs', () => ({ DASHBOARD_AUTO_REFRESH_INTERVALS: [ [0, "Don't refresh"], [10, '10 seconds'], - [30, '30 seconds'], - [60, '1 minute'], - [300, '5 minutes'], - [1800, '30 minutes'], - [3600, '1 hour'], - [21600, '6 hours'], - [43200, '12 hours'], - [86400, '24 hours'], ], })), })); diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 528b2171c50b..0e04725119a2 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -91,14 +91,6 @@ jest.mock('src/configs', () => ({ DASHBOARD_AUTO_REFRESH_INTERVALS: [ [0, "Don't refresh"], [10, '10 seconds'], - [30, '30 seconds'], - [60, '1 minute'], - [300, '5 minutes'], - [1800, '30 minutes'], - [3600, '1 hour'], - [21600, '6 hours'], - [43200, '12 hours'], - [86400, '24 hours'], ], })), })); diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 4f717214257a..0048deec02a1 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -119,14 +119,6 @@ jest.mock('src/configs', () => ({ DASHBOARD_AUTO_REFRESH_INTERVALS: [ [0, "Don't refresh"], [10, '10 seconds'], - [30, '30 seconds'], - [60, '1 minute'], - [300, '5 minutes'], - [1800, '30 minutes'], - [3600, '1 hour'], - [21600, '6 hours'], - [43200, '12 hours'], - [86400, '24 hours'], ], })), })); diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx index 26095c106280..7b020b6c4bbe 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -32,14 +32,6 @@ jest.mock('src/configs', () => ({ DASHBOARD_AUTO_REFRESH_INTERVALS: [ [0, "Don't refresh"], [10, '10 seconds'], - [30, '30 seconds'], - [60, '1 minute'], - [300, '5 minutes'], - [1800, '30 minutes'], - [3600, '1 hour'], - [21600, '6 hours'], - [43200, '12 hours'], - [86400, '24 hours'], ], })), })); diff --git a/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx b/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx index 0a3a3f29cab5..fd775efbc474 100644 --- a/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx +++ b/superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx @@ -103,14 +103,6 @@ jest.mock('src/configs', () => ({ DASHBOARD_AUTO_REFRESH_INTERVALS: [ [0, "Don't refresh"], [10, '10 seconds'], - [30, '30 seconds'], - [60, '1 minute'], - [300, '5 minutes'], - [1800, '30 minutes'], - [3600, '1 hour'], - [21600, '6 hours'], - [43200, '12 hours'], - [86400, '24 hours'], ], })), })); From 20e3cd1f012c7615c220c6548eab4f4ce9ddf3cd Mon Sep 17 00:00:00 2001 From: Rui Zhao Date: Tue, 25 Oct 2022 15:54:38 -0700 Subject: [PATCH 4/9] Switch to read config from redux --- superset-frontend/src/configs.ts | 32 ----------------- .../dashboard/components/Dashboard.test.jsx | 10 ------ .../DashboardBuilder.test.tsx | 9 ----- .../components/Header/Header.test.tsx | 17 ++++----- .../HeaderActionsDropdown.test.tsx | 17 ++++----- .../Header/HeaderActionsDropdown/index.jsx | 4 +++ .../src/dashboard/components/Header/index.jsx | 11 ++++-- .../components/RefreshIntervalModal.test.tsx | 35 +++++++++---------- .../components/RefreshIntervalModal.tsx | 25 ++++++------- .../CRUD/dashboard/DashboardList.test.jsx | 10 ------ 10 files changed, 53 insertions(+), 117 deletions(-) delete mode 100644 superset-frontend/src/configs.ts diff --git a/superset-frontend/src/configs.ts b/superset-frontend/src/configs.ts deleted file mode 100644 index 1ee233a33352..000000000000 --- a/superset-frontend/src/configs.ts +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -export function configs() { - // read superset config using multiple sources - // currently it only reads from bootstrap data - return configsFromBootstrapData(); -} - -function configsFromBootstrapData() { - // read config from bootstrap data - const container = document.getElementById('app'); - const bootstrapJson = container?.getAttribute('data-bootstrap') ?? '{}'; - const bootstrap = JSON.parse(bootstrapJson); - return bootstrap?.common?.conf; -} diff --git a/superset-frontend/src/dashboard/components/Dashboard.test.jsx b/superset-frontend/src/dashboard/components/Dashboard.test.jsx index 84ff84d45ca7..56a696f91314 100644 --- a/superset-frontend/src/dashboard/components/Dashboard.test.jsx +++ b/superset-frontend/src/dashboard/components/Dashboard.test.jsx @@ -40,16 +40,6 @@ import dashboardState from 'spec/fixtures/mockDashboardState'; import { sliceEntitiesForChart as sliceEntities } from 'spec/fixtures/mockSliceEntities'; import { getAllActiveFilters } from 'src/dashboard/util/activeAllDashboardFilters'; -jest.mock('src/configs', () => ({ - ...jest.requireActual('src/configs'), - configs: jest.fn(() => ({ - DASHBOARD_AUTO_REFRESH_INTERVALS: [ - [0, "Don't refresh"], - [10, '10 seconds'], - ], - })), -})); - describe('Dashboard', () => { const props = { actions: { diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index 0e04725119a2..65969e2ca6d7 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -85,15 +85,6 @@ jest.mock('src/dashboard/components/nativeFilters/FilterBar', () => () => ( jest.mock('src/dashboard/containers/DashboardGrid', () => () => (
)); -jest.mock('src/configs', () => ({ - ...jest.requireActual('src/configs'), - configs: jest.fn(() => ({ - DASHBOARD_AUTO_REFRESH_INTERVALS: [ - [0, "Don't refresh"], - [10, '10 seconds'], - ], - })), -})); describe('DashboardBuilder', () => { let favStarStub: jest.Mock; diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 0048deec02a1..4f8bf64f68cd 100644 --- a/superset-frontend/src/dashboard/components/Header/Header.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/Header.test.tsx @@ -37,7 +37,12 @@ const createProps = () => ({ userId: '1', metadata: {}, common: { - conf: {}, + conf: { + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + ], + }, }, }, user: { @@ -113,16 +118,6 @@ const redoProps = { fetchMock.get('glob:*/csstemplateasyncmodelview/api/read', {}); -jest.mock('src/configs', () => ({ - ...jest.requireActual('src/configs'), - configs: jest.fn(() => ({ - DASHBOARD_AUTO_REFRESH_INTERVALS: [ - [0, "Don't refresh"], - [10, '10 seconds'], - ], - })), -})); - function setup(props: HeaderProps, initialState = {}) { return render(
diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx index 7b020b6c4bbe..36a3e2cb2c38 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -26,16 +26,6 @@ import { HeaderDropdownProps } from 'src/dashboard/components/Header/types'; import injectCustomCss from 'src/dashboard/util/injectCustomCss'; import HeaderActionsDropdown from '.'; -jest.mock('src/configs', () => ({ - ...jest.requireActual('src/configs'), - configs: jest.fn(() => ({ - DASHBOARD_AUTO_REFRESH_INTERVALS: [ - [0, "Don't refresh"], - [10, '10 seconds'], - ], - })), -})); - const createProps = () => ({ addSuccessToast: jest.fn(), addDangerToast: jest.fn(), @@ -48,7 +38,12 @@ const createProps = () => ({ userId: '1', metadata: {}, common: { - conf: {}, + conf: { + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + ], + }, }, }, dashboardTitle: 'Title', diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx index 3d25b049fba5..eb20c5701951 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx @@ -239,6 +239,9 @@ class HeaderActionsDropdown extends React.PureComponent { hash: window.location.hash, }); + const refreshIntervalOptions = + dashboardInfo.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS; + return ( {!editMode && ( @@ -386,6 +389,7 @@ class HeaderActionsDropdown extends React.PureComponent { refreshWarning={refreshWarning} onChange={this.changeRefreshInterval} editMode={editMode} + refreshIntervalOptions={refreshIntervalOptions} triggerNode={{t('Set auto-refresh interval')}} /> diff --git a/superset-frontend/src/dashboard/components/Header/index.jsx b/superset-frontend/src/dashboard/components/Header/index.jsx index 178f6da6eeb4..a94473ea82fe 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -289,12 +289,17 @@ class Header extends React.PureComponent { startPeriodicRender(interval) { let intervalMessage; + if (interval) { - const predefinedValue = PeriodicRefreshOptions.find( - option => option.value === interval / 1000, + const { dashboardInfo } = this.props; + const periodicRefreshOptions = + dashboardInfo.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS; + const predefinedValue = periodicRefreshOptions.find( + option => Number(option[0]) === interval / 1000, ); + if (predefinedValue) { - intervalMessage = predefinedValue.label; + intervalMessage = t(predefinedValue[1]); } else { intervalMessage = moment.duration(interval, 'millisecond').humanize(); } diff --git a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx index 8c25f605c911..aad254d9ceb4 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx @@ -28,24 +28,6 @@ import HeaderActionsDropdown from 'src/dashboard/components/Header/HeaderActions import Alert from 'src/components/Alert'; import { supersetTheme, ThemeProvider } from '@superset-ui/core'; -jest.mock('src/configs', () => ({ - ...jest.requireActual('src/configs'), - configs: jest.fn(() => ({ - DASHBOARD_AUTO_REFRESH_INTERVALS: [ - [0, "Don't refresh"], - [10, '10 seconds'], - [30, '30 seconds'], - [60, '1 minute'], - [300, '5 minutes'], - [1800, '30 minutes'], - [3600, '1 hour'], - [21600, '6 hours'], - [43200, '12 hours'], - [86400, '24 hours'], - ], - })), -})); - describe('RefreshIntervalModal - Enzyme', () => { const getMountWrapper = (props: any) => mount(, { @@ -59,6 +41,7 @@ describe('RefreshIntervalModal - Enzyme', () => { refreshFrequency: 10, onChange: jest.fn(), editMode: true, + refreshIntervalOptions: [], }; it('should show warning message', () => { const props = { @@ -96,7 +79,20 @@ const createProps = () => ({ userId: '1', metadata: {}, common: { - conf: {}, + conf: { + DASHBOARD_AUTO_REFRESH_INTERVALS: [ + [0, "Don't refresh"], + [10, '10 seconds'], + [30, '30 seconds'], + [60, '1 minute'], + [300, '5 minutes'], + [1800, '30 minutes'], + [3600, '1 hour'], + [21600, '6 hours'], + [43200, '12 hours'], + [86400, '24 hours'], + ], + }, }, }, dashboardTitle: 'Title', @@ -151,6 +147,7 @@ const defaultRefreshIntervalModalProps = { onChange: jest.fn(), editMode: true, addSuccessToast: jest.fn(), + refreshIntervalOptions: [], }; describe('RefreshIntervalModal - RTL', () => { diff --git a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx index e5ae1005b899..988abe45ce24 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx @@ -25,15 +25,6 @@ import Button from 'src/components/Button'; import ModalTrigger, { ModalTriggerRef } from 'src/components/ModalTrigger'; import { FormLabel } from 'src/components/Form'; import { propertyComparator } from 'src/components/Select/utils'; -import { configs } from 'src/configs'; - -const configValues = configs(); -export const options = configValues.DASHBOARD_AUTO_REFRESH_INTERVALS.map( - (o: any[]) => ({ - value: o[0] as number, - label: o[1], - }), -); const StyledModalTrigger = styled(ModalTrigger)` .ant-modal-body { @@ -53,6 +44,7 @@ type RefreshIntervalModalProps = { editMode: boolean; refreshLimit?: number; refreshWarning: string | null; + refreshIntervalOptions: any; }; type RefreshIntervalModalState = { @@ -95,13 +87,19 @@ class RefreshIntervalModal extends React.PureComponent< } handleFrequencyChange(value: number) { + const { refreshIntervalOptions } = this.props; this.setState({ - refreshFrequency: value || options[0].value, + refreshFrequency: value || (refreshIntervalOptions[0][0] as number), }); } render() { - const { refreshLimit = 0, refreshWarning, editMode } = this.props; + const { + refreshLimit = 0, + refreshWarning, + editMode, + refreshIntervalOptions, + } = this.props; const { refreshFrequency = 0 } = this.state; const showRefreshWarning = !!refreshFrequency && !!refreshWarning && refreshFrequency < refreshLimit; @@ -116,7 +114,10 @@ class RefreshIntervalModal extends React.PureComponent< {t('Refresh frequency')} ({ - value: o[0] as number, - label: t(o[1]), + options={refreshIntervalOptions.map(option => ({ + value: option[0], + label: t(option[1]), }))} value={refreshFrequency} onChange={this.handleFrequencyChange} From 5eda9c5652fe058ec5fcd24fcf0a8f62affc2845 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Wed, 26 Oct 2022 14:34:02 -0300 Subject: [PATCH 9/9] Update superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx --- .../src/dashboard/components/RefreshIntervalModal.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx index d36ea8fb3597..6299b09c539a 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx @@ -44,7 +44,7 @@ type RefreshIntervalModalProps = { editMode: boolean; refreshLimit?: number; refreshWarning: string | null; - refreshIntervalOptions: [[number, string]]; + refreshIntervalOptions: [number, string][]; }; type RefreshIntervalModalState = {