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

fix(dashboard): Refresh Native Filters when Dashboard refreshes #15890

Merged
merged 5 commits into from Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions superset-frontend/src/dashboard/actions/dashboardState.js
Expand Up @@ -275,6 +275,32 @@ export function fetchCharts(
};
}

const refreshCharts = (chartList, force, interval, dashboardId, dispatch) =>
new Promise(resolve => {
dispatch(fetchCharts(chartList, force, interval, dashboardId));
resolve();
});

export const ON_REFRESH_SUCCESS = 'ON_REFRESH_SUCCESS';
export function onRefreshSuccess() {
return { type: ON_REFRESH_SUCCESS };
}

export const ON_REFRESH = 'ON_REFRESH';
export function onRefresh(
chartList = [],
force = false,
interval = 0,
dashboardId,
) {
return dispatch => {
dispatch({ type: ON_REFRESH });
refreshCharts(chartList, force, interval, dashboardId, dispatch).then(() =>
dispatch({ type: ON_REFRESH_SUCCESS }),
);
};
}

export const SHOW_BUILDER_PANE = 'SHOW_BUILDER_PANE';
export function showBuilderPane() {
return { type: SHOW_BUILDER_PANE };
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/actions/hydrate.js
Expand Up @@ -378,6 +378,7 @@ export const hydrateDashboard = (dashboardData, chartData) => (
hasUnsavedChanges: false,
maxUndoHistoryExceeded: false,
lastModifiedTime: dashboardData.changed_on,
isRefreshing: false,
activeTabs: [],
},
dashboardLayout,
Expand Down
Expand Up @@ -54,6 +54,7 @@ const createProps = () => ({
onChange: jest.fn(),
fetchFaveStar: jest.fn(),
fetchCharts: jest.fn(),
onRefresh: jest.fn(),
saveFaveStar: jest.fn(),
savePublished: jest.fn(),
isPublished: false,
Expand Down Expand Up @@ -301,5 +302,5 @@ test('should refresh the charts', async () => {
render(setup(mockedProps));
await openActionsDropdown();
userEvent.click(screen.getByText('Refresh dashboard'));
expect(mockedProps.fetchCharts).toHaveBeenCalledTimes(1);
expect(mockedProps.onRefresh).toHaveBeenCalledTimes(1);
});
4 changes: 2 additions & 2 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Expand Up @@ -82,6 +82,7 @@ const propTypes = {
lastModifiedTime: PropTypes.number.isRequired,

// redux
onRefresh: PropTypes.func.isRequired,
onUndo: PropTypes.func.isRequired,
onRedo: PropTypes.func.isRequired,
undoLength: PropTypes.number.isRequired,
Expand Down Expand Up @@ -216,8 +217,7 @@ class Header extends React.PureComponent {
interval: 0,
chartCount: chartList.length,
});

return this.props.fetchCharts(
return this.props.onRefresh(
chartList,
true,
0,
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/components/Header/types.ts
Expand Up @@ -87,6 +87,7 @@ export interface HeaderProps {
lastModifiedTime: number;
onUndo: () => void;
onRedo: () => void;
onRefresh: () => void;
undoLength: number;
redoLength: number;
setMaxUndoHistoryExceeded: () => void;
Expand Down
Expand Up @@ -28,14 +28,15 @@ import {
JsonObject,
getChartMetadataRegistry,
} from '@superset-ui/core';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { areObjectsEqual } from 'src/reduxUtils';
import { getChartDataRequest } from 'src/chart/chartAction';
import Loading from 'src/components/Loading';
import BasicErrorAlert from 'src/components/ErrorMessage/BasicErrorAlert';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import { waitForAsyncData } from 'src/middleware/asyncEvent';
import { ClientErrorObject } from 'src/utils/getClientErrorObject';
import { RootState } from 'src/dashboard/types';
import { dispatchFocusAction } from './utils';
import { FilterProps } from './types';
import { getFormData } from '../../utils';
Expand All @@ -62,6 +63,9 @@ const FilterValue: React.FC<FilterProps> = ({
const { id, targets, filterType, adhoc_filters, time_range } = filter;
const metadata = getChartMetadataRegistry().get(filterType);
const cascadingFilters = useCascadingFilters(id, dataMaskSelected);
const isDashboardRefreshing = useSelector<RootState, boolean>(
state => state.dashboardState.isRefreshing,
);
const [state, setState] = useState<ChartDataResponseResult[]>([]);
const [error, setError] = useState<string>('');
const [formData, setFormData] = useState<Partial<QueryFormData>>({
Expand All @@ -78,7 +82,7 @@ const FilterValue: React.FC<FilterProps> = ({
const { name: groupby } = column;
const hasDataSource = !!datasetId;
const [isLoading, setIsLoading] = useState<boolean>(hasDataSource);
const [isRefreshing, setIsRefreshing] = useState(true);
const [isRefreshing, setIsRefreshing] = useState(false);
const dispatch = useDispatch();

useEffect(() => {
Expand All @@ -102,8 +106,10 @@ const FilterValue: React.FC<FilterProps> = ({
});
const filterOwnState = filter.dataMask?.ownState || {};
if (
!areObjectsEqual(formData, newFormData) ||
!areObjectsEqual(ownState, filterOwnState)
!isRefreshing &&
(!areObjectsEqual(formData, newFormData) ||
!areObjectsEqual(ownState, filterOwnState) ||
isDashboardRefreshing)
) {
setFormData(newFormData);
setOwnState(filterOwnState);
Expand Down Expand Up @@ -165,6 +171,8 @@ const FilterValue: React.FC<FilterProps> = ({
groupby,
JSON.stringify(filter),
hasDataSource,
isRefreshing,
isDashboardRefreshing,
]);

useEffect(() => {
Expand Down
Expand Up @@ -39,6 +39,7 @@ import {
setMaxUndoHistoryExceeded,
maxUndoHistoryToast,
setRefreshFrequency,
onRefresh,
} from '../actions/dashboardState';

import {
Expand Down Expand Up @@ -120,6 +121,7 @@ function mapDispatchToProps(dispatch) {
maxUndoHistoryToast,
logEvent,
setRefreshFrequency,
onRefresh,
dashboardInfoChanged,
dashboardTitleChanged,
updateDataMask,
Expand Down
14 changes: 14 additions & 0 deletions superset-frontend/src/dashboard/reducers/dashboardState.js
Expand Up @@ -32,6 +32,8 @@ import {
TOGGLE_PUBLISHED,
UPDATE_CSS,
SET_REFRESH_FREQUENCY,
ON_REFRESH,
ON_REFRESH_SUCCESS,
SET_DIRECT_PATH,
SET_FOCUSED_FILTER_FIELD,
UNSET_FOCUSED_FILTER_FIELD,
Expand Down Expand Up @@ -128,6 +130,18 @@ export default function dashboardStateReducer(state = {}, action) {
hasUnsavedChanges: action.isPersistent,
};
},
[ON_REFRESH]() {
return {
...state,
isRefreshing: true,
};
},
[ON_REFRESH_SUCCESS]() {
return {
...state,
isRefreshing: false,
};
},
[SET_DIRECT_PATH]() {
return {
...state,
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/types.ts
Expand Up @@ -60,6 +60,7 @@ export type DashboardState = {
directPathToChild: string[];
activeTabs: ActiveTabs;
fullSizeChartId: number | null;
isRefreshing: boolean;
};
export type DashboardInfo = {
common: {
Expand Down