From 27f4ef49793daf74504d68ce31b14c5dffd5370a Mon Sep 17 00:00:00 2001 From: Ankur Sinha Date: Wed, 25 Nov 2026 14:06:26 +0530 Subject: [PATCH] feat: add LocalQueue list page - Add namespace-scoped LocalQueues tab with filtering and workload metrics. - Add create entry and delete action for each LQ. Signed-off-by: Ankur Sinha --- console-extensions.json | 13 ++ .../en/plugin__pipelines-console-plugin.json | 4 + package.json | 3 +- .../__tests__/useMultiKueueResources.spec.ts | 61 +++++ .../hooks/useMultiKueueResources.ts | 23 +- src/components/localqueues/LocalQueueRow.tsx | 70 ++++++ .../localqueues/LocalQueuesList.tsx | 49 ++++ .../__tests__/LocalQueuesList.spec.tsx | 221 ++++++++++++++++++ .../localqueues/useLocalQueuesColumns.ts | 79 +++++++ src/components/localqueues/utils.ts | 13 ++ .../pipelines-list/PipelinesTabbedPage.tsx | 11 + .../__tests__/PipelinesTabbedPage.spec.tsx | 10 +- src/utils/localQueue-actions-provider.ts | 43 ++++ 13 files changed, 588 insertions(+), 12 deletions(-) create mode 100644 src/components/localqueues/LocalQueueRow.tsx create mode 100644 src/components/localqueues/LocalQueuesList.tsx create mode 100644 src/components/localqueues/__tests__/LocalQueuesList.spec.tsx create mode 100644 src/components/localqueues/useLocalQueuesColumns.ts create mode 100644 src/components/localqueues/utils.ts create mode 100644 src/utils/localQueue-actions-provider.ts diff --git a/console-extensions.json b/console-extensions.json index a94abcb3..5843b666 100644 --- a/console-extensions.json +++ b/console-extensions.json @@ -1612,6 +1612,19 @@ } } }, + { + "type": "console.action/resource-provider", + "properties": { + "model": { + "group": "kueue.x-k8s.io", + "version": "v1beta2", + "kind": "LocalQueue" + }, + "provider": { + "$codeRef": "localQueueActionsProvider.useLocalQueueActionsProvider" + } + } + }, { "type": "console.action/resource-provider", "properties": { diff --git a/locales/en/plugin__pipelines-console-plugin.json b/locales/en/plugin__pipelines-console-plugin.json index a30a68f5..24dd3c87 100644 --- a/locales/en/plugin__pipelines-console-plugin.json +++ b/locales/en/plugin__pipelines-console-plugin.json @@ -53,6 +53,7 @@ "Add when expression": "Add when expression", "Add workspace": "Add workspace", "Adding this task may take a few moments.": "Adding this task may take a few moments.", + "Admitted Workloads": "Admitted Workloads", "Advanced options": "Advanced options", "All": "All", "All Clusters": "All Clusters", @@ -303,6 +304,7 @@ "Last run duration": "Last run duration", "Last run status": "Last run status", "Last run time": "Last run time", + "Last Updated": "Last Updated", "Last week": "Last week", "Last year": "Last year", "Learn more": "Learn more", @@ -312,6 +314,7 @@ "Loading clusters": "Loading clusters", "Loading events...": "Loading events...", "Local Queue": "Local Queue", + "LocalQueues": "LocalQueues", "Log snippet": "Log snippet", "Logs": "Logs", "Low": "Low", @@ -401,6 +404,7 @@ "Password or token for Git authentication. Required if a ca.crt or .gitconfig file is not specified.": "Password or token for Git authentication. Required if a ca.crt or .gitconfig file is not specified.", "Pause event streaming": "Pause event streaming", "Pending": "Pending", + "Pending Workloads": "Pending Workloads", "Per Pipeline": "Per Pipeline", "Per Repository": "Per Repository", "Permissions to the mounted drive": "Permissions to the mounted drive", diff --git a/package.json b/package.json index bb1a84b0..b2bc5a57 100644 --- a/package.json +++ b/package.json @@ -166,7 +166,8 @@ "pipelineRunActionsProvider": "./utils/pipelineRun-actions-provider.tsx", "taskRunActionsProvider": "./utils/taskRun-actions-provider.tsx", "approvalTaskActionsProvider": "./utils/approvalTask-actions-provider.tsx", - "clusterQueueActionsProvider": "./utils/clusterQueue-actions-provider.ts" + "clusterQueueActionsProvider": "./utils/clusterQueue-actions-provider.ts", + "localQueueActionsProvider": "./utils/localQueue-actions-provider.ts" }, "dependencies": { "@console/pluginAPI": ">=4.22" diff --git a/src/components/hooks/__tests__/useMultiKueueResources.spec.ts b/src/components/hooks/__tests__/useMultiKueueResources.spec.ts index eecefceb..cc4497b2 100644 --- a/src/components/hooks/__tests__/useMultiKueueResources.spec.ts +++ b/src/components/hooks/__tests__/useMultiKueueResources.spec.ts @@ -5,12 +5,14 @@ import { import { WORKLOAD_KUEUE_UID_LABEL } from '../../../consts'; import { ClusterQueueModel, + LocalQueueModel, MultiKueueClusterModel, WorkloadModel, } from '../../../models'; import { testHook } from '../../../test-data/utils/hooks-utils'; import { ClusterQueueKind, + LocalQueueKind, MultiKueueClusterKind, PipelineRunKind, } from '../../../types'; @@ -20,6 +22,7 @@ import { useClusterQueues, useGetClusterQueue, useGetMultiKueueCluster, + useLocalQueues, useWorkloads, } from '../useMultiKueueResources'; @@ -48,6 +51,12 @@ const clusterQueueGVK = { kind: ClusterQueueModel.kind, }; +const localQueueGVK = { + group: LocalQueueModel.apiGroup, + version: LocalQueueModel.apiVersion, + kind: LocalQueueModel.kind, +}; + const multiKueueClusterGVK = { group: MultiKueueClusterModel.apiGroup, version: MultiKueueClusterModel.apiVersion, @@ -146,6 +155,10 @@ describe('useGetClusterQueue', () => { }); describe('useClusterQueues', () => { + beforeEach(() => { + useMultiClusterProxyServiceMock.mockReturnValue({ isHub: true }); + }); + it('should watch ClusterQueues', () => { const clusterQueues: ClusterQueueKind[] = []; useK8sWatchResourceMock.mockReturnValue([clusterQueues, true, null]); @@ -158,6 +171,54 @@ describe('useClusterQueues', () => { }); expect(result.current).toEqual([clusterQueues, true, null]); }); + + it('should skip the watch on a non-hub cluster', () => { + useMultiClusterProxyServiceMock.mockReturnValue({ isHub: false }); + + testHook(() => useClusterQueues()); + + expect(useK8sWatchResourceMock).toHaveBeenCalledWith(null); + }); +}); + +describe('useLocalQueues', () => { + beforeEach(() => { + useK8sWatchResourceMock.mockReturnValue([[], true, null]); + useMultiClusterProxyServiceMock.mockReturnValue({ isHub: true }); + }); + + it('should watch LocalQueues in the requested namespace', () => { + const localQueues: LocalQueueKind[] = []; + useK8sWatchResourceMock.mockReturnValue([localQueues, true, null]); + + const { result } = testHook(() => useLocalQueues('test-namespace')); + + expect(useK8sWatchResourceMock).toHaveBeenCalledWith({ + isList: true, + groupVersionKind: localQueueGVK, + namespace: 'test-namespace', + namespaced: true, + }); + expect(result.current).toEqual([localQueues, true, null]); + }); + + it('should watch LocalQueues across namespaces for the all-namespaces route', () => { + testHook(() => useLocalQueues('-')); + + expect(useK8sWatchResourceMock).toHaveBeenCalledWith({ + isList: true, + groupVersionKind: localQueueGVK, + namespaced: true, + }); + }); + + it('should skip the watch on a non-hub cluster', () => { + useMultiClusterProxyServiceMock.mockReturnValue({ isHub: false }); + + testHook(() => useLocalQueues('test-namespace')); + + expect(useK8sWatchResourceMock).toHaveBeenCalledWith(null); + }); }); describe('useWorkloads', () => { diff --git a/src/components/hooks/useMultiKueueResources.ts b/src/components/hooks/useMultiKueueResources.ts index ee0d4caf..7c17e010 100644 --- a/src/components/hooks/useMultiKueueResources.ts +++ b/src/components/hooks/useMultiKueueResources.ts @@ -104,16 +104,21 @@ export const useWorkloads = ( }; export const useClusterQueues = (): [ClusterQueueKind[], boolean, unknown] => { + const { isHub } = useMultiClusterProxyService({}); + const watchOptions = useMemo( - () => ({ - isList: true, - groupVersionKind: { - group: ClusterQueueModel.apiGroup, - kind: ClusterQueueModel.kind, - version: ClusterQueueModel.apiVersion, - }, - }), - [], + () => + isHub + ? { + isList: true, + groupVersionKind: { + group: ClusterQueueModel.apiGroup, + kind: ClusterQueueModel.kind, + version: ClusterQueueModel.apiVersion, + }, + } + : null, + [isHub], ); return useK8sWatchResource(watchOptions); diff --git a/src/components/localqueues/LocalQueueRow.tsx b/src/components/localqueues/LocalQueueRow.tsx new file mode 100644 index 00000000..68356c8e --- /dev/null +++ b/src/components/localqueues/LocalQueueRow.tsx @@ -0,0 +1,70 @@ +import { + getGroupVersionKindForModel, + ResourceLink, + Timestamp, +} from '@openshift-console/dynamic-plugin-sdk'; +import { + actionsCellProps, + getNameCellProps, + LazyActionMenu, +} from '@openshift-console/dynamic-plugin-sdk-internal'; +import { GetDataViewRows } from '@openshift-console/dynamic-plugin-sdk-internal/lib/api/internal-types'; +import { LocalQueueModel } from '../../models'; +import { LocalQueueKind } from '../../types'; +import { getReferenceForModel } from '../pipelines-overview/utils'; +import { localQueueColumnIds } from './useLocalQueuesColumns'; +import { getLastUpdatedTimestamp } from './utils'; + +export const getLocalQueueDataViewRows: GetDataViewRows = ( + data, + columns, +) => + data.map(({ obj }) => { + const admitted = obj.status?.admittedWorkloads ?? 0; + const pending = obj.status?.pendingWorkloads ?? 0; + const rowCells = { + [localQueueColumnIds.name]: { + cell: ( + + ), + props: { + ...getNameCellProps('localqueues-list'), + modifier: 'nowrap', + }, + }, + [localQueueColumnIds.namespace]: { + cell: obj.metadata.namespace, + props: { modifier: 'nowrap' }, + }, + [localQueueColumnIds.admittedWorkloads]: { + cell: admitted, + props: { modifier: 'nowrap' }, + }, + [localQueueColumnIds.pendingWorkloads]: { + cell: pending, + props: { modifier: 'nowrap' }, + }, + [localQueueColumnIds.lastUpdated]: { + cell: , + props: { modifier: 'nowrap' }, + }, + [localQueueColumnIds.actions]: { + cell: ( + + ), + props: actionsCellProps, + }, + }; + + return columns.map(({ id }) => ({ + id, + cell: rowCells[id]?.cell, + props: rowCells[id]?.props, + })); + }); diff --git a/src/components/localqueues/LocalQueuesList.tsx b/src/components/localqueues/LocalQueuesList.tsx new file mode 100644 index 00000000..9d9dca43 --- /dev/null +++ b/src/components/localqueues/LocalQueuesList.tsx @@ -0,0 +1,49 @@ +import { ListPageBody } from '@openshift-console/dynamic-plugin-sdk'; +import { ConsoleDataView } from '@openshift-console/dynamic-plugin-sdk-internal'; +import type { FC } from 'react'; +import { useTranslation } from 'react-i18next'; +import { useParams } from 'react-router'; +import { LocalQueueKind } from '../../types'; +import { DataViewFilterToolbar } from '../common/DataViewFilterToolbar'; +import { useDataViewFilter } from '../hooks/useDataViewFilter'; +import { useLocalQueues } from '../hooks/useMultiKueueResources'; +import { getLocalQueueDataViewRows } from './LocalQueueRow'; +import useLocalQueuesColumns from './useLocalQueuesColumns'; + +const LocalQueuesList: FC = () => { + const { t } = useTranslation('plugin__pipelines-console-plugin'); + const { ns } = useParams(); + const namespace = ns ?? '-'; + const columns = useLocalQueuesColumns(ns); + const [localQueues, loaded, loadError] = useLocalQueues(namespace); + const { filterValues, onFilterChange, onClearAll, filteredData } = + useDataViewFilter({ + data: localQueues || [], + options: { + getName: (localQueue) => localQueue.metadata.name, + }, + }); + + return ( + + + + label={t('LocalQueues')} + columns={columns} + data={filteredData} + loaded={loaded} + loadError={loadError} + getDataViewRows={getLocalQueueDataViewRows} + hideColumnManagement + hideNameLabelFilters + /> + + ); +}; + +export default LocalQueuesList; diff --git a/src/components/localqueues/__tests__/LocalQueuesList.spec.tsx b/src/components/localqueues/__tests__/LocalQueuesList.spec.tsx new file mode 100644 index 00000000..58d395b3 --- /dev/null +++ b/src/components/localqueues/__tests__/LocalQueuesList.spec.tsx @@ -0,0 +1,221 @@ +import { fireEvent, render, screen } from '@testing-library/react'; +import { SortByDirection } from '@patternfly/react-table'; +import { useState } from 'react'; +import { ConsoleDataView } from '@openshift-console/dynamic-plugin-sdk-internal'; +import { LocalQueueKind } from '../../../types'; +import { useDataViewFilter } from '../../hooks/useDataViewFilter'; +import { useLocalQueues } from '../../hooks/useMultiKueueResources'; +import LocalQueuesList from '../LocalQueuesList'; + +let mockNamespace: string | undefined = 'test-namespace'; + +jest.mock('@openshift-console/dynamic-plugin-sdk', () => ({ + ListPageBody: ({ children }) =>
{children}
, + getGroupVersionKindForModel: jest.fn(), + ResourceLink: ({ name, namespace }) => ( + {name} + ), + Timestamp: ({ timestamp }) => , +})); + +jest.mock('@openshift-console/dynamic-plugin-sdk-internal', () => ({ + ConsoleDataView: jest.fn(({ columns, data, getDataViewRows, loaded }) => { + if (!loaded) return
; + if (data.length === 0) return
; + + const rows = getDataViewRows( + data.map((obj) => ({ obj })), + columns, + ); + + return ( +
+ {columns.map(({ id, title }) => ( +
+ {title} +
+ ))} + {rows.flatMap((row, rowIndex) => + row.map(({ id, cell }, cellIndex) => ( +
{cell}
+ )), + )} +
+ ); + }), + actionsCellProps: {}, + getNameCellProps: jest.fn(() => ({})), + LazyActionMenu: () => null, +})); + +jest.mock('react-router', () => ({ + useParams: () => ({ ns: mockNamespace }), +})); + +jest.mock('../../common/DataViewFilterToolbar', () => ({ + DataViewFilterToolbar: ({ filterValues, onFilterChange, children }) => ( + <> + onFilterChange('name', event.target.value)} + /> + {children} + + ), +})); + +jest.mock('../../hooks/useDataViewFilter', () => ({ + useDataViewFilter: jest.fn(), +})); + +jest.mock('../../hooks/useMultiKueueResources', () => ({ + useLocalQueues: jest.fn(), +})); + +const useLocalQueuesMock = useLocalQueues as jest.Mock; +const useDataViewFilterMock = useDataViewFilter as jest.Mock; + +const localQueues: LocalQueueKind[] = [ + { + apiVersion: 'kueue.x-k8s.io/v1beta2', + kind: 'LocalQueue', + metadata: { + name: 'gpu-local-queue', + namespace: 'test-namespace', + creationTimestamp: '2026-09-08T09:10:27Z', + managedFields: [ + { time: '2026-09-08T09:10:27Z' }, + { time: '2026-09-08T09:39:25Z' }, + ], + }, + spec: { clusterQueue: 'gpu-cluster-queue' }, + status: { admittedWorkloads: 2, pendingWorkloads: 1 }, + }, + { + apiVersion: 'kueue.x-k8s.io/v1beta2', + kind: 'LocalQueue', + metadata: { + name: 'cpu-local-queue', + namespace: 'test-namespace', + creationTimestamp: '2026-09-07T09:10:27Z', + }, + }, +]; + +describe('LocalQueuesList', () => { + beforeEach(() => { + mockNamespace = 'test-namespace'; + useLocalQueuesMock.mockReturnValue([localQueues, true, undefined]); + useDataViewFilterMock.mockImplementation(({ data, options }) => { + const [name, setName] = useState(''); + const filteredData = data.filter((localQueue) => + options.getName(localQueue).toLowerCase().includes(name.toLowerCase()), + ); + + return { + filterValues: { name, labels: [] }, + onFilterChange: (_key: string, value: string) => setName(value), + onClearAll: jest.fn(), + filteredData, + }; + }); + }); + + it('renders the expected LocalQueue row values', () => { + render(); + + expect(screen.queryByTestId('column-namespace')).toBeNull(); + expect(screen.getByRole('link', { name: 'gpu-local-queue' })).toBeTruthy(); + expect(screen.getByText('2')).toBeTruthy(); + expect(screen.getByText('1')).toBeTruthy(); + expect(screen.getByText('2026-09-08T09:39:25Z')).toBeTruthy(); + }); + + it('filters LocalQueues by name', () => { + render(); + + const search = screen.getByLabelText('Filter by name'); + fireEvent.change(search, { target: { value: 'gpu' } }); + expect(screen.getByText('gpu-local-queue')).toBeTruthy(); + expect(screen.queryByText('cpu-local-queue')).toBeNull(); + }); + + it('shows Namespace when listing LocalQueues across all projects', () => { + mockNamespace = undefined; + const localQueuesAcrossNamespaces = localQueues.map( + (localQueue, index) => ({ + ...localQueue, + metadata: { + ...localQueue.metadata, + namespace: index === 0 ? 'team-a' : 'team-b', + }, + }), + ); + useLocalQueuesMock.mockReturnValue([ + localQueuesAcrossNamespaces, + true, + undefined, + ]); + + render(); + + expect(screen.getByTestId('column-namespace')).toBeTruthy(); + expect(screen.getByText('team-a')).toBeTruthy(); + expect(screen.getByText('team-b')).toBeTruthy(); + expect(useLocalQueuesMock).toHaveBeenLastCalledWith('-'); + }); + + it('renders loading and empty states', () => { + useLocalQueuesMock.mockReturnValue([[], false, undefined]); + const { rerender } = render(); + + expect(screen.getByTestId('loading-state')).toBeTruthy(); + + useLocalQueuesMock.mockReturnValue([[], true, undefined]); + rerender(); + + expect(screen.getByTestId('empty-state')).toBeTruthy(); + }); + + it('sorts by the displayed last updated timestamp', () => { + render(); + + const consoleDataViewMock = ConsoleDataView as jest.Mock; + const [{ columns }] = + consoleDataViewMock.mock.calls[consoleDataViewMock.mock.calls.length - 1]; + const lastUpdatedColumn = columns.find( + (column) => column.id === 'last-updated', + ); + if (typeof lastUpdatedColumn?.sort !== 'function') { + throw new Error('Expected Last Updated to have a custom sort function'); + } + + const olderQueueWithRecentUpdate: LocalQueueKind = { + ...localQueues[0], + metadata: { + ...localQueues[0].metadata, + name: 'older-queue', + creationTimestamp: '2026-09-01T09:10:27Z', + managedFields: [{ time: '2026-09-10T09:39:25Z' }], + }, + }; + const newerQueueWithoutUpdate: LocalQueueKind = { + ...localQueues[1], + metadata: { + ...localQueues[1].metadata, + name: 'newer-queue', + creationTimestamp: '2026-09-08T09:10:27Z', + }, + }; + const sortedQueues = lastUpdatedColumn.sort( + [newerQueueWithoutUpdate, olderQueueWithRecentUpdate], + SortByDirection.desc, + ); + + expect(sortedQueues.map((queue) => queue.metadata.name)).toEqual([ + 'older-queue', + 'newer-queue', + ]); + }); +}); diff --git a/src/components/localqueues/useLocalQueuesColumns.ts b/src/components/localqueues/useLocalQueuesColumns.ts new file mode 100644 index 00000000..27ed8450 --- /dev/null +++ b/src/components/localqueues/useLocalQueuesColumns.ts @@ -0,0 +1,79 @@ +import { TableColumn } from '@openshift-console/dynamic-plugin-sdk'; +import { SortByDirection } from '@patternfly/react-table'; +import { useTranslation } from 'react-i18next'; +import { LocalQueueKind } from '../../types'; +import { getLastUpdatedTimestamp } from './utils'; + +export const localQueueColumnIds = { + name: 'name', + namespace: 'namespace', + admittedWorkloads: 'admitted-workloads', + pendingWorkloads: 'pending-workloads', + lastUpdated: 'last-updated', + actions: 'actions', +}; + +const useLocalQueuesColumns = ( + namespace?: string, +): TableColumn[] => { + const { t } = useTranslation('plugin__pipelines-console-plugin'); + const isAllNamespaces = !namespace; + + return [ + { + id: localQueueColumnIds.name, + title: t('Name'), + sort: 'metadata.name', + props: { + width: isAllNamespaces ? 25 : 35, + isStickyColumn: true, + modifier: 'nowrap', + }, + }, + ...(isAllNamespaces + ? [ + { + id: localQueueColumnIds.namespace, + title: t('Namespace'), + sort: 'metadata.namespace', + props: { width: 15, modifier: 'nowrap' }, + }, + ] + : []), + { + id: localQueueColumnIds.admittedWorkloads, + title: t('Admitted Workloads'), + sort: 'status.admittedWorkloads', + props: { width: 20, modifier: 'nowrap' }, + }, + { + id: localQueueColumnIds.pendingWorkloads, + title: t('Pending Workloads'), + sort: 'status.pendingWorkloads', + props: { width: 20, modifier: 'nowrap' }, + }, + { + id: localQueueColumnIds.lastUpdated, + title: t('Last Updated'), + sort: (data: LocalQueueKind[], direction: SortByDirection) => + [...data].sort((a, b) => { + const aTimestamp = Date.parse(getLastUpdatedTimestamp(a)) || 0; + const bTimestamp = Date.parse(getLastUpdatedTimestamp(b)) || 0; + const comparison = aTimestamp - bTimestamp; + + return direction === SortByDirection.asc ? comparison : -comparison; + }), + props: { + width: isAllNamespaces ? 15 : 20, + modifier: 'nowrap', + }, + }, + { + id: localQueueColumnIds.actions, + title: '', + props: { width: 5 }, + }, + ]; +}; + +export default useLocalQueuesColumns; diff --git a/src/components/localqueues/utils.ts b/src/components/localqueues/utils.ts new file mode 100644 index 00000000..c2d8d364 --- /dev/null +++ b/src/components/localqueues/utils.ts @@ -0,0 +1,13 @@ +import { LocalQueueKind } from '../../types'; + +export const getLastUpdatedTimestamp = (queue: LocalQueueKind): string => { + let lastUpdatedTimestamp = queue.metadata.creationTimestamp ?? ''; + + queue.metadata.managedFields?.forEach(({ time }) => { + if (time && time > lastUpdatedTimestamp) { + lastUpdatedTimestamp = time; + } + }); + + return lastUpdatedTimestamp; +}; diff --git a/src/components/pipelines-list/PipelinesTabbedPage.tsx b/src/components/pipelines-list/PipelinesTabbedPage.tsx index a2a4dc0f..35805464 100644 --- a/src/components/pipelines-list/PipelinesTabbedPage.tsx +++ b/src/components/pipelines-list/PipelinesTabbedPage.tsx @@ -8,6 +8,7 @@ import { import { ApprovalTaskModel, ClusterQueueModel, + LocalQueueModel, PipelineModel, PipelineRunModel, RepositoryModel, @@ -34,6 +35,7 @@ import { useK8sGet } from '../hooks/use-k8sGet-hook'; import { SecretKind } from '../../types'; import { PAC_SECRET_NAME } from '../pac/const'; import ClusterQueuesList from '../clusterqueues/ClusterQueuesList'; +import LocalQueuesList from '../localqueues/LocalQueuesList'; import { useMultiClusterProxyService } from '../hooks/useMultiClusterProxyService'; import { getReferenceForModel } from '../pipelines-overview/utils'; @@ -68,6 +70,9 @@ export const PageContents: FC = ({ }, ...(isHub ? { + localQueue: { + model: LocalQueueModel, + }, clusterQueue: { model: ClusterQueueModel, // TODO: Update this path when the ClusterQueue create page is available. @@ -102,6 +107,12 @@ export const PageContents: FC = ({ : []), ...(isHub ? [ + { + href: 'localqueues', + // t(LocalQueueModel.labelPluralKey) + name: LocalQueueModel.labelPluralKey, + component: LocalQueuesList, + }, { href: 'clusterqueues', // t(ClusterQueueModel.labelPluralKey) diff --git a/src/components/pipelines-list/__tests__/PipelinesTabbedPage.spec.tsx b/src/components/pipelines-list/__tests__/PipelinesTabbedPage.spec.tsx index eac4ba03..ac64ff68 100644 --- a/src/components/pipelines-list/__tests__/PipelinesTabbedPage.spec.tsx +++ b/src/components/pipelines-list/__tests__/PipelinesTabbedPage.spec.tsx @@ -21,6 +21,8 @@ jest.mock('../../approval-tasks', () => ({ jest.mock('../../clusterqueues/ClusterQueuesList', () => () => null); +jest.mock('../../localqueues/LocalQueuesList', () => () => null); + jest.mock('../../pipelineRuns-list', () => ({ PipelineRunsList: () => null, })); @@ -59,21 +61,25 @@ describe('PipelinesTabbedPage', () => { useFlagMock.mockReturnValue(false); }); - it('shows the ClusterQueues tab on a hub cluster', () => { + it('shows the LocalQueues and ClusterQueues tabs on a hub cluster', () => { useMultiClusterProxyServiceMock.mockReturnValue({ isHub: true }); render(); + expect(screen.getByTestId('tab-localqueues')).toBeTruthy(); expect(screen.getByTestId('tab-clusterqueues')).toBeTruthy(); + expect(screen.getByTestId('create-localQueue')).toBeTruthy(); expect(screen.getByTestId('create-clusterQueue')).toBeTruthy(); }); - it('hides the ClusterQueues tab on a non-hub cluster', () => { + it('hides the LocalQueues and ClusterQueues tabs on a non-hub cluster', () => { useMultiClusterProxyServiceMock.mockReturnValue({ isHub: false }); render(); + expect(screen.queryByTestId('tab-localqueues')).toBeNull(); expect(screen.queryByTestId('tab-clusterqueues')).toBeNull(); + expect(screen.queryByTestId('create-localQueue')).toBeNull(); expect(screen.queryByTestId('create-clusterQueue')).toBeNull(); }); }); diff --git a/src/utils/localQueue-actions-provider.ts b/src/utils/localQueue-actions-provider.ts new file mode 100644 index 00000000..dab7fc18 --- /dev/null +++ b/src/utils/localQueue-actions-provider.ts @@ -0,0 +1,43 @@ +import { + Action, + useAccessReview, + useDeleteModal, +} from '@openshift-console/dynamic-plugin-sdk'; +import { useMemo } from 'react'; +import { useTranslation } from 'react-i18next'; +import { LocalQueueModel } from '../models'; +import { LocalQueueKind } from '../types'; + +export const useLocalQueueActionsProvider = (resource: LocalQueueKind) => { + const { t } = useTranslation('plugin__pipelines-console-plugin'); + const launchDeleteModal = useDeleteModal(resource); + const { name, namespace } = resource.metadata; + + const [canDeleteLocalQueue] = useAccessReview({ + group: LocalQueueModel.apiGroup, + resource: LocalQueueModel.plural, + verb: 'delete', + name, + namespace, + }); + + return useMemo<[Action[], boolean, any]>( + () => [ + [ + { + id: 'delete-localqueue', + label: t('Delete'), + cta: () => launchDeleteModal(), + disabled: !canDeleteLocalQueue, + disabledTooltip: t( + 'Insufficient permissions to delete {{resourceKind}}', + { resourceKind: LocalQueueModel.label }, + ), + }, + ], + true, + undefined, + ], + [canDeleteLocalQueue, launchDeleteModal, t], + ); +};