diff --git a/ui/src/dashboards/actions/index.js b/ui/src/dashboards/actions/index.js index 56c9fff99d..97eb50e456 100644 --- a/ui/src/dashboards/actions/index.js +++ b/ui/src/dashboards/actions/index.js @@ -1,5 +1,6 @@ -import {push} from 'react-router-redux' +import _ from 'lodash' import queryString from 'query-string' +import {push} from 'react-router-redux' import { getDashboards as getDashboardsAJAX, @@ -365,9 +366,14 @@ export const updateTempVarValues = (source, dashboard) => async dispatch => { export const syncURLQueryFromQueryObject = ( location, - updatedQuery + updatedQuery, + deletedQueries = {} ) => dispatch => { const updatedLocationQuery = {...location.query, ...updatedQuery} + _.each(deletedQueries, (v, k) => { + delete updatedLocationQuery[k] + }) + const updatedSearchString = queryString.stringify(updatedLocationQuery) const updatedSearch = {search: updatedSearchString} const updatedLocation = { @@ -379,8 +385,15 @@ export const syncURLQueryFromQueryObject = ( dispatch(push(updatedLocation)) } -export const syncURLQueryFromTempVars = (location, tempVars) => dispatch => { +export const syncURLQueryFromTempVars = ( + location, + tempVars, + deletedTempVars = [] +) => dispatch => { const updatedQueries = generateURLQueryFromTempVars(tempVars) + const deletedQueries = generateURLQueryFromTempVars(deletedTempVars) - dispatch(syncURLQueryFromQueryObject(location, updatedQueries)) + dispatch( + syncURLQueryFromQueryObject(location, updatedQueries, deletedQueries) + ) } diff --git a/ui/src/dashboards/containers/DashboardPage.js b/ui/src/dashboards/containers/DashboardPage.js index 974c0e57fd..a180540964 100644 --- a/ui/src/dashboards/containers/DashboardPage.js +++ b/ui/src/dashboards/containers/DashboardPage.js @@ -301,7 +301,15 @@ class DashboardPage extends Component { templates, }) onSaveTemplatesSuccess() - dashboardActions.syncURLQueryFromTempVars(location, templates) + const deletedTempVars = dashboard.templates.filter( + ({tempVar: oldTempVar}) => + !templates.find(({tempVar: newTempVar}) => oldTempVar === newTempVar) + ) + dashboardActions.syncURLQueryFromTempVars( + location, + templates, + deletedTempVars + ) } catch (error) { console.error(error) }