Skip to content

Commit

Permalink
Sort sibling nodes again when a delta with an updated workflow is rec…
Browse files Browse the repository at this point in the history
…eived
  • Loading branch information
kinow committed Sep 16, 2021
1 parent dd1c293 commit 1d19a63
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
38 changes: 36 additions & 2 deletions src/components/cylc/gscan/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,45 @@ function updateWorkflow (workflow, gscan, options) {
throw new Error(`Updated node [${workflow.id}] not found in workflow lookup`)
}
mergeWith(existingData.node, workflow, mergeWithCustomizer)
Vue.set(gscan.lookup, existingData.id, existingData)
// FIXME: we need to sort its parent again!
const hierarchical = options.hierarchical || true
if (hierarchical) {
updateHierarchicalWorkflow(existingData, gscan.lookup, gscan.tree, options)
}
// TODO: create workflow hierarchy (from workflow object), then iterate
// it and use lookup to fetch the existing node. Finally, combine
// the gscan states (latestStateTasks & stateTotals).
Vue.set(gscan.lookup, existingData.id, existingData)
}

function updateHierarchicalWorkflow (existingData, lookup, tree, options) {
// We need to sort its parent again.
const workflowNameParts = parseWorkflowNameParts(existingData.id)
const nodesIds = getWorkflowNamePartsNodesIds(workflowNameParts)
// Discard the last since it's the workflow ID that we already have
// in the `existingData` object. Now if not empty, we have our parent.
nodesIds.pop()
const parentId = nodesIds.length > 0 ? nodesIds.pop() : null
const parent = parentId ? lookup[parentId] : tree
if (!parent) {
throw new Error(`Invalid orphan hierarchical node: ${existingData.id}`)
}
const siblings = parent.children
// Where is this node at the moment?
const currentIndex = siblings.findIndex(node => node.id === existingData.id)
// Where should it be now?
const sortedIndex = sortedIndexBy(
parent.children,
existingData,
(n) => n.name,
sortWorkflowNamePartNodeOrWorkflowNode
)
// If it is not where it is, we need to add it to its correct location.
if (currentIndex !== sortedIndex) {
// siblings.splice(currentIndex, 1)
// siblings.splice(sortedIndex, 0, existingData)
Vue.delete(siblings, currentIndex)
Vue.set(siblings, sortedIndex, existingData)
}
}

// -- Pruned
Expand Down
1 change: 1 addition & 0 deletions src/components/cylc/gscan/nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function getWorkflowNamePartsNodesIds (workflowNameParts) {
return prefix
})
nodesIds.push(workflowNameParts.workflowId)
return nodesIds
}

/**
Expand Down

0 comments on commit 1d19a63

Please sign in to comment.