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
32 changes: 32 additions & 0 deletions superset-frontend/src/configs.ts
Original file line number Diff line number Diff line change
@@ -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() {
zhaorui2022 marked this conversation as resolved.
Show resolved Hide resolved
// 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;
}
10 changes: 10 additions & 0 deletions superset-frontend/src/dashboard/components/Dashboard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ 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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ jest.mock('src/dashboard/components/nativeFilters/FilterBar', () => () => (
jest.mock('src/dashboard/containers/DashboardGrid', () => () => (
<div data-test="mock-dashboard-grid" />
));
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;
Expand Down
10 changes: 10 additions & 0 deletions superset-frontend/src/dashboard/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ 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(
<div className="dashboard">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(<RefreshIntervalModal {...props} />, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions superset-frontend/src/views/CRUD/dashboard/DashboardList.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ 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'],
],
})),
}));

describe('DashboardList', () => {
const isFeatureEnabledMock = jest
.spyOn(featureFlags, 'isFeatureEnabled')
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