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: clear the filters after the dashboard has been switched #612

Merged
merged 2 commits into from
Mar 4, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions src/actions/dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ import {
} from '../reducers/dashboards';
import { sGetUserUsername } from '../reducers/user';
import { tSetSelectedDashboardById, acSetSelectedId } from './selected';
import { sGetSelectedId } from '../reducers/selected';
import { sGetIsEditing } from '../reducers/editDashboard';
import { sGetEditItemFiltersRoot } from '../reducers/editItemFilters';
import { acSetItemFilters, acClearItemFilters } from './itemFilters';
import { acClearEditItemFilters } from './editItemFilters';
import { acClearEditDashboard } from './editDashboard';
import {
apiFetchDashboards,
Expand Down Expand Up @@ -87,20 +82,6 @@ export const tSelectDashboard = id => async (dispatch, getState) => {

if (dashboardToSelect) {
dispatch(tSetSelectedDashboardById(dashboardToSelect.id));

if (dashboardToSelect.id === sGetSelectedId(state)) {
if (sGetIsEditing(state)) {
// disable filters when switching to edit mode
dispatch(acClearItemFilters());
} else {
// enable filters when switching to view mode
dispatch(acSetItemFilters(sGetEditItemFiltersRoot(state)));
}
} else {
// clear filters when switching dashboard
dispatch(acClearEditItemFilters());
dispatch(acClearItemFilters());
}
} else {
dispatch(acSetSelectedId());
}
Expand Down
37 changes: 31 additions & 6 deletions src/actions/selected.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { getCustomDashboards, sGetDashboardById } from '../reducers/dashboards';
import { sGetIsEditing } from '../reducers/editDashboard';
import { sGetEditItemFiltersRoot } from '../reducers/editItemFilters';
import {
SET_SELECTED_ID,
SET_SELECTED_ISLOADING,
SET_SELECTED_SHOWDESCRIPTION,
sGetSelectedIsLoading,
sGetSelectedId,
} from '../reducers/selected';
import { acAddVisualization } from '../actions/visualizations';
import { sGetSelectedIsLoading } from '../reducers/selected';
import { sGetUserUsername } from '../reducers/user';
import { getCustomDashboards, sGetDashboardById } from '../reducers/dashboards';
import { apiFetchDashboard } from '../api/dashboards';

import { acSetDashboardItems, acAppendDashboards } from './dashboards';
import { withShape } from '../components/ItemGrid/gridUtil';
import { acClearEditItemFilters } from './editItemFilters';
import { acClearItemFilters, acSetItemFilters } from './itemFilters';
import { tGetMessages } from '../components/Item/MessagesItem/actions';
import { acReceivedSnackbarMessage, acCloseSnackbar } from './snackbar';
import { acAddVisualization } from './visualizations';

import { apiFetchDashboard } from '../api/dashboards';
import { storePreferredDashboardId } from '../api/localStorage';

import { withShape } from '../components/ItemGrid/gridUtil';
import { loadingDashboardMsg } from '../components/SnackbarMessage/SnackbarMessage';
import { extractFavorite } from '../components/Item/VisualizationItem/plugin';

import {
REPORT_TABLE,
CHART,
Expand All @@ -22,7 +32,6 @@ import {
EVENT_CHART,
MESSAGES,
} from '../modules/itemTypes';
import { extractFavorite } from '../components/Item/VisualizationItem/plugin';
import { orObject } from '../modules/util';

// actions
Expand All @@ -45,6 +54,7 @@ export const acSetSelectedShowDescription = value => ({
export const tLoadDashboard = id => async dispatch => {
try {
const dash = await apiFetchDashboard(id);

dispatch(acAppendDashboards(dash));

return Promise.resolve(dash);
Expand Down Expand Up @@ -100,6 +110,21 @@ export const tSetSelectedDashboardById = id => async (dispatch, getState) => {
}
});

const state = getState();
if (id === sGetSelectedId(state)) {
if (sGetIsEditing(state)) {
// disable filters when switching to edit mode
dispatch(acClearItemFilters());
} else {
// enable filters when switching to view mode
dispatch(acSetItemFilters(sGetEditItemFiltersRoot(state)));
}
} else {
// clear filters when switching dashboard
dispatch(acClearEditItemFilters());
dispatch(acClearItemFilters());
}

dispatch(acSetSelectedId(id));

dispatch(acSetSelectedIsLoading(false));
Expand Down