Skip to content

Commit 7ab6a3d

Browse files
committed
Handle GScan updated delta
1 parent 3c0d793 commit 7ab6a3d

File tree

3 files changed

+41
-36
lines changed

3 files changed

+41
-36
lines changed

src/components/cylc/gscan/deltas.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17-
import { addWorkflow, updateWorkflow, removeWorkflow } from '@/components/cylc/gscan/index'
18-
import { createWorkflowNode } from '@/components/cylc/gscan/nodes'
17+
import * as GScanTree from '@/components/cylc/gscan/index'
1918

2019
/**
2120
* Deltas added.
@@ -30,10 +29,9 @@ function applyDeltasAdded (added, gscan, options) {
3029
errors: []
3130
}
3231
if (added.workflow) {
33-
const hierarchical = options.hierarchical || true
34-
const workflowNode = createWorkflowNode(added.workflow, hierarchical)
32+
const workflow = added.workflow
3533
try {
36-
addWorkflow(workflowNode, gscan, options)
34+
GScanTree.addWorkflow(workflow, gscan, options)
3735
} catch (error) {
3836
result.errors.push([
3937
'Error applying added-delta, see browser console logs for more. Please reload your browser tab to retrieve the full flow state',
@@ -60,26 +58,14 @@ function applyDeltasUpdated (updated, gscan, options) {
6058
errors: []
6159
}
6260
if (updated.workflow) {
63-
const updatedData = updated.workflow
61+
const workflow = updated.workflow
6462
try {
65-
const existingData = gscan.lookup[updatedData.id]
66-
if (!existingData) {
67-
result.errors.push([
68-
`Updated node [${updatedData.id}] not found in workflow lookup`,
69-
updatedData,
70-
gscan,
71-
options
72-
])
73-
} else {
74-
// TODO: hierarchy is always false here?
75-
const workflowNode = createWorkflowNode(updatedData, false)
76-
updateWorkflow(workflowNode, gscan, options)
77-
}
63+
GScanTree.updateWorkflow(workflow, gscan, options)
7864
} catch (error) {
7965
result.errors.push([
8066
'Error applying updated-delta, see browser console logs for more. Please reload your browser tab to retrieve the full flow state',
8167
error,
82-
updatedData,
68+
workflow,
8369
gscan,
8470
options
8571
])
@@ -100,11 +86,12 @@ function applyDeltasPruned (pruned, gscan, options) {
10086
const result = {
10187
errors: []
10288
}
103-
// TODO: why not pruned.workflows???
89+
// TBD: why not workflows? We have that in the jsdoc for DeltasPruned, and I believe
90+
// that's how other queries return the data.
10491
if (pruned.workflow) {
10592
const workflowId = pruned.workflow
10693
try {
107-
removeWorkflow(workflowId, gscan, options)
94+
GScanTree.removeWorkflow(workflowId, gscan, options)
10895
} catch (error) {
10996
result.errors.push([
11097
'Error applying pruned-delta, see browser console logs for more. Please reload your browser tab to retrieve the full flow state',
@@ -137,17 +124,17 @@ const DELTAS = {
137124
* @returns {Result}
138125
*/
139126
function handleDeltas (deltas, gscan, options) {
140-
const errors = []
127+
const results = {
128+
errors: []
129+
}
141130
Object.keys(DELTAS).forEach(key => {
142131
if (deltas[key]) {
143132
const handlingFunction = DELTAS[key]
144133
const result = handlingFunction(deltas[key], gscan, options)
145-
errors.push(...result.errors)
134+
results.errors.push(...result.errors)
146135
}
147136
})
148-
return {
149-
errors
150-
}
137+
return results
151138
}
152139

153140
/**

src/components/cylc/gscan/index.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
* You should have received a copy of the GNU General Public License
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
17+
import Vue from 'vue'
18+
import { mergeWith } from 'lodash'
19+
import { sortedIndexBy } from '@/components/cylc/common/sort'
20+
import { mergeWithCustomizer } from '@/components/cylc/common/merge'
21+
import { sortWorkflowNamePartNodeOrWorkflowNode } from '@/components/cylc/gscan/sort'
22+
import { createWorkflowNode } from '@/components/cylc/gscan/nodes'
1723

1824
/**
1925
* @typedef {Object} GScan
@@ -25,9 +31,6 @@
2531
* @typedef {Object<String, TreeNode>} Lookup
2632
*/
2733

28-
import { sortedIndexBy } from '@/components/cylc/common/sort'
29-
import { sortWorkflowNamePartNodeOrWorkflowNode } from '@/components/cylc/gscan/sort'
30-
3134
/**
3235
* @param {TreeNode} workflow
3336
* @param {GScan} gscan
@@ -36,18 +39,24 @@ import { sortWorkflowNamePartNodeOrWorkflowNode } from '@/components/cylc/gscan/
3639
function addWorkflow (workflow, gscan, options) {
3740
const hierarchical = options.hierarchical || true
3841
if (hierarchical) {
39-
addHierarchicalWorkflow(workflow, gscan.lookup, gscan.tree, options)
42+
const workflowNode = createWorkflowNode(workflow, hierarchical)
43+
addHierarchicalWorkflow(workflowNode, gscan.lookup, gscan.tree, options)
4044
} else {
4145
gscan.lookup[workflow.id] = workflow
4246
gscan.tree.push(workflow)
4347
}
4448
}
4549

4650
/**
51+
* This function is private. It receives a lookup and tree instead of a GScan object (as in other
52+
* functions of this module). This is required as we apply recursion for adding nodes into the tree,
53+
* but we replace the tree and pass only a sub-tree.
54+
*
4755
* @param workflow
4856
* @param {Lookup} lookup
4957
* @param {Array<TreeNode>} tree
5058
* @param {*} options
59+
* @private
5160
*/
5261
function addHierarchicalWorkflow (workflow, lookup, tree, options) {
5362
if (!lookup[workflow.id]) {
@@ -78,24 +87,34 @@ function addHierarchicalWorkflow (workflow, lookup, tree, options) {
7887
// we will have to merge the hierarchies
7988
const existingNode = lookup[workflow.id]
8089
// TODO: combine states summaries?
81-
// Copy array since we will iterate it, and modify existingNode.children
8290
if (existingNode.children) {
91+
// Copy array since we will iterate it, and modify existingNode.children
8392
const children = [...workflow.children]
8493
for (const child of children) {
8594
// Recursion
8695
addHierarchicalWorkflow(child, lookup, existingNode.children, options)
8796
}
97+
} else {
98+
// Here we have an existing workflow node. Let's merge it.
99+
mergeWith(existingNode, workflow, mergeWithCustomizer)
88100
}
89101
}
90102
}
91103

92104
/**
93-
* @param {TreeNode} workflow
105+
* @param {WorkflowGraphQLData} workflow
94106
* @param {GScan} gscan
95107
* @param {*} options
96108
*/
97109
function updateWorkflow (workflow, gscan, options) {
98-
110+
// We don't care whether it is hierarchical or not here, since we can quickly
111+
// access the node via the GScan lookup.
112+
const existingData = gscan.lookup[workflow.id]
113+
if (!existingData) {
114+
throw new Error(`Updated node [${workflow.id}] not found in workflow lookup`)
115+
}
116+
mergeWith(existingData.node, workflow, mergeWithCustomizer)
117+
Vue.set(gscan.lookup, existingData.id, existingData)
99118
}
100119

101120
/**

src/components/cylc/gscan/nodes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { sortWorkflowNamePartNodeOrWorkflowNode } from '@/components/cylc/gscan/
2525
* @property {String} type
2626
* @property {WorkflowGraphQLData} node
2727
*/
28-
2928
/**
3029
* @typedef {TreeNode} WorkflowGScanNode
3130
*/
@@ -85,7 +84,7 @@ function newWorkflowPartNode (id, part) {
8584
*
8685
* @param {WorkflowGraphQLData} workflow
8786
* @param {boolean} hierarchy - whether to parse the Workflow name and create a hierarchy or not
88-
* @returns {TreeNode}
87+
* @returns {TreeNode|null}
8988
*/
9089
function createWorkflowNode (workflow, hierarchy) {
9190
if (!hierarchy) {

0 commit comments

Comments
 (0)