diff --git a/superset-frontend/src/dashboard/components/Header/Header.test.tsx b/superset-frontend/src/dashboard/components/Header/Header.test.tsx index 2eb73091bcd8..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: { 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..36a3e2cb2c38 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/HeaderActionsDropdown.test.tsx @@ -38,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..1a831b482258 100644 --- a/superset-frontend/src/dashboard/components/Header/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/index.jsx @@ -54,7 +54,6 @@ import { import setPeriodicRunner, { stopPeriodicRender, } from 'src/dashboard/util/setPeriodicRunner'; -import { options as PeriodicRefreshOptions } from 'src/dashboard/components/RefreshIntervalModal'; import { FILTER_BOX_MIGRATION_STATES } from 'src/explore/constants'; import { PageHeaderWithActions } from 'src/components/PageHeaderWithActions'; import { DashboardEmbedModal } from '../DashboardEmbedControls'; @@ -289,12 +288,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 9151275e800d..aad254d9ceb4 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.test.tsx @@ -41,6 +41,7 @@ describe('RefreshIntervalModal - Enzyme', () => { refreshFrequency: 10, onChange: jest.fn(), editMode: true, + refreshIntervalOptions: [], }; it('should show warning message', () => { const props = { @@ -78,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', @@ -133,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 98b763ed859b..6299b09c539a 100644 --- a/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx +++ b/superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx @@ -26,19 +26,6 @@ import ModalTrigger, { ModalTriggerRef } from 'src/components/ModalTrigger'; import { FormLabel } from 'src/components/Form'; import { propertyComparator } from 'src/components/Select/utils'; -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 StyledModalTrigger = styled(ModalTrigger)` .ant-modal-body { overflow: visible; @@ -57,6 +44,7 @@ type RefreshIntervalModalProps = { editMode: boolean; refreshLimit?: number; refreshWarning: string | null; + refreshIntervalOptions: [number, string][]; }; type RefreshIntervalModalState = { @@ -99,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], }); } 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; @@ -120,7 +114,10 @@ class RefreshIntervalModal extends React.PureComponent< {t('Refresh frequency')}