|
1 | 1 | import * as React from 'react'; |
2 | 2 | import * as _ from 'lodash-es'; |
3 | 3 |
|
| 4 | +import { ApplicationModel } from '@gitops/models/ApplicationModel'; |
| 5 | +import { ApplicationSetModel } from '@gitops/models/ApplicationSetModel'; |
4 | 6 | import { |
| 7 | + K8sModel, |
5 | 8 | K8sResourceKind, |
6 | 9 | OwnerReference, |
7 | 10 | ResourceLink, |
8 | 11 | } from '@openshift-console/dynamic-plugin-sdk'; |
| 12 | +import { getK8sModel } from '@openshift-console/dynamic-plugin-sdk/lib/utils/k8s/hooks/useK8sModel'; |
9 | 13 | import { Tooltip } from '@patternfly/react-core'; |
10 | 14 |
|
11 | 15 | import { useGitOpsTranslation } from '../../hooks/useGitOpsTranslation'; |
12 | 16 |
|
| 17 | +const getModel = (ownerRef: OwnerReference): K8sModel | null => { |
| 18 | + // Try to get the model from the console's registry first |
| 19 | + const model = getK8sModel(ownerRef.apiVersion); |
| 20 | + if (model) { |
| 21 | + return model; |
| 22 | + } |
| 23 | + |
| 24 | + // Fallback for Argo CD resources |
| 25 | + const argoApiGroup = 'argoproj.io'; |
| 26 | + if (ownerRef.apiVersion.includes(argoApiGroup)) { |
| 27 | + if (ownerRef.kind === 'ApplicationSet') { |
| 28 | + return ApplicationSetModel; |
| 29 | + } else if (ownerRef.kind === 'Application') { |
| 30 | + return ApplicationModel; |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + return null; |
| 35 | +}; |
| 36 | + |
13 | 37 | export const OwnerReferences: React.FC<OwnerReferencesProps> = ({ resource }) => { |
14 | 38 | const { t } = useGitOpsTranslation(); |
15 | 39 | const owners = (_.get(resource.metadata, 'ownerReferences') || []).map((o: OwnerReference) => { |
16 | | - if (o.kind === 'ApplicationSet') { |
| 40 | + const model = getModel(o); |
| 41 | + |
| 42 | + if (!model) { |
| 43 | + // Fallback to simple ResourceLink for unknown types |
17 | 44 | return ( |
18 | | - <Tooltip key={o.uid} content={<div>View ApplicationSet</div>} position="top"> |
19 | | - <ResourceLink |
20 | | - namespace={resource.metadata.namespace} |
21 | | - groupVersionKind={{ |
22 | | - group: 'argoproj.io', |
23 | | - version: 'v1alpha1', |
24 | | - kind: 'ApplicationSet', |
25 | | - }} |
26 | | - name={o.name} |
27 | | - /> |
28 | | - </Tooltip> |
| 45 | + <ResourceLink |
| 46 | + key={o.uid} |
| 47 | + kind={o.kind} |
| 48 | + name={o.name} |
| 49 | + namespace={resource.metadata.namespace} |
| 50 | + /> |
29 | 51 | ); |
30 | 52 | } |
31 | 53 |
|
32 | 54 | return ( |
33 | | - <ResourceLink |
34 | | - key={o.uid} |
35 | | - kind={o.kind} |
36 | | - name={o.name} |
37 | | - namespace={resource.metadata.namespace} |
38 | | - /> |
| 55 | + <Tooltip key={o.uid} content={<div>View {model.kind}</div>} position="top"> |
| 56 | + <ResourceLink |
| 57 | + namespace={resource.metadata.namespace} |
| 58 | + groupVersionKind={{ |
| 59 | + group: model.apiGroup, |
| 60 | + version: model.apiVersion, |
| 61 | + kind: model.kind, |
| 62 | + }} |
| 63 | + name={o.name} |
| 64 | + /> |
| 65 | + </Tooltip> |
39 | 66 | ); |
40 | 67 | }); |
41 | 68 | return owners.length ? ( |
|
0 commit comments