Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 28 additions & 20 deletions src/components/Graphs/useGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ export function useGraph(colorBy: ColorBy, onYamlClick: (item: ManagedResourceIt
const treeData = useMemo(() => {
if (!managedResources || !providerConfigsList) return [];
const allNodesMap = new Map<string, NodeData>();

managedResources.forEach((group: ManagedResourceGroup) => {
group.items?.forEach((item: ManagedResourceItem) => {
const id = item?.metadata?.name;
const name = item?.metadata?.name;
const apiVersion = item?.apiVersion ?? '';
const id = `${name}-${apiVersion}`;
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ID generation could create collisions when resource names contain hyphens. For example, 'my-resource' with apiVersion 'v1' would have the same ID as 'my' with apiVersion 'resource-v1'. Consider using a different separator like '::' or implement a more robust encoding scheme.

Copilot uses AI. Check for mistakes.

const kind = item?.kind;
const providerConfigName = item?.spec?.providerConfigRef?.name ?? 'unknown';
const providerType = resolveProviderType(providerConfigName, providerConfigsList);
Expand Down Expand Up @@ -135,23 +138,10 @@ export function useGraph(colorBy: ColorBy, onYamlClick: (item: ManagedResourceIt
globalaccountTrustConfigurationRef,
} = extractRefs(item);

const parentId = serviceManagerRef || subaccountRef;
const extraRefs = [
spaceRef,
orgRef,
cloudManagementRef,
directoryRef,
entitlementRef,
globalAccountRef,
orgRoleRef,
spaceMembersRef,
cloudFoundryEnvironmentRef,
kymaEnvironmentRef,
roleCollectionRef,
roleCollectionAssignmentRef,
subaccountTrustConfigurationRef,
globalaccountTrustConfigurationRef,
].filter(Boolean) as string[];
const createReferenceIdWithApiVersion = (referenceName: string | undefined) => {
if (!referenceName) return undefined;
return `${referenceName}-${apiVersion}`;
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reference ID generation uses the current resource's apiVersion for all references, but referenced resources may have different API versions. This could create incorrect references to non-existent nodes in the graph.

Copilot uses AI. Check for mistakes.

};

if (id) {
allNodesMap.set(id, {
Expand All @@ -164,14 +154,32 @@ export function useGraph(colorBy: ColorBy, onYamlClick: (item: ManagedResourceIt
transitionTime: statusCond?.lastTransitionTime ?? '',
statusMessage: statusCond?.reason ?? statusCond?.message ?? '',
fluxName,
parentId,
extraRefs,
parentId: createReferenceIdWithApiVersion(serviceManagerRef || subaccountRef),
extraRefs: [
spaceRef,
orgRef,
cloudManagementRef,
directoryRef,
entitlementRef,
globalAccountRef,
orgRoleRef,
spaceMembersRef,
cloudFoundryEnvironmentRef,
kymaEnvironmentRef,
roleCollectionRef,
roleCollectionAssignmentRef,
subaccountTrustConfigurationRef,
globalaccountTrustConfigurationRef,
]
.map(createReferenceIdWithApiVersion)
.filter(Boolean) as string[],
item,
onYamlClick,
});
}
});
});

return Array.from(allNodesMap.values());
}, [managedResources, providerConfigsList, onYamlClick]);

Expand Down
Loading