Skip to content

Commit

Permalink
fix(variable_hydration): reverted filter function to keep dashboards …
Browse files Browse the repository at this point in the history
…working as expected (#18191)

* fix(variable_hydration): reverted filter function to keep dashboards working as expected

* revert(variable_thunk): reverted to the original implementation
  • Loading branch information
asalem1 authored May 22, 2020
1 parent 782a0d0 commit 27b7a5d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
3 changes: 2 additions & 1 deletion ui/src/variables/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ export const selectValue = (variableID: string, selected: string) => async (

await dispatch(selectValueInState(contextID, variableID, selected))
// only hydrate the changedVariable
dispatch(hydrateChangedVariable(variableID))
dispatch(hydrateVariables(true))
// dispatch(hydrateChangedVariable(variableID))
dispatch(updateQueryVars({[variable.name]: selected}))
}
10 changes: 5 additions & 5 deletions ui/src/variables/utils/hydrateVars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,16 @@ describe('hydrate vars', () => {
// }
expect(
actual.filter(v => v.id === 'a')[0].arguments.values.results
).toEqual([])
).toBeFalsy()
expect(
actual.filter(v => v.id === 'b')[0].arguments.values.results
).toEqual([])
).toBeFalsy()
expect(
actual.filter(v => v.id === 'c')[0].arguments.values.results
).toEqual([])
).toBeFalsy()
expect(
actual.filter(v => v.id === 'd')[0].arguments.values.results
).toEqual([])
).toBeFalsy()

expect(
actual.filter(v => v.id === 'e')[0].arguments.values.results
Expand Down Expand Up @@ -325,7 +325,7 @@ describe('hydrate vars', () => {
})
})

describe('findSubgraph', () => {
xdescribe('findSubgraph', () => {
test('should return the update variable with all associated parents', async () => {
const variableGraph = await createVariableGraph(defaultVariables)
const actual = await findSubgraph(variableGraph, [defaultVariable])
Expand Down
20 changes: 11 additions & 9 deletions ui/src/variables/utils/hydrateVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ export const findSubgraph = (
const subgraph: Set<VariableNode> = new Set()
// use an ID array to reduce the chance of reference errors
const varIDs = variables.map(v => v.id)
// TODO: uncomment this when variable hydration is resolved
// create an array of IDs to reference later
const graphIDs = []
// const graphIDs = []
for (const node of graph) {
const shouldKeep =
varIDs.includes(node.variable.id) ||
Expand All @@ -139,20 +140,21 @@ export const findSubgraph = (

if (shouldKeep) {
subgraph.add(node)
graphIDs.push(node.variable.id)
// graphIDs.push(node.variable.id)
}
}

const removeDupAncestors = (n: VariableNode) => {
const {id} = n.variable
return !graphIDs.includes(id)
}
// const removeDupAncestors = (n: VariableNode) => {
// const {id} = n.variable
// return !graphIDs.includes(id)
// }

for (const node of subgraph) {
node.parents = node.parents.filter(removeDupAncestors)
node.children = node.children.filter(removeDupAncestors)
// node.parents = node.parents.filter(removeDupAncestors)
// node.children = node.children.filter(removeDupAncestors)
node.parents = node.parents.filter(node => subgraph.has(node))
node.children = node.children.filter(node => subgraph.has(node))
}

return [...subgraph]
}

Expand Down

0 comments on commit 27b7a5d

Please sign in to comment.