From cb999a824522470d28716da7dfa527d1466b690f Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 3 Mar 2020 15:30:43 -0800 Subject: [PATCH 1/2] fix: clear the filters after the dashboard has been switched --- src/actions/dashboards.js | 19 ------------------- src/actions/selected.js | 38 +++++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/actions/dashboards.js b/src/actions/dashboards.js index 1658396f7..e98b5d833 100644 --- a/src/actions/dashboards.js +++ b/src/actions/dashboards.js @@ -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, @@ -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()); } diff --git a/src/actions/selected.js b/src/actions/selected.js index 20d1d7e48..eef8ce0f9 100644 --- a/src/actions/selected.js +++ b/src/actions/selected.js @@ -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 { tGetMessages } from '../components/Item/MessagesItem/actions'; +import { acClearEditItemFilters } from './editItemFilters'; +import { acClearItemFilters, acSetItemFilters } from './itemFilters'; 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 { tGetMessages } from '../components/Item/MessagesItem/actions'; import { loadingDashboardMsg } from '../components/SnackbarMessage/SnackbarMessage'; +import { extractFavorite } from '../components/Item/VisualizationItem/plugin'; + import { REPORT_TABLE, CHART, @@ -22,7 +32,6 @@ import { EVENT_CHART, MESSAGES, } from '../modules/itemTypes'; -import { extractFavorite } from '../components/Item/VisualizationItem/plugin'; import { orObject } from '../modules/util'; // actions @@ -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); @@ -100,6 +110,20 @@ export const tSetSelectedDashboardById = id => async (dispatch, getState) => { } }); + if (id === sGetSelectedId(getState())) { + if (sGetIsEditing(getState())) { + // disable filters when switching to edit mode + dispatch(acClearItemFilters()); + } else { + // enable filters when switching to view mode + dispatch(acSetItemFilters(sGetEditItemFiltersRoot(getState()))); + } + } else { + // clear filters when switching dashboard + dispatch(acClearEditItemFilters()); + dispatch(acClearItemFilters()); + } + dispatch(acSetSelectedId(id)); dispatch(acSetSelectedIsLoading(false)); From 53c2f281eb8b5e2123fd2582bd8764ce474d7194 Mon Sep 17 00:00:00 2001 From: Jen Jones Arnesen Date: Tue, 3 Mar 2020 19:53:00 -0800 Subject: [PATCH 2/2] fix: no need to use getState at each call --- src/actions/selected.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/actions/selected.js b/src/actions/selected.js index eef8ce0f9..99384f18c 100644 --- a/src/actions/selected.js +++ b/src/actions/selected.js @@ -13,6 +13,7 @@ import { sGetUserUsername } from '../reducers/user'; import { acSetDashboardItems, acAppendDashboards } from './dashboards'; 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'; @@ -20,7 +21,6 @@ import { apiFetchDashboard } from '../api/dashboards'; import { storePreferredDashboardId } from '../api/localStorage'; import { withShape } from '../components/ItemGrid/gridUtil'; -import { tGetMessages } from '../components/Item/MessagesItem/actions'; import { loadingDashboardMsg } from '../components/SnackbarMessage/SnackbarMessage'; import { extractFavorite } from '../components/Item/VisualizationItem/plugin'; @@ -110,13 +110,14 @@ export const tSetSelectedDashboardById = id => async (dispatch, getState) => { } }); - if (id === sGetSelectedId(getState())) { - if (sGetIsEditing(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(getState()))); + dispatch(acSetItemFilters(sGetEditItemFiltersRoot(state))); } } else { // clear filters when switching dashboard