Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard): Move dashboard auto refresh intervals options to config #21924

Merged
merged 9 commits into from
Oct 27, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ const createProps = () => ({
userId: '1',
metadata: {},
common: {
conf: {},
conf: {
DASHBOARD_AUTO_REFRESH_INTERVALS: [
[0, "Don't refresh"],
[10, '10 seconds'],
],
},
},
},
user: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ class HeaderActionsDropdown extends React.PureComponent {
hash: window.location.hash,
});

const refreshIntervalOptions =
dashboardInfo.common?.conf?.DASHBOARD_AUTO_REFRESH_INTERVALS;

return (
<Menu selectable={false} data-test="header-actions-menu" {...rest}>
{!editMode && (
Expand Down Expand Up @@ -386,6 +389,7 @@ class HeaderActionsDropdown extends React.PureComponent {
refreshWarning={refreshWarning}
onChange={this.changeRefreshInterval}
editMode={editMode}
refreshIntervalOptions={refreshIntervalOptions}
triggerNode={<span>{t('Set auto-refresh interval')}</span>}
/>
</Menu.Item>
Expand Down
12 changes: 8 additions & 4 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('RefreshIntervalModal - Enzyme', () => {
refreshFrequency: 10,
onChange: jest.fn(),
editMode: true,
refreshIntervalOptions: [],
};
it('should show warning message', () => {
const props = {
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -133,6 +147,7 @@ const defaultRefreshIntervalModalProps = {
onChange: jest.fn(),
editMode: true,
addSuccessToast: jest.fn(),
refreshIntervalOptions: [],
};

describe('RefreshIntervalModal - RTL', () => {
Expand Down
29 changes: 13 additions & 16 deletions superset-frontend/src/dashboard/components/RefreshIntervalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,6 +44,7 @@ type RefreshIntervalModalProps = {
editMode: boolean;
refreshLimit?: number;
refreshWarning: string | null;
refreshIntervalOptions: [number, string][];
};

type RefreshIntervalModalState = {
Expand Down Expand Up @@ -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;
Expand All @@ -120,7 +114,10 @@ class RefreshIntervalModal extends React.PureComponent<
<FormLabel>{t('Refresh frequency')}</FormLabel>
<Select
ariaLabel={t('Refresh interval')}
options={options}
options={refreshIntervalOptions.map(option => ({
value: option[0],
label: t(option[1]),
}))}
value={refreshFrequency}
onChange={this.handleFrequencyChange}
sortComparator={propertyComparator('value')}
Expand Down
13 changes: 13 additions & 0 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down