From 285cb1b9badfc93cddd4859fe83dbdb1537c1c6a Mon Sep 17 00:00:00 2001 From: Shivanand Sonnad Date: Tue, 4 Mar 2025 12:07:03 +0000 Subject: [PATCH] feat: [AH-1020]: support delete artifact action on registry artifact list and artifact details page (#3497) * feat: [AH-1020]: fix failing unit tests * feat: [AH-1020]: enode artifact key before calling api * feat: [AH-1020]: add unit test for registry artifact list tables * feat: [AH-1020]: support delete artifact action on registry artifact list and artifact details page --- .../Version/ArtifactActionsWidget.tsx | 40 +++ web/src/ar/frameworks/Version/Version.tsx | 19 +- .../ar/gitness/utils/getARRouteDefinitions.ts | 2 +- .../ArtifactActions.module.scss | 19 - .../ArtifactActions.module.scss.d.ts | 19 - .../ArtifactActions/ArtifactActions.tsx | 73 ++-- ...ository.tsx => DeleteArtifactMenuItem.tsx} | 26 +- .../ArtifactActions/EditRepository.tsx | 58 ---- ...etupClient.tsx => SetupClientMenuItem.tsx} | 5 +- .../components/ArtifactActions/types.ts | 9 +- .../ArtifactDetailsHeaderContent.tsx | 10 +- .../useDeleteArtifactModal.tsx | 67 ++++ .../artifact-details/strings/strings.en.yaml | 4 + .../RegistryArtifactListTable.module.scss | 2 +- .../RegistryArtifactListTable.tsx | 7 + .../RegistryArtifactListTableCell.tsx | 16 +- .../artifact-list/strings/strings.en.yaml | 1 + .../__tests__/__mockData__.ts | 2 +- .../__tests__/__mockData__.ts | 2 +- .../HelmRepository/__tests__/__mockData__.ts | 2 +- .../MavenRepository/__tests__/__mockData__.ts | 2 +- .../DockerVersion/DockerVersionType.tsx | 12 +- .../__tests__/DockerArtifactListPage.test.tsx | 325 ++++++++++++++++++ .../GenericVersion/GenericVersionType.tsx | 6 + .../GenericArtifactListPage.test.tsx | 325 ++++++++++++++++++ .../HelmVersion/HelmVersionType.tsx | 12 +- .../__tests__/HelmArtifactListPage.test.tsx | 325 ++++++++++++++++++ .../MavenVersion/MavenVersion.tsx | 8 +- .../__tests__/MavenArtifactListPage.test.tsx | 325 ++++++++++++++++++ .../NpmVersion/NpmVersionType.tsx | 8 +- web/src/ar/strings/types.ts | 4 + 31 files changed, 1574 insertions(+), 161 deletions(-) create mode 100644 web/src/ar/frameworks/Version/ArtifactActionsWidget.tsx delete mode 100644 web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss delete mode 100644 web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss.d.ts rename web/src/ar/pages/artifact-details/components/ArtifactActions/{DeleteRepository.tsx => DeleteArtifactMenuItem.tsx} (62%) delete mode 100644 web/src/ar/pages/artifact-details/components/ArtifactActions/EditRepository.tsx rename web/src/ar/pages/artifact-details/components/ArtifactActions/{SetupClient.tsx => SetupClientMenuItem.tsx} (90%) create mode 100644 web/src/ar/pages/artifact-details/hooks/useDeleteArtifactModal/useDeleteArtifactModal.tsx create mode 100644 web/src/ar/pages/version-details/DockerVersion/__tests__/DockerArtifactListPage.test.tsx create mode 100644 web/src/ar/pages/version-details/GenericVersion/__tests__/GenericArtifactListPage.test.tsx create mode 100644 web/src/ar/pages/version-details/HelmVersion/__tests__/HelmArtifactListPage.test.tsx create mode 100644 web/src/ar/pages/version-details/MavenVersion/__tests__/MavenArtifactListPage.test.tsx diff --git a/web/src/ar/frameworks/Version/ArtifactActionsWidget.tsx b/web/src/ar/frameworks/Version/ArtifactActionsWidget.tsx new file mode 100644 index 000000000..ab90920f9 --- /dev/null +++ b/web/src/ar/frameworks/Version/ArtifactActionsWidget.tsx @@ -0,0 +1,40 @@ +/* + * Copyright 2024 Harness, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react' +import { Text } from '@harnessio/uicore' + +import { useStrings } from '@ar/frameworks/strings' +import type { RepositoryPackageType } from '@ar/common/types' + +import versionFactory from './VersionFactory' +import type { ArtifactActionProps } from './Version' +import type { VersionAbstractFactory } from './VersionAbstractFactory' + +interface ArtifactActionsWidgetProps extends ArtifactActionProps { + factory?: VersionAbstractFactory + packageType: RepositoryPackageType +} + +export default function ArtifactActionsWidget(props: ArtifactActionsWidgetProps): JSX.Element { + const { factory = versionFactory, packageType, ...rest } = props + const { getString } = useStrings() + const repositoryType = factory?.getVersionType(packageType) + if (!repositoryType) { + return {getString('stepNotFound')} + } + return repositoryType.renderArtifactActions({ ...rest }) +} diff --git a/web/src/ar/frameworks/Version/Version.tsx b/web/src/ar/frameworks/Version/Version.tsx index 7b3f818bb..be8743e30 100644 --- a/web/src/ar/frameworks/Version/Version.tsx +++ b/web/src/ar/frameworks/Version/Version.tsx @@ -15,9 +15,13 @@ */ import type { PaginationProps } from '@harnessio/uicore' -import type { ListArtifactVersion } from '@harnessio/react-har-service-client' +import type { + ArtifactSummary, + ListArtifactVersion, + RegistryArtifactMetadata +} from '@harnessio/react-har-service-client' import type { VersionDetailsTab } from '@ar/pages/version-details/components/VersionDetailsTabs/constants' -import type { Parent, RepositoryPackageType } from '@ar/common/types' +import type { PageType, Parent, RepositoryPackageType } from '@ar/common/types' export interface VersionDetailsHeaderProps { data: T @@ -39,6 +43,15 @@ export interface VersionListTableProps { parent: Parent } +export interface ArtifactActionProps { + data: RegistryArtifactMetadata | ArtifactSummary + pageType: PageType + repoKey: string + artifactKey: string + readonly?: boolean + onClose?: () => void +} + export abstract class VersionStep { protected abstract packageType: RepositoryPackageType protected abstract allowedVersionDetailsTabs: VersionDetailsTab[] @@ -56,4 +69,6 @@ export abstract class VersionStep { abstract renderVersionDetailsHeader(props: VersionDetailsHeaderProps): JSX.Element abstract renderVersionDetailsTab(props: VersionDetailsTabProps): JSX.Element + + abstract renderArtifactActions(props: ArtifactActionProps): JSX.Element } diff --git a/web/src/ar/gitness/utils/getARRouteDefinitions.ts b/web/src/ar/gitness/utils/getARRouteDefinitions.ts index 8e8149911..7b82253de 100644 --- a/web/src/ar/gitness/utils/getARRouteDefinitions.ts +++ b/web/src/ar/gitness/utils/getARRouteDefinitions.ts @@ -38,7 +38,7 @@ export default function getARRouteDefinitions(routeParams: Record `/${params?.repositoryIdentifier}`, toARRepositoryDetailsTab: params => `/${params?.repositoryIdentifier}/${params?.tab}`, toARRepositoryWebhookDetails: params => `/${params?.repositoryIdentifier}/webhooks/${params?.webhookIdentifier}`, - toARArtifacts: () => `/${routeParams?.repositoryIdentifier}?tab=packages`, + toARArtifacts: () => `/${routeParams?.repositoryIdentifier}/packages`, toARArtifactDetails: params => `/${params?.repositoryIdentifier}/artifacts/${params?.artifactIdentifier}`, toARVersionDetails: params => `/${params?.repositoryIdentifier}/artifacts/${params?.artifactIdentifier}/versions/${params?.versionIdentifier}`, diff --git a/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss b/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss deleted file mode 100644 index 8f3fe057c..000000000 --- a/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2024 Harness, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -.optionsMenu { - min-width: unset; -} diff --git a/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss.d.ts b/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss.d.ts deleted file mode 100644 index 851246897..000000000 --- a/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.module.scss.d.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2023 Harness, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* eslint-disable */ -// This is an auto-generated file -export declare const optionsMenu: string diff --git a/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.tsx b/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.tsx index 257ace431..846c5059b 100644 --- a/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.tsx +++ b/web/src/ar/pages/artifact-details/components/ArtifactActions/ArtifactActions.tsx @@ -15,45 +15,46 @@ */ import React, { useState } from 'react' -import { Menu, Position } from '@blueprintjs/core' -import { Button, ButtonVariation } from '@harnessio/uicore' -import DeleteRepositoryMenuItem from './DeleteRepository' -import EditRepositoryMenuItem from './EditRepository' -import SetupClientMenuItem from './SetupClient' +import { PageType } from '@ar/common/types' +import ActionButton from '@ar/components/ActionButton/ActionButton' + +import SetupClientMenuItem from './SetupClientMenuItem' import type { ArtifactActionProps } from './types' +import DeleteArtifactMenuItem from './DeleteArtifactMenuItem' -import css from './ArtifactActions.module.scss' - -export default function ArtifactActions({ data, repoKey }: ArtifactActionProps): JSX.Element { - const [menuOpen, setMenuOpen] = useState(false) +export default function ArtifactActions({ + data, + repoKey, + artifactKey, + pageType, + readonly, + onClose +}: ArtifactActionProps): JSX.Element { + const [open, setOpen] = useState(false) return ( -