|
1 | 1 | import { useK8sWatchResource } from '@openshift-console/dynamic-plugin-sdk'; |
2 | 2 | import { useMemo } from 'react'; |
3 | | -import { MultiKueueClusterModel, WorkloadModel } from '../../models'; |
4 | | -import { MultiKueueClusterKind, WorkloadKind } from '../../types'; |
| 3 | +import { |
| 4 | + ClusterQueueModel, |
| 5 | + LocalQueueModel, |
| 6 | + MultiKueueClusterModel, |
| 7 | + WorkloadModel, |
| 8 | +} from '../../models'; |
| 9 | +import { |
| 10 | + ClusterQueueKind, |
| 11 | + LocalQueueKind, |
| 12 | + MultiKueueClusterKind, |
| 13 | + WorkloadKind, |
| 14 | +} from '../../types'; |
5 | 15 | import { useMultiClusterProxyService } from './useMultiClusterProxyService'; |
6 | 16 |
|
7 | 17 | /** |
@@ -59,3 +69,49 @@ export const useWorkloads = ( |
59 | 69 |
|
60 | 70 | return useK8sWatchResource<WorkloadKind[]>(watchOptions); |
61 | 71 | }; |
| 72 | + |
| 73 | +export const useClusterQueues = (): [ClusterQueueKind[], boolean, unknown] => { |
| 74 | + const { isHub } = useMultiClusterProxyService({}); |
| 75 | + |
| 76 | + const watchOptions = useMemo( |
| 77 | + () => |
| 78 | + isHub |
| 79 | + ? { |
| 80 | + isList: true, |
| 81 | + groupVersionKind: { |
| 82 | + group: ClusterQueueModel.apiGroup, |
| 83 | + kind: ClusterQueueModel.kind, |
| 84 | + version: ClusterQueueModel.apiVersion, |
| 85 | + }, |
| 86 | + } |
| 87 | + : null, |
| 88 | + [isHub], |
| 89 | + ); |
| 90 | + |
| 91 | + return useK8sWatchResource<ClusterQueueKind[]>(watchOptions); |
| 92 | +}; |
| 93 | + |
| 94 | +export const useLocalQueues = ( |
| 95 | + namespace: string, |
| 96 | +): [LocalQueueKind[], boolean, unknown] => { |
| 97 | + const { isHub } = useMultiClusterProxyService({}); |
| 98 | + |
| 99 | + const watchOptions = useMemo( |
| 100 | + () => |
| 101 | + isHub && namespace |
| 102 | + ? { |
| 103 | + isList: true, |
| 104 | + groupVersionKind: { |
| 105 | + group: LocalQueueModel.apiGroup, |
| 106 | + kind: LocalQueueModel.kind, |
| 107 | + version: LocalQueueModel.apiVersion, |
| 108 | + }, |
| 109 | + ...(namespace !== '-' ? { namespace } : {}), |
| 110 | + namespaced: true, |
| 111 | + } |
| 112 | + : null, |
| 113 | + [isHub, namespace], |
| 114 | + ); |
| 115 | + |
| 116 | + return useK8sWatchResource<LocalQueueKind[]>(watchOptions); |
| 117 | +}; |
0 commit comments