-
Couldn't load subscription status.
- Fork 3
fix: Resources on graph based on name AND apiVersion #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
3e68da9
887ede8
55b3ad2
5eb969d
ab25411
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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}`; | ||
| const kind = item?.kind; | ||
| const providerConfigName = item?.spec?.providerConfigRef?.name ?? 'unknown'; | ||
| const providerType = resolveProviderType(providerConfigName, providerConfigsList); | ||
|
|
@@ -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}`; | ||
|
||
| }; | ||
|
|
||
| if (id) { | ||
| allNodesMap.set(id, { | ||
|
|
@@ -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]); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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.