Remove deleted tempVars from URL query upon manager save

pull/10616/head
Jared Scheib 2018-05-30 15:34:35 -07:00 committed by Deniz Kusefoglu
parent 65f15927ce
commit 62c39c00f8
2 changed files with 26 additions and 5 deletions

View File

@ -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)
)
}

View File

@ -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)
}