@@ -7,8 +7,13 @@ import {
77 kindToAbbr ,
88 NODE_DIAMETER ,
99} from '@gitops/components/graph/utils' ;
10- import { ApplicationKind , ApplicationResourceStatus } from '@gitops/models/ApplicationModel' ;
10+ import {
11+ ApplicationKind ,
12+ ApplicationModel ,
13+ ApplicationResourceStatus ,
14+ } from '@gitops/models/ApplicationModel' ;
1115import { HealthStatus , SyncStatus } from '@gitops/utils/constants' ;
16+ import { resourcePathFromModel } from '@gitops/utils/utils' ;
1217import { K8sModel } from '@openshift-console/dynamic-plugin-sdk' ;
1318import {
1419 EdgeStyle ,
@@ -247,6 +252,27 @@ const createGroupResourceNode = (
247252 return groupResourceNodeMap ;
248253} ;
249254
255+ export const getResourceMapKey = ( resource : ApplicationResourceStatus ) : string => {
256+ return `${ resource . group } -${ resource . version } -${ resource . kind } -${ resource . namespace } -${ resource . name } ` ;
257+ } ;
258+
259+ export const getResourcePathForResource = (
260+ resource : ApplicationResourceStatus ,
261+ allK8sModels : { [ key : string ] : K8sModel } ,
262+ ) : string => {
263+ if ( resource . kind === ApplicationModel . kind ) {
264+ return (
265+ resourcePathFromModel ( ApplicationModel as K8sModel , resource . name , resource . namespace ) +
266+ '/resources'
267+ ) ;
268+ }
269+ const k8sModel = allK8sModels [ resource . kind ] ;
270+ if ( ! k8sModel ) {
271+ return '' ;
272+ }
273+ return resourcePathFromModel ( k8sModel , resource . name , resource . namespace ) ;
274+ } ;
275+
250276// Application Graph Nodes
251277export const getInitialNodes = (
252278 application : ApplicationKind ,
@@ -255,6 +281,7 @@ export const getInitialNodes = (
255281 showGroupNodes : boolean ,
256282 groupNodeStates : string [ ] ,
257283 resourceNodeLayout : boolean ,
284+ resourcePaths : Map < string , string > ,
258285) => {
259286 // This contains all the nodes we want to add to the graph view
260287 const initialNodes : NodeModel [ ] = [ ] ;
@@ -281,6 +308,8 @@ export const getInitialNodes = (
281308 const key = resource . kind + 's' ;
282309 const resourceGroupExpandState = groupNodeStates . includes ( key ) ;
283310
311+ const resourcePath = resourcePaths . get ( getResourceMapKey ( resource ) ) ;
312+
284313 if ( showGroupNodes && resources . filter ( ( res ) => res . kind === resource . kind ) . length > 1 ) {
285314 groupResourceNodeMap = createGroupResourceNode (
286315 kind ,
@@ -316,6 +345,7 @@ export const getInitialNodes = (
316345 group : resource . group ,
317346 kind : resource . kind ,
318347 resourceNodeLayout : resourceNodeLayout ,
348+ resourcePath : resourcePath ,
319349 version : resource . version ,
320350 namespace : resource . namespace ,
321351 indent : 100 ,
0 commit comments