Skip to content

Commit 55c6198

Browse files
frontend: src: Change apiVersion to apiGroup and fix linting error
1 parent eb71d21 commit 55c6198

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

frontend/src/components/common/Link.tsx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import React from 'react';
2020
import { Link as RouterLink } from 'react-router-dom';
2121
import { formatClusterPathParam, getCluster, getSelectedClusters } from '../../lib/cluster';
2222
import { kubeObjectQueryKey, useEndpoints } from '../../lib/k8s/api/v2/hooks';
23-
import type { KubeObject } from '../../lib/k8s/KubeObject';
23+
import type { KubeObject, KubeObjectClass } from '../../lib/k8s/KubeObject';
2424
import type { RouteURLProps } from '../../lib/router/createRouteURL';
2525
import { createRouteURL } from '../../lib/router/createRouteURL';
26-
import { ResourceClasses } from '../../lib/k8s';
2726
import { useTypedSelector } from '../../redux/hooks';
2827
import { Activity } from '../activity/Activity';
2928
import { canRenderDetails, KubeObjectDetails } from '../resourceMap/details/KubeNodeDetails';
@@ -65,7 +64,7 @@ function KubeObjectLink(props: {
6564

6665
const client = useQueryClient();
6766
const { namespace, name } = kubeObject.metadata;
68-
const { endpoint } = useEndpoints(kubeObject._class().apiEndpoint.apiInfo, kubeObject.cluster);
67+
const { endpoint } = useEndpoints((kubeObject.constructor as KubeObjectClass).apiEndpoint.apiInfo, kubeObject.cluster);
6968

7069
return (
7170
<MuiLink
@@ -147,7 +146,7 @@ export default function Link(props: React.PropsWithChildren<LinkProps | LinkObje
147146

148147
const { tooltip, ...propsRest } = props as LinkObjectProps;
149148

150-
const kind = 'kubeObject' in props ? props.kubeObject?._class().kind : props?.routeName;
149+
const kind = 'kubeObject' in props ? props.kubeObject?.kind : props?.routeName;
151150
const cluster =
152151
'kubeObject' in props && props.kubeObject?.cluster
153152
? props.kubeObject?.cluster
@@ -157,22 +156,21 @@ export default function Link(props: React.PropsWithChildren<LinkProps | LinkObje
157156

158157
if ('kubeObject' in props && props.kubeObject) {
159158
const obj = props.kubeObject;
160-
161-
const standardClass = Object.values(ResourceClasses).find((c: any) => c.kind === obj.kind) as any;
162-
if (standardClass) {
163-
const stdGroup = standardClass.apiGroupName || '';
164-
const objGroup = obj._class().apiGroupName || '';
165-
166-
if (stdGroup !== objGroup) {
167-
matchesStandard = false;
168-
}
159+
const objClass = obj.constructor as KubeObjectClass;
160+
161+
// If the instance's class doesn't define the 'kind' static property matching the instance's kind,
162+
// it implies this is a generic KubeObject (CRD) rather than a specific implementation (e.g. Service, Pod).
163+
// Specific implementations in Headlamp (like Service) are considered "Standard" and should open the drawer.
164+
// Generic objects (like Knative Service) should not open the drawer for a "Service" kind match.
165+
if (objClass.kind !== obj.kind) {
166+
matchesStandard = false;
169167
}
170168
}
171169

172170
const openDrawer =
173171
drawerEnabled && canRenderDetails(kind) && matchesStandard
174172
? () => {
175-
// Object information can be provided throught kubeObject or route parameters
173+
// Object information can be provided through kubeObject or route parameters
176174
const name = 'kubeObject' in props ? props.kubeObject?.getName() : props.params?.name;
177175
const namespace =
178176
'kubeObject' in props ? props.kubeObject?.getNamespace() : props.params?.namespace;

0 commit comments

Comments
 (0)