Skip to content

Commit

Permalink
feat(wip): this is a WIP. Made slight changes to the thunk for coloca…
Browse files Browse the repository at this point in the history
…tion purposes and added some filter logic to subgraphs
  • Loading branch information
asalem1 committed May 13, 2020
1 parent 4a19780 commit 928f4c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions ui/src/variables/actions/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,13 @@ export const hydrateVariables = (skipCache?: boolean) => async (
await hydration.promise
}

export const hydrateChangedVariable = (variable: Variable) => async (
export const hydrateChangedVariable = (variableID: string) => async (
dispatch: Dispatch<Action>,
getState: GetState
) => {
const state = getState()
const org = getOrg(state)
const variable = getVariableFromState(state, variableID)
const hydration = hydrateVars([variable], getAllVariablesFromState(state), {
orgID: org.id,
url: state.links.query.self,
Expand Down Expand Up @@ -432,6 +433,7 @@ export const selectValue = (variableID: string, selected: string) => async (

await dispatch(selectValueInState(contextID, variableID, selected))
// only hydrate the changedVariable
dispatch(hydrateChangedVariable(variable))
dispatch(hydrateChangedVariable(variableID))
// dispatch(hydrateVariables(true))
dispatch(updateQueryVars({[variable.name]: selected}))
}
12 changes: 10 additions & 2 deletions ui/src/variables/utils/hydrateVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ const findSubgraph = (

// use an ID array to reduce the chance of reference errors
const varIDs = variables.map(v => v.id)
// create an array of IDs to reference later
const graphIDs = []
for (const node of graph) {
const shouldKeep =
varIDs.includes(node.variable.id) ||
Expand All @@ -138,12 +140,17 @@ const findSubgraph = (

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

for (const node of subgraph) {
node.parents = node.parents.filter(node => subgraph.has(node))
node.children = node.children.filter(node => subgraph.has(node))
// node.parents = node.parents.filter(n => {
// const {id} = n.variable
// return !graphIDs.includes(id)
// })
// node.parents = node.parents.filter(n => !subgraph.has(n))
node.children = node.children.filter(n => subgraph.has(n))
}

return [...subgraph]
Expand Down Expand Up @@ -488,6 +495,7 @@ export const hydrateVars = (
// register listeners for the loading state changes
Promise.resolve()
.then(() => {
console.log('graph in promise resolve: ', graph)
return Promise.all(findLeaves(graph).map(resolve))
})
.then(() => {
Expand Down

0 comments on commit 928f4c6

Please sign in to comment.