Remove deleted tempVars from URL query upon manager save

pull/3556/head
Jared Scheib 2018-05-30 15:34:35 -07:00 committed by Deniz Kusefoglu
parent b592cede56
commit 747443da49
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 queryString from 'query-string'
import {push} from 'react-router-redux'
import { import {
getDashboards as getDashboardsAJAX, getDashboards as getDashboardsAJAX,
@ -365,9 +366,14 @@ export const updateTempVarValues = (source, dashboard) => async dispatch => {
export const syncURLQueryFromQueryObject = ( export const syncURLQueryFromQueryObject = (
location, location,
updatedQuery updatedQuery,
deletedQueries = {}
) => dispatch => { ) => dispatch => {
const updatedLocationQuery = {...location.query, ...updatedQuery} const updatedLocationQuery = {...location.query, ...updatedQuery}
_.each(deletedQueries, (v, k) => {
delete updatedLocationQuery[k]
})
const updatedSearchString = queryString.stringify(updatedLocationQuery) const updatedSearchString = queryString.stringify(updatedLocationQuery)
const updatedSearch = {search: updatedSearchString} const updatedSearch = {search: updatedSearchString}
const updatedLocation = { const updatedLocation = {
@ -379,8 +385,15 @@ export const syncURLQueryFromQueryObject = (
dispatch(push(updatedLocation)) dispatch(push(updatedLocation))
} }
export const syncURLQueryFromTempVars = (location, tempVars) => dispatch => { export const syncURLQueryFromTempVars = (
location,
tempVars,
deletedTempVars = []
) => dispatch => {
const updatedQueries = generateURLQueryFromTempVars(tempVars) 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, templates,
}) })
onSaveTemplatesSuccess() 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) { } catch (error) {
console.error(error) console.error(error)
} }