-
Notifications
You must be signed in to change notification settings - Fork 76
OSAC-3599: [UI] Storage Backends list page #130
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
Merged
openshift-merge-bot
merged 12 commits into
osac-project:main
from
ElayAharoni:OSAC-3599-storage-backends-list-page
Aug 11, 2026
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b19e39f
OSAC-3599: add StorageBackendStateLabel component
ElayAharoni a55d728
OSAC-3599: add StorageBackendDeleteConfirmModal
ElayAharoni 9f8cab0
OSAC-3599: add StorageBackendActionsMenu
ElayAharoni 8affdbc
OSAC-3599: add StorageBackendsTable
ElayAharoni 8191b3e
OSAC-3599: add StorageBackendsListPage
ElayAharoni e775cde
OSAC-3599: wire StorageBackendsListPage into StorageManagementPage
ElayAharoni 7b73f00
OSAC-3599: address code review feedback
ElayAharoni f002046
OSAC-3599: Address review feedback — rename State to Status, reorder …
ElayAharoni aea1dc1
OSAC-3599: update hardcoded routes for the new Infrastructure nav path
ElayAharoni 50805a1
OSAC-3599: Address review feedback — sync MenuToggle aria-expanded state
ElayAharoni b6dabb6
OSAC-3599: fix post-rebase drift from OSAC-3604's Tiers list page
ElayAharoni c0f1304
OSAC-3599: Address review feedback — always render Create backend button
ElayAharoni File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
libs/ui-components/src/components/Storage/StorageBackendActionsMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { useState } from 'react'; | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import { Dropdown, DropdownItem, DropdownList, MenuToggle } from '@patternfly/react-core'; | ||
| import { EllipsisVIcon } from '@patternfly/react-icons/dist/esm/icons/ellipsis-v-icon'; | ||
|
|
||
| import type { StorageBackend } from '@osac/types/private'; | ||
|
|
||
| import StorageBackendDeleteConfirmModal from './StorageBackendDeleteConfirmModal'; | ||
| import { useTranslation } from '../../hooks/useTranslation'; | ||
|
|
||
| interface StorageBackendActionsMenuProps { | ||
| backend: StorageBackend; | ||
| } | ||
|
|
||
| const StorageBackendActionsMenu = ({ backend }: StorageBackendActionsMenuProps) => { | ||
| const { t } = useTranslation(); | ||
| const navigate = useNavigate(); | ||
| const [open, setOpen] = useState(false); | ||
| const [deleteOpen, setDeleteOpen] = useState(false); | ||
|
|
||
| const backendName = backend.metadata?.name ?? backend.id; | ||
|
|
||
| return ( | ||
| <> | ||
| {deleteOpen && ( | ||
| <StorageBackendDeleteConfirmModal | ||
| backend={backend} | ||
| onClose={() => setDeleteOpen(false)} | ||
| onSuccess={() => setDeleteOpen(false)} | ||
| /> | ||
| )} | ||
| <Dropdown | ||
| isOpen={open} | ||
| onOpenChange={setOpen} | ||
| toggle={(ref) => ( | ||
| <MenuToggle | ||
| ref={ref} | ||
| variant="plain" | ||
| onClick={() => setOpen((o) => !o)} | ||
| isExpanded={open} | ||
| aria-label={t('Actions for {{name}}', { name: backendName })} | ||
| > | ||
| <EllipsisVIcon /> | ||
| </MenuToggle> | ||
| )} | ||
| popperProps={{ position: 'right' }} | ||
| > | ||
| <DropdownList> | ||
| <DropdownItem | ||
| onClick={() => navigate(`/admin/infrastructure/storage/backends/${backend.id}/edit`)} | ||
| > | ||
| {t('Edit')} | ||
| </DropdownItem> | ||
| <DropdownItem | ||
| value="delete" | ||
| onClick={() => { | ||
| setDeleteOpen(true); | ||
| setOpen(false); | ||
| }} | ||
| > | ||
| {t('Delete')} | ||
| </DropdownItem> | ||
| </DropdownList> | ||
| </Dropdown> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default StorageBackendActionsMenu; | ||
107 changes: 107 additions & 0 deletions
107
libs/ui-components/src/components/Storage/StorageBackendDeleteConfirmModal.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { render, screen, waitFor } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
|
||
| import StorageBackendDeleteConfirmModal from './StorageBackendDeleteConfirmModal'; | ||
| import * as storageBackendsApi from '../../api/v1/private/storage-backends'; | ||
|
|
||
| vi.mock('../../api/v1/private/storage-backends', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof storageBackendsApi>(); | ||
| return { | ||
| ...actual, | ||
| useDeleteStorageBackend: vi.fn(), | ||
| }; | ||
| }); | ||
|
|
||
| const mockBackend = { | ||
| id: 'backend-1', | ||
| metadata: { name: 'vast-prod' }, | ||
| spec: { provider: 'vast', endpoint: 'vast.example.com' }, | ||
| }; | ||
|
|
||
| describe('StorageBackendDeleteConfirmModal', () => { | ||
| const mutate = vi.fn(); | ||
| const reset = vi.fn(); | ||
|
|
||
| beforeEach(() => { | ||
| vi.resetAllMocks(); | ||
| vi.mocked(storageBackendsApi.useDeleteStorageBackend).mockReturnValue({ | ||
| mutate, | ||
| reset, | ||
| isPending: false, | ||
| error: null, | ||
| } as unknown as ReturnType<typeof storageBackendsApi.useDeleteStorageBackend>); | ||
| }); | ||
|
|
||
| it('deletes the backend and calls onSuccess', async () => { | ||
| const user = userEvent.setup(); | ||
| mutate.mockImplementation((_id: string, options?: { onSuccess?: () => void }) => { | ||
| options?.onSuccess?.(); | ||
| return Promise.resolve(undefined); | ||
| }); | ||
| const onSuccess = vi.fn(); | ||
|
|
||
| render( | ||
| <StorageBackendDeleteConfirmModal | ||
| backend={mockBackend as never} | ||
| onClose={vi.fn()} | ||
| onSuccess={onSuccess} | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByRole('dialog')).toBeInTheDocument(); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /^Delete$/i })); | ||
|
|
||
| await waitFor(() => { | ||
| expect(mutate).toHaveBeenCalledWith('backend-1', { | ||
| onSuccess: expect.any(Function) as unknown, | ||
| }); | ||
| expect(onSuccess).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
|
|
||
| it('shows the FAILED_PRECONDITION error verbatim and does not call onSuccess', async () => { | ||
| const user = userEvent.setup(); | ||
| vi.mocked(storageBackendsApi.useDeleteStorageBackend).mockReturnValue({ | ||
| mutate, | ||
| reset, | ||
| isPending: false, | ||
| error: new Error('[failed_precondition] backend is referenced by an active storage tier'), | ||
| } as unknown as ReturnType<typeof storageBackendsApi.useDeleteStorageBackend>); | ||
| const onSuccess = vi.fn(); | ||
|
|
||
| render( | ||
| <StorageBackendDeleteConfirmModal | ||
| backend={mockBackend as never} | ||
| onClose={vi.fn()} | ||
| onSuccess={onSuccess} | ||
| />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /^Delete$/i })); | ||
|
|
||
| await waitFor(() => { | ||
| expect( | ||
| screen.getByText(/backend is referenced by an active storage tier/i), | ||
| ).toBeInTheDocument(); | ||
| }); | ||
| expect(onSuccess).not.toHaveBeenCalled(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }); | ||
|
|
||
| it('calls onClose when Cancel is clicked', async () => { | ||
| const user = userEvent.setup(); | ||
| const onClose = vi.fn(); | ||
|
|
||
| render( | ||
| <StorageBackendDeleteConfirmModal | ||
| backend={mockBackend as never} | ||
| onClose={onClose} | ||
| onSuccess={vi.fn()} | ||
| />, | ||
| ); | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /Cancel/i })); | ||
| expect(onClose).toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
77 changes: 77 additions & 0 deletions
77
libs/ui-components/src/components/Storage/StorageBackendDeleteConfirmModal.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import { | ||
| Alert, | ||
| Button, | ||
| Modal, | ||
| ModalBody, | ||
| ModalFooter, | ||
| ModalHeader, | ||
| Stack, | ||
| StackItem, | ||
| } from '@patternfly/react-core'; | ||
|
|
||
| import type { StorageBackend } from '@osac/types/private'; | ||
|
|
||
| import { useDeleteStorageBackend } from '../../api/v1/private/storage-backends'; | ||
| import { useTranslation } from '../../hooks/useTranslation'; | ||
| import { getErrorMessage } from '../../utils/error'; | ||
|
|
||
| interface StorageBackendDeleteConfirmModalProps { | ||
| backend: StorageBackend; | ||
| onClose: () => void; | ||
| onSuccess: () => void; | ||
| } | ||
|
|
||
| const StorageBackendDeleteConfirmModal = ({ | ||
| backend, | ||
| onClose, | ||
| onSuccess, | ||
| }: StorageBackendDeleteConfirmModalProps) => { | ||
| const { t } = useTranslation(); | ||
| const { mutate, isPending, error } = useDeleteStorageBackend(); | ||
|
|
||
| const backendName = backend.metadata?.name ?? backend.id; | ||
|
|
||
| return ( | ||
| <Modal | ||
| variant="small" | ||
| isOpen | ||
| onClose={isPending ? undefined : onClose} | ||
| aria-labelledby="storage-backend-delete-confirm-title" | ||
| > | ||
| <ModalHeader | ||
| title={t('Delete {{name}}?', { name: backendName })} | ||
| titleIconVariant="warning" | ||
| labelId="storage-backend-delete-confirm-title" | ||
| /> | ||
| <ModalBody> | ||
| <Stack hasGutter> | ||
| <StackItem> | ||
| {t('This permanently deletes the storage backend. This action cannot be undone.')} | ||
| </StackItem> | ||
| {error && ( | ||
| <StackItem> | ||
| <Alert variant="danger" title={t('Failed to delete storage backend')} isInline> | ||
| {getErrorMessage(error)} | ||
| </Alert> | ||
| </StackItem> | ||
| )} | ||
| </Stack> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button variant="link" onClick={onClose} isDisabled={isPending}> | ||
| {t('Cancel')} | ||
| </Button> | ||
| <Button | ||
| variant="danger" | ||
| onClick={() => mutate(backend.id, { onSuccess })} | ||
| isDisabled={isPending} | ||
| isLoading={isPending} | ||
| > | ||
| {t('Delete')} | ||
| </Button> | ||
| </ModalFooter> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export default StorageBackendDeleteConfirmModal; |
24 changes: 24 additions & 0 deletions
24
libs/ui-components/src/components/Storage/StorageBackendStatusLabel.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { screen } from '@testing-library/react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import { StorageBackendState } from '@osac/types/private'; | ||
|
|
||
| import StorageBackendStatusLabel from './StorageBackendStatusLabel'; | ||
| import { renderWithProviders } from '../../test-utils/TestProviders'; | ||
|
|
||
| describe('StorageBackendStatusLabel', () => { | ||
| it('maps READY to ready/Ready', () => { | ||
| renderWithProviders(<StorageBackendStatusLabel state={StorageBackendState.READY} />); | ||
| expect(screen.getByText('Ready')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('maps UNSPECIFIED to unspecified/Unspecified', () => { | ||
| renderWithProviders(<StorageBackendStatusLabel state={StorageBackendState.UNSPECIFIED} />); | ||
| expect(screen.getByText('Unspecified')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('maps undefined to unspecified/Unspecified', () => { | ||
| renderWithProviders(<StorageBackendStatusLabel />); | ||
| expect(screen.getByText('Unspecified')).toBeInTheDocument(); | ||
| }); | ||
| }); |
34 changes: 34 additions & 0 deletions
34
libs/ui-components/src/components/Storage/StorageBackendStatusLabel.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { TFunction } from 'i18next'; | ||
|
|
||
| import { StorageBackendState } from '@osac/types/private'; | ||
|
|
||
| import { useTranslation } from '../../hooks/useTranslation'; | ||
| import { ResourceStatusLabel, StatusLabelProps } from '../Resource/ResourceStatusLabel'; | ||
|
|
||
| interface StorageBackendStatusLabelProps { | ||
| state?: StorageBackendState; | ||
| } | ||
|
|
||
| const storageBackendStatusMap = (t: TFunction): Record<StorageBackendState, StatusLabelProps> => ({ | ||
| [StorageBackendState.READY]: { | ||
| status: 'ready', | ||
| text: t('Ready'), | ||
| }, | ||
| [StorageBackendState.UNSPECIFIED]: { | ||
| status: 'unspecified', | ||
| text: t('Unspecified'), | ||
| }, | ||
| }); | ||
|
|
||
| const StorageBackendStatusLabel = ({ state }: StorageBackendStatusLabelProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| const statusMap = storageBackendStatusMap(t); | ||
|
|
||
| const status = | ||
| state !== undefined ? statusMap[state] : statusMap[StorageBackendState.UNSPECIFIED]; | ||
|
|
||
| return <ResourceStatusLabel {...status} />; | ||
| }; | ||
|
|
||
| export default StorageBackendStatusLabel; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.