Skip to content

Commit

Permalink
fix(findSubgraph): simplified findSubgraph logic to fix breaking e2e …
Browse files Browse the repository at this point in the history
…test. Need to write unit tests to validate work
  • Loading branch information
asalem1 committed May 18, 2020
1 parent 8964f8f commit c9f1eff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion ui/src/shared/components/graph_tips/GraphTips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const GraphTips: FC = () => (
</p>
<h1>Static Legend Tips:</h1>
<p>
<code>Click</code>Focus on single Series
<code>Click</code> Focus on single Series
<br />
<code>Shift + Click</code> Show/Hide single Series
</p>
Expand Down
41 changes: 18 additions & 23 deletions ui/src/variables/utils/hydrateVars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ const findSubgraph = (
variables: Variable[]
): VariableNode[] => {
const subgraph: Set<VariableNode> = new Set()

// 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
Expand All @@ -144,13 +143,14 @@ const findSubgraph = (
}
}

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

for (const node of subgraph) {
// 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))
node.parents = node.parents.filter(removeDupAncestors)
node.children = node.children.filter(removeDupAncestors)
}

return [...subgraph]
Expand Down Expand Up @@ -230,15 +230,14 @@ const hydrateVarsHelper = async (
if (node.status !== RemoteDataState.Loading) {
node.status = RemoteDataState.Loading
on.fire('status', node.variable, node.status)

collectAncestors(node)
.filter(parent => parent.variable.arguments.type === 'query')
.forEach(parent => {
if (parent.status !== RemoteDataState.Loading) {
parent.status = RemoteDataState.Loading
on.fire('status', parent.variable, parent.status)
}
})
.filter(parent => parent.variable.arguments.type === 'query')
.forEach(parent => {
if (parent.status !== RemoteDataState.Loading) {
parent.status = RemoteDataState.Loading
on.fire('status', parent.variable, parent.status)
}
})
}

const descendants = collectDescendants(node)
Expand Down Expand Up @@ -398,10 +397,9 @@ export const hydrateVars = (
allVariables: Variable[],
options: HydrateVarsOptions
): EventedCancelBox<Variable[]> => {
const graph = findSubgraph(
createVariableGraph(allVariables),
variables
).filter(n => n.variable.arguments.type !== 'system')
const graph = findSubgraph(createVariableGraph(allVariables), variables).filter(
n => n.variable.arguments.type !== 'system'
)
invalidateCycles(graph)

let isCancelled = false
Expand Down Expand Up @@ -494,10 +492,7 @@ export const hydrateVars = (
// from the main execution thread, allowing external services to
// 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(() => Promise.all(findLeaves(graph).map(resolve)))
.then(() => {
deferred.resolve(extractResult(graph))
})
Expand Down

0 comments on commit c9f1eff

Please sign in to comment.