Skip to content

Commit 651ded4

Browse files
authored
Improve focusing on components in dependency graph (#365)
* Improve focusing on dependency If focusing on a dependency, the graph is now built from a dataset of de-duplicated components, drastically reducing the amount of data needed for the pre-expanded graph. Signed-off-by: RBickert <[email protected]> * Fix circular references not being prevented Signed-off-by: RBickert <[email protected]> Signed-off-by: RBickert <[email protected]>
1 parent 6cc2d5f commit 651ded4

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

src/views/portfolio/projects/ProjectDependencyGraph.vue

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default {
6565
this.loading = true
6666
let url = `${this.$api.BASE_URL}/${this.$api.URL_COMPONENT}/project/${this.project.uuid}/dependencyGraph/${this.$route.params.componentUuid}`
6767
this.axios.get(url).then(response => {
68-
if (response.data && response.data.length > 0){
68+
if (response.data && Object.keys(response.data).length > 0){
6969
this.showCompleteGraph = false
7070
this.notFound = false
7171
this.response = response
@@ -201,37 +201,58 @@ export default {
201201
for(let i = 0; i < dependencies.length; i++) {
202202
let dependency = dependencies[i]
203203
let childNode = this.transformDependencyToOrgTree(dependency);
204-
for (const gatheredKey of treeNode.gatheredKeys){
204+
for (const gatheredKey of treeNode.gatheredKeys) {
205205
childNode.gatheredKeys.push(gatheredKey)
206206
}
207-
childNode.gatheredKeys.push(childNode.label)
208-
if (getChildren === true) {
209-
this.getChildrenFromDependency(childNode, dependency);
207+
if (!childNode.gatheredKeys.some(gatheredKey => gatheredKey === childNode.label)) {
208+
childNode.gatheredKeys.push(childNode.label)
209+
if (getChildren === true) {
210+
this.getChildrenFromDependency(childNode, dependency);
211+
}
212+
children.push(childNode);
210213
}
211-
children.push(childNode);
212214
}
213215
}
214216
return children;
215217
},
216218
transformDependenciesToOrgTreeWithSearchedDependency: function (dependencies, treeNode, onlySearched) {
217-
let children
218-
if (dependencies) {
219-
children = []
220-
for (const dependency of dependencies) {
221-
if (!onlySearched || (onlySearched && (dependency.expandDependencyGraph || dependency.uuid === this.$route.params.componentUuid))) {
222-
let childNode = this.transformDependencyToOrgTreeWithSearchedDependency(dependency)
219+
let children = []
220+
let directDependencies = JSON.parse(this.project.directDependencies)
221+
directDependencies.forEach((directDependency) => {
222+
if (dependencies[directDependency.uuid] && (!onlySearched || (onlySearched && (dependencies[directDependency.uuid].expandDependencyGraph || directDependency.uuid === this.$route.params.componentUuid)))) {
223+
let childNode = this.transformDependencyToOrgTreeWithSearchedDependency(dependencies[directDependency.uuid])
224+
childNode.gatheredKeys.push(childNode.label)
225+
children.push(childNode)
226+
if (onlySearched && directDependency.uuid === this.$route.params.componentUuid) {
227+
this.$set(childNode, 'children', this.getChildrenFromDependencyWithSearchedDependency(dependencies, dependencies[directDependency.uuid], childNode, false))
228+
} else {
229+
this.$set(childNode, 'children', this.getChildrenFromDependencyWithSearchedDependency(dependencies, dependencies[directDependency.uuid], childNode, onlySearched))
230+
}
231+
}
232+
})
233+
return children
234+
},
235+
getChildrenFromDependencyWithSearchedDependency: function (dependencies, component, treeNode, onlySearched) {
236+
let children = []
237+
if (component.dependencyGraph) {
238+
component.dependencyGraph.forEach((dependency) => {
239+
if (dependencies[dependency] && (!onlySearched || (onlySearched && (dependencies[dependency].expandDependencyGraph || dependency === this.$route.params.componentUuid)))) {
240+
let childNode = this.transformDependencyToOrgTreeWithSearchedDependency(dependencies[dependency])
223241
for (const gatheredKey of treeNode.gatheredKeys) {
224242
childNode.gatheredKeys.push(gatheredKey)
225243
}
226-
childNode.gatheredKeys.push(childNode.label)
227-
children.push(childNode)
228-
if (onlySearched && dependency.uuid === this.$route.params.componentUuid) {
229-
this.$set(childNode, 'children', this.transformDependenciesToOrgTreeWithSearchedDependency(dependency.dependencyGraph, childNode, false))
230-
} else {
231-
this.$set(childNode, 'children', this.transformDependenciesToOrgTreeWithSearchedDependency(dependency.dependencyGraph, childNode, onlySearched))
244+
if (!childNode.gatheredKeys.some(gatheredKey => gatheredKey === childNode.label)) {
245+
childNode.gatheredKeys.push(childNode.label)
246+
children.push(childNode)
247+
if (onlySearched && dependency === this.$route.params.componentUuid) {
248+
this.$set(childNode, 'children', this.getChildrenFromDependencyWithSearchedDependency(dependencies, dependencies[dependency], childNode, false))
249+
this.collapse(childNode.children)
250+
} else {
251+
this.$set(childNode, 'children', this.getChildrenFromDependencyWithSearchedDependency(dependencies, dependencies[dependency], childNode, onlySearched))
252+
}
232253
}
233254
}
234-
}
255+
})
235256
}
236257
return children
237258
},
@@ -265,15 +286,6 @@ export default {
265286
let data = response.data;
266287
if (data && data.directDependencies) {
267288
let jsonObject = JSON.parse(data.directDependencies)
268-
let indexes = []
269-
for (let i = 0; i < jsonObject.length; i++){
270-
if (treeNode.gatheredKeys.some(gatheredKey => gatheredKey === jsonObject[i].purl)){
271-
indexes.unshift(i)
272-
}
273-
}
274-
for (const index of indexes){
275-
jsonObject.splice(index, 1)
276-
}
277289
this.$set(treeNode, 'children', this.transformDependenciesToOrgTree(jsonObject, false, treeNode) )
278290
}
279291
}
@@ -350,6 +362,7 @@ export default {
350362
if (child.expand) {
351363
child.expand = false
352364
}
365+
child.fetchedChildren = false
353366
child.children && _this.collapse(child.children)
354367
})
355368
},

0 commit comments

Comments
 (0)