mirror of
https://github.com/harness/drone.git
synced 2025-05-05 15:32:56 +00:00
feat: [AH-1251]: Support Delete Version for non oci flow (#3728)
* feat: [AH-1251]: Support Delete Version for non oci flow
This commit is contained in:
parent
8d0c8b2f1e
commit
92f986122f
@ -67,7 +67,8 @@ export enum RepositoryConfigType {
|
||||
|
||||
export enum PageType {
|
||||
Details = 'Details',
|
||||
Table = 'Table'
|
||||
Table = 'Table',
|
||||
GlobalList = 'GlobalList'
|
||||
}
|
||||
|
||||
export enum Scanners {
|
||||
|
@ -263,7 +263,7 @@ export const ArtifactVersionActions: CellType = ({ row }) => {
|
||||
const { original } = row
|
||||
return (
|
||||
<VersionActionsWidget
|
||||
pageType={PageType.Table}
|
||||
pageType={PageType.GlobalList}
|
||||
data={original}
|
||||
repoKey={original.registryIdentifier}
|
||||
artifactKey={original.name}
|
||||
|
@ -96,9 +96,14 @@ export class DockerVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(props: ArtifactRowSubComponentProps): JSX.Element {
|
||||
|
@ -31,6 +31,7 @@ import VersionListTable, {
|
||||
type CommonVersionListTableProps
|
||||
} from '@ar/pages/version-list/components/VersionListTable/VersionListTable'
|
||||
import { VersionListColumnEnum } from '@ar/pages/version-list/components/VersionListTable/types'
|
||||
import ArtifactActions from '@ar/pages/artifact-details/components/ArtifactActions/ArtifactActions'
|
||||
import { VersionDetailsTab } from '../components/VersionDetailsTabs/constants'
|
||||
import GenericOverviewPage from './pages/overview/OverviewPage'
|
||||
import OSSContentPage from './pages/oss-details/OSSContentPage'
|
||||
@ -54,12 +55,16 @@ export class GenericVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
[VersionListColumnEnum.Name]: { width: '100%' },
|
||||
[VersionListColumnEnum.Size]: { width: '100%' },
|
||||
[VersionListColumnEnum.FileCount]: { width: '100%' },
|
||||
[VersionListColumnEnum.LastModified]: { width: '100%' }
|
||||
// [VersionListColumnEnum.Actions]: { width: '10%' } // TODO: will add this once BE support actions
|
||||
[VersionListColumnEnum.LastModified]: { width: '100%' },
|
||||
[VersionListColumnEnum.Actions]: { width: '10%' }
|
||||
}
|
||||
|
||||
protected allowedActionsOnVersion = [VersionAction.SetupClient, VersionAction.ViewVersionDetails]
|
||||
protected allowedActionsOnVersionDetailsPage = []
|
||||
protected allowedActionsOnVersion = [
|
||||
VersionAction.Delete,
|
||||
VersionAction.SetupClient,
|
||||
VersionAction.ViewVersionDetails
|
||||
]
|
||||
protected allowedActionsOnVersionDetailsPage = [VersionAction.Delete]
|
||||
|
||||
renderVersionListTable(props: VersionListTableProps): JSX.Element {
|
||||
return <VersionListTable {...props} columnConfigs={this.versionListTableColumnConfig} />
|
||||
@ -82,14 +87,19 @@ export class GenericVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactActions(_props: ArtifactActionProps): JSX.Element {
|
||||
return <></>
|
||||
renderArtifactActions(props: ArtifactActionProps): JSX.Element {
|
||||
return <ArtifactActions {...props} />
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(props: ArtifactRowSubComponentProps): JSX.Element {
|
||||
|
@ -92,9 +92,14 @@ export class HelmVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(): JSX.Element {
|
||||
|
@ -32,6 +32,7 @@ import {
|
||||
type VersionListTableProps,
|
||||
VersionStep
|
||||
} from '@ar/frameworks/Version/Version'
|
||||
import ArtifactActions from '@ar/pages/artifact-details/components/ArtifactActions/ArtifactActions'
|
||||
|
||||
import OSSContentPage from './pages/oss-details/OSSContentPage'
|
||||
import VersionFilesProvider from '../context/VersionFilesProvider'
|
||||
@ -56,12 +57,16 @@ export class MavenVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
[VersionListColumnEnum.Name]: { width: '100%' },
|
||||
[VersionListColumnEnum.Size]: { width: '100%' },
|
||||
[VersionListColumnEnum.FileCount]: { width: '100%' },
|
||||
[VersionListColumnEnum.LastModified]: { width: '100%' }
|
||||
// [VersionListColumnEnum.Actions]: { width: '10%' } // TODO: will add this once BE support actions
|
||||
[VersionListColumnEnum.LastModified]: { width: '100%' },
|
||||
[VersionListColumnEnum.Actions]: { width: '10%' }
|
||||
}
|
||||
|
||||
protected allowedActionsOnVersion = [VersionAction.SetupClient, VersionAction.ViewVersionDetails]
|
||||
protected allowedActionsOnVersionDetailsPage = []
|
||||
protected allowedActionsOnVersion = [
|
||||
VersionAction.Delete,
|
||||
VersionAction.SetupClient,
|
||||
VersionAction.ViewVersionDetails
|
||||
]
|
||||
protected allowedActionsOnVersionDetailsPage = [VersionAction.Delete]
|
||||
|
||||
renderVersionListTable(props: VersionListTableProps): JSX.Element {
|
||||
return <VersionListTable {...props} columnConfigs={this.versionListTableColumnConfig} />
|
||||
@ -84,14 +89,19 @@ export class MavenVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactActions(_props: ArtifactActionProps): JSX.Element {
|
||||
return <></>
|
||||
renderArtifactActions(props: ArtifactActionProps): JSX.Element {
|
||||
return <ArtifactActions {...props} />
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(props: ArtifactRowSubComponentProps): JSX.Element {
|
||||
|
@ -63,12 +63,13 @@ export class NpmVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
protected allowedActionsOnVersion = [
|
||||
VersionAction.Delete,
|
||||
VersionAction.SetupClient,
|
||||
VersionAction.DownloadCommand,
|
||||
VersionAction.ViewVersionDetails
|
||||
]
|
||||
|
||||
protected allowedActionsOnVersionDetailsPage = []
|
||||
protected allowedActionsOnVersionDetailsPage = [VersionAction.Delete]
|
||||
|
||||
renderVersionListTable(props: VersionListTableProps): JSX.Element {
|
||||
return <VersionListTable {...props} columnConfigs={this.versionListTableColumnConfig} />
|
||||
@ -101,9 +102,14 @@ export class NpmVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(props: ArtifactRowSubComponentProps): JSX.Element {
|
||||
|
@ -63,12 +63,13 @@ export class NuGetVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
protected allowedActionsOnVersion: VersionAction[] = [
|
||||
VersionAction.Delete,
|
||||
VersionAction.SetupClient,
|
||||
VersionAction.DownloadCommand,
|
||||
VersionAction.ViewVersionDetails
|
||||
]
|
||||
|
||||
protected allowedActionsOnVersionDetailsPage = []
|
||||
protected allowedActionsOnVersionDetailsPage = [VersionAction.Delete]
|
||||
|
||||
renderVersionListTable(props: VersionListTableProps): JSX.Element {
|
||||
return <VersionListTable {...props} columnConfigs={this.versionListTableColumnConfig} />
|
||||
@ -101,9 +102,14 @@ export class NuGetVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(props: ArtifactRowSubComponentProps): JSX.Element {
|
||||
|
@ -64,12 +64,13 @@ export class PythonVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
protected allowedActionsOnVersion = [
|
||||
VersionAction.Delete,
|
||||
VersionAction.SetupClient,
|
||||
VersionAction.DownloadCommand,
|
||||
VersionAction.ViewVersionDetails
|
||||
]
|
||||
|
||||
protected allowedActionsOnVersionDetailsPage = []
|
||||
protected allowedActionsOnVersionDetailsPage = [VersionAction.Delete]
|
||||
|
||||
renderVersionListTable(props: VersionListTableProps): JSX.Element {
|
||||
return <VersionListTable {...props} columnConfigs={this.versionListTableColumnConfig} />
|
||||
@ -102,9 +103,14 @@ export class PythonVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
}
|
||||
|
||||
renderVersionActions(props: VersionActionProps): JSX.Element {
|
||||
const allowedActions =
|
||||
props.pageType === PageType.Table ? this.allowedActionsOnVersion : this.allowedActionsOnVersionDetailsPage
|
||||
return <VersionActions {...props} allowedActions={allowedActions} />
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
}
|
||||
|
||||
renderArtifactRowSubComponent(props: ArtifactRowSubComponentProps): JSX.Element {
|
||||
|
@ -115,6 +115,8 @@ export class RPMVersionType extends VersionStep<ArtifactVersionSummary> {
|
||||
switch (props.pageType) {
|
||||
case PageType.Details:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersionDetailsPage} />
|
||||
case PageType.Table:
|
||||
case PageType.GlobalList:
|
||||
default:
|
||||
return <VersionActions {...props} allowedActions={this.allowedActionsOnVersion} />
|
||||
}
|
||||
|
@ -15,39 +15,32 @@
|
||||
*/
|
||||
|
||||
import React from 'react'
|
||||
import { useHistory } from 'react-router-dom'
|
||||
|
||||
import { useStrings } from '@ar/frameworks/strings'
|
||||
import { queryClient } from '@ar/utils/queryClient'
|
||||
import { useParentComponents, useRoutes } from '@ar/hooks'
|
||||
import { useParentComponents } from '@ar/hooks'
|
||||
import { PermissionIdentifier, ResourceType } from '@ar/common/permissionTypes'
|
||||
|
||||
import type { VersionActionProps } from './types'
|
||||
import useDeleteVersionModal from '../../hooks/useDeleteVersionModal'
|
||||
import { useUtilsForDeleteVersion } from '../../hooks/useUtilsForDeleteVersion'
|
||||
|
||||
export default function DeleteVersionMenuItem(props: VersionActionProps): JSX.Element {
|
||||
const { artifactKey, repoKey, readonly, onClose, versionKey } = props
|
||||
const { artifactKey, repoKey, readonly, onClose, versionKey, pageType } = props
|
||||
const { getString } = useStrings()
|
||||
const { RbacMenuItem } = useParentComponents()
|
||||
const history = useHistory()
|
||||
const routes = useRoutes()
|
||||
|
||||
const handleAfterDeleteRepository = (): void => {
|
||||
const { handleRedirectAfterDeleteVersion } = useUtilsForDeleteVersion()
|
||||
|
||||
const handleAfterDeleteVersion = () => {
|
||||
onClose?.()
|
||||
queryClient.invalidateQueries(['GetAllArtifactVersions'])
|
||||
history.push(
|
||||
routes.toARArtifactDetails({
|
||||
repositoryIdentifier: repoKey,
|
||||
artifactIdentifier: artifactKey
|
||||
})
|
||||
)
|
||||
handleRedirectAfterDeleteVersion(pageType)
|
||||
}
|
||||
|
||||
const { triggerDelete } = useDeleteVersionModal({
|
||||
artifactKey,
|
||||
repoKey,
|
||||
versionKey,
|
||||
onSuccess: handleAfterDeleteRepository
|
||||
onSuccess: handleAfterDeleteVersion
|
||||
})
|
||||
|
||||
const handleDeleteService = (): void => {
|
||||
|
@ -0,0 +1,74 @@
|
||||
/*
|
||||
* 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 { useHistory, useParams } from 'react-router-dom'
|
||||
import { getAllArtifactVersions } from '@harnessio/react-har-service-client'
|
||||
|
||||
import { useRoutes } from '@ar/hooks'
|
||||
import { PageType } from '@ar/common/types'
|
||||
import type { ArtifactDetailsPathParams } from '@ar/routes/types'
|
||||
import { encodeRef, useGetSpaceRef } from '@ar/hooks/useGetSpaceRef'
|
||||
import { RepositoryDetailsTab } from '@ar/pages/repository-details/constants'
|
||||
import { queryClient } from '@ar/utils/queryClient'
|
||||
|
||||
export function useUtilsForDeleteVersion() {
|
||||
const routes = useRoutes()
|
||||
const history = useHistory()
|
||||
const registryRef = useGetSpaceRef()
|
||||
const { repositoryIdentifier, artifactIdentifier } = useParams<ArtifactDetailsPathParams>()
|
||||
|
||||
async function handleRedirectToVersionListURL(): Promise<void> {
|
||||
try {
|
||||
await getAllArtifactVersions({
|
||||
registry_ref: registryRef,
|
||||
artifact: encodeRef(artifactIdentifier),
|
||||
queryParams: {
|
||||
size: 1
|
||||
}
|
||||
})
|
||||
queryClient.invalidateQueries(['GetAllArtifactVersions'])
|
||||
history.push(
|
||||
routes.toARArtifactDetails({
|
||||
repositoryIdentifier,
|
||||
artifactIdentifier
|
||||
})
|
||||
)
|
||||
} catch (e) {
|
||||
history.push(
|
||||
routes.toARRepositoryDetailsTab({
|
||||
repositoryIdentifier,
|
||||
tab: RepositoryDetailsTab.PACKAGES
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRedirectAfterDeleteVersion(pageType: PageType): Promise<void> {
|
||||
switch (pageType) {
|
||||
case PageType.Details:
|
||||
case PageType.Table:
|
||||
handleRedirectToVersionListURL()
|
||||
return
|
||||
default:
|
||||
queryClient.invalidateQueries(['GetAllHarnessArtifacts'])
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
handleRedirectAfterDeleteVersion
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user