-
Notifications
You must be signed in to change notification settings - Fork 2
feat(ui): clavis pca certitificate get-by-id #844
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4d40c8f
feat(ui): list certificates issued by ca
vlad-schur-external-sap 990d343
feat(ui): get-by-id cert of ca register route
vlad-schur-external-sap d43c28c
Merge branch 'main' into vlad-clavis-pca-cert-get-by-id
vlad-schur-external-sap 635ca5a
feat(aurora-portal): cert details view page
vlad-schur-external-sap 6acf99d
Merge branch 'main' into vlad-clavis-pca-cert-get-by-id
vlad-schur-external-sap e6878e4
fix(bff): get-by-id certificate schema
vlad-schur-external-sap 1cd5ad8
refactor(ui): certificate-id structure with tests
vlad-schur-external-sap fbc65fd
chore(docs): update clavis docs
vlad-schur-external-sap 68d815a
fix(ui): code-rabbit comment
vlad-schur-external-sap 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
116 changes: 116 additions & 0 deletions
116
...l/src/client/routes/_auth/projects/$projectId/services/pca/$pcaId/$certificateId.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,116 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest" | ||
| import { render, screen } from "@testing-library/react" | ||
| import userEvent from "@testing-library/user-event" | ||
| import { I18nProvider } from "@lingui/react" | ||
| import { i18n } from "@lingui/core" | ||
| import { PortalProvider } from "@cloudoperators/juno-ui-components" | ||
| import { trpcReact } from "@/client/trpcClient" | ||
| import { RouteComponent } from "./$certificateId" | ||
|
|
||
| const mockSetPageTitle = vi.fn() | ||
| const mockNavigate = vi.fn() | ||
|
|
||
| vi.mock("@tanstack/react-router", () => ({ | ||
| createFileRoute: () => () => ({ | ||
| staticData: {}, | ||
| useParams: () => ({ projectId: "project-1", pcaId: "ca-1", certificateId: "cert-1" }), | ||
| useRouteContext: () => ({ setPageTitle: mockSetPageTitle }), | ||
| }), | ||
| useNavigate: () => mockNavigate, | ||
| })) | ||
|
|
||
| vi.mock("@/client/trpcClient", async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import("@/client/trpcClient")>() | ||
| return { | ||
| ...actual, | ||
| trpcReact: { | ||
| ...actual.trpcReact, | ||
| services: { | ||
| ...actual.trpcReact.services, | ||
| pca: { | ||
| ...actual.trpcReact.services.pca, | ||
| getByIdCertificate: { | ||
| ...actual.trpcReact.services.pca.getByIdCertificate, | ||
| useQuery: vi.fn(), | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| const renderComponent = () => | ||
| render( | ||
| <I18nProvider i18n={i18n}> | ||
| <PortalProvider> | ||
| <RouteComponent /> | ||
| </PortalProvider> | ||
| </I18nProvider> | ||
| ) | ||
|
|
||
| const mockQuery = (overrides: object) => | ||
| vi.mocked(trpcReact.services.pca.getByIdCertificate.useQuery).mockReturnValue({ | ||
| data: undefined, | ||
| isLoading: false, | ||
| isError: false, | ||
| error: null, | ||
| ...overrides, | ||
| } as never) | ||
|
|
||
| describe("$certificateId page", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| it("renders loading state", () => { | ||
| mockQuery({ isLoading: true }) | ||
| renderComponent() | ||
|
|
||
| expect(screen.getByText("Loading Certificate Details...")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("renders error state with message", () => { | ||
| mockQuery({ isError: true, error: { message: "Not found" } }) | ||
| renderComponent() | ||
|
|
||
| expect(screen.getByText("Not found")).toBeInTheDocument() | ||
| expect(screen.getByRole("button", { name: "Back to Certificate Authorities Details page" })).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("renders not-found state", () => { | ||
| mockQuery({ data: undefined }) | ||
| renderComponent() | ||
|
|
||
| expect(screen.getByText("Certificate not found")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("renders certificate details", () => { | ||
| mockQuery({ | ||
| data: { | ||
| id: "cert-1", | ||
| certificate_authority_id: "ca-1", | ||
| project_id: "project-1", | ||
| csr: "-----BEGIN CERTIFICATE REQUEST-----\nABC\n-----END CERTIFICATE REQUEST-----", | ||
| configuration: { validity: { not_before: 0, not_after: 86400 } }, | ||
| }, | ||
| }) | ||
| renderComponent() | ||
|
|
||
| expect(screen.getByText("cert-1 Certificate Details")).toBeInTheDocument() | ||
| expect(screen.getByText("ca-1")).toBeInTheDocument() | ||
| expect(screen.getByText("1 days")).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it("navigates back on error back button click", async () => { | ||
| const user = userEvent.setup() | ||
| mockQuery({ isError: true, error: { message: "error" } }) | ||
| renderComponent() | ||
|
|
||
| await user.click(screen.getByRole("button", { name: "Back to Certificate Authorities Details page" })) | ||
|
|
||
| expect(mockNavigate).toHaveBeenCalledWith({ | ||
| to: "/projects/$projectId/services/pca/$pcaId", | ||
| params: { projectId: "project-1", pcaId: "ca-1" }, | ||
| }) | ||
| }) | ||
| }) |
142 changes: 142 additions & 0 deletions
142
...portal/src/client/routes/_auth/projects/$projectId/services/pca/$pcaId/$certificateId.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,142 @@ | ||
| import { createFileRoute, useNavigate } from "@tanstack/react-router" | ||
| import type { RouteInfo } from "@/client/routes/routeInfo" | ||
| import { trpcReact } from "@/client/trpcClient" | ||
| import { | ||
| Button, | ||
| DescriptionDefinition, | ||
| DescriptionList, | ||
| DescriptionTerm, | ||
| Divider, | ||
| Spinner, | ||
| Stack, | ||
| } from "@cloudoperators/juno-ui-components/index" | ||
| import { Trans, useLingui } from "@lingui/react/macro" | ||
| import { MdContentCopy, MdDownload } from "react-icons/md" | ||
| import { Fragment } from "react/jsx-runtime" | ||
|
|
||
| export const Route = createFileRoute("/_auth/projects/$projectId/services/pca/$pcaId/$certificateId")({ | ||
| staticData: { section: "services", service: "pca" } satisfies RouteInfo, | ||
| component: RouteComponent, | ||
| }) | ||
|
|
||
| export function RouteComponent() { | ||
| const { t } = useLingui() | ||
| const navigate = useNavigate() | ||
| const { setPageTitle } = Route.useRouteContext() | ||
| const { projectId, pcaId, certificateId } = Route.useParams() | ||
|
|
||
| const { | ||
| isLoading, | ||
| isError, | ||
| error, | ||
| data: certificate, | ||
| } = trpcReact.services.pca.getByIdCertificate.useQuery({ | ||
| project_id: projectId, | ||
| certificate_authority_id: pcaId, | ||
| certificate_id: certificateId, | ||
| }) | ||
|
|
||
| // Loading state | ||
| if (isLoading) { | ||
| setPageTitle(t`Loading...`) | ||
| return ( | ||
| <Stack className="fixed inset-0" distribution="center" alignment="center" direction="vertical"> | ||
| <Spinner variant="primary" size="large" className="mb-2" /> | ||
| <Trans>Loading Certificate Details...</Trans> | ||
| </Stack> | ||
| ) | ||
| } | ||
|
|
||
| const handleBack = () => | ||
| navigate({ | ||
| to: "/projects/$projectId/services/pca/$pcaId", | ||
| params: { projectId, pcaId }, | ||
| }) | ||
|
vlad-schur-external-sap marked this conversation as resolved.
|
||
|
|
||
| // Error state | ||
| if (isError) { | ||
| const errorMessage = error?.message || "Unknown error" | ||
| return ( | ||
| <Stack className="fixed inset-0" distribution="center" alignment="center" direction="vertical" gap="5"> | ||
| <p className="text-theme-error font-semibold"> | ||
| <Trans>Error loading Certificate</Trans> | ||
| </p> | ||
| <p className="text-theme-highest">{errorMessage}</p> | ||
| <Button onClick={handleBack} variant="primary"> | ||
| <Trans>Back to Certificate Authorities Details page</Trans> | ||
| </Button> | ||
| </Stack> | ||
| ) | ||
| } | ||
|
|
||
| // No data state | ||
| if (!certificate) { | ||
| return ( | ||
| <Stack className="fixed inset-0" distribution="center" alignment="center" direction="vertical" gap="5"> | ||
| <p className="text-theme-secondary"> | ||
| <Trans>Certificate not found</Trans> | ||
| </p> | ||
| <Button onClick={handleBack} variant="primary"> | ||
| <Trans>Back to Certificate Authorities Details page</Trans> | ||
| </Button> | ||
| </Stack> | ||
| ) | ||
| } | ||
|
|
||
| setPageTitle(`Certificate ${certificate.id}`) | ||
|
|
||
| const basicInfo = [ | ||
| { label: t`CA ID`, value: certificate.certificate_authority_id }, | ||
| { label: t`ID`, value: certificate.id }, | ||
| { | ||
| label: t`Duration/validity`, | ||
| value: | ||
| certificate.configuration?.validity.not_before !== undefined && | ||
| certificate.configuration?.validity.not_after !== undefined | ||
| ? `${Math.round( | ||
| (certificate.configuration.validity.not_after - certificate.configuration.validity.not_before) / | ||
| (60 * 60 * 24) | ||
| )} days` | ||
| : undefined, | ||
| }, | ||
| ] as const | ||
|
|
||
| return ( | ||
| <Stack direction="vertical" gap="3"> | ||
| <div className="text-theme-default text-2xl font-semibold">{`${certificate.id} Certificate Details`}</div> | ||
|
|
||
| <p className="text-theme-highest text-sm"> | ||
| <Trans>Manage your Certificate</Trans> | ||
| </p> | ||
|
|
||
| <Stack gap="4" className="grid grid-cols-2 items-start"> | ||
| <DescriptionList alignTerms="right" className="w-full"> | ||
| {basicInfo.map(({ label, value }) => ( | ||
| <Fragment key={label}> | ||
| <DescriptionTerm>{label}</DescriptionTerm> | ||
| <DescriptionDefinition>{value || "—"}</DescriptionDefinition> | ||
| </Fragment> | ||
| ))} | ||
| </DescriptionList> | ||
|
|
||
| <div className="bg-dt-background w-full rounded-sm"> | ||
| <div className="text-theme-default p-4 text-xl font-bold">Certificate {`${certificate.id}`}</div> | ||
| <Divider /> | ||
|
|
||
| <div className="p-4 text-sm break-all whitespace-pre-wrap">{certificate?.csr}</div> | ||
|
|
||
| {/* I will implement downloading-copying functionality at issue/import part of the epic as I need to clarify some stuff with design-clavis team */} | ||
| <Divider /> | ||
| <Stack gap="2" distribution="end" className="p-4"> | ||
| <Button> | ||
| <MdDownload /> | ||
| </Button> | ||
| <Button> | ||
| <MdContentCopy /> | ||
| </Button> | ||
| </Stack> | ||
| </div> | ||
| </Stack> | ||
| </Stack> | ||
| ) | ||
| } | ||
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.