Skip to content

Commit 554ce87

Browse files
committed
feat: add isTemplateView in savePipeline and deleteWorkflow
1 parent 90c8571 commit 554ce87

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/Common/DeleteCINodeButton/DeleteCINodeButton.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export const DeleteCINodeButton = ({
3232
deletePayloadConfig,
3333
onDelete,
3434
getWorkflows,
35+
isTemplateView,
3536
}: DeleteCINodeButtonProps) => {
3637
const [showDeleteModal, setShowDeleteModal] = useState<boolean>(false)
3738

@@ -50,6 +51,7 @@ export const DeleteCINodeButton = ({
5051
const response = await deleteWorkflow(
5152
String(deletePayloadConfig.appId),
5253
Number(deletePayloadConfig.appWorkflowId),
54+
isTemplateView,
5355
)
5456
if (response.errors) {
5557
const { errors } = response
@@ -83,7 +85,7 @@ export const DeleteCINodeButton = ({
8385
name: deletePayloadConfig.pipelineName,
8486
},
8587
}
86-
await savePipeline(deletePayload)
88+
await savePipeline(deletePayload, { isTemplateView })
8789
if (typeof onDelete === 'function') {
8890
onDelete()
8991
}

src/Common/DeleteCINodeButton/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
import { AppConfigProps } from '@Pages/index'
2+
13
interface DeletePayloadConfig {
24
appId: string
35
appWorkflowId: number
46
pipelineId: number
57
pipelineName: string
68
}
79

8-
export interface DeleteCINodeButtonProps {
10+
export interface DeleteCINodeButtonProps extends Required<Pick<AppConfigProps, 'isTemplateView'>> {
911
testId: string
1012
title: string
1113
showIconOnly?: boolean
Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,39 @@
11
import { Routes } from '@Shared/constants'
2+
import { AppConfigProps, GetTemplateAPIRouteType } from '@Pages/index'
3+
import { getTemplateAPIRoute } from '@Shared/index'
24
import { post, trash } from '..'
35

4-
export function savePipeline(request, isRegexMaterial = false): Promise<any> {
6+
export function savePipeline(
7+
request,
8+
{
9+
isRegexMaterial = false,
10+
isTemplateView,
11+
}: Required<Pick<AppConfigProps, 'isTemplateView'>> & {
12+
isRegexMaterial?: boolean
13+
},
14+
): Promise<any> {
515
let url
616
if (isRegexMaterial) {
717
url = `${Routes.CI_PIPELINE_PATCH}/regex`
818
} else {
9-
url = `${Routes.CI_PIPELINE_PATCH}`
19+
url = isTemplateView
20+
? getTemplateAPIRoute({
21+
type: GetTemplateAPIRouteType.CI_PIPELINE,
22+
queryParams: {
23+
id: request.appId,
24+
},
25+
})
26+
: Routes.CI_PIPELINE_PATCH
1027
}
1128
return post(url, request)
1229
}
1330

14-
export function deleteWorkflow(appId: string, workflowId: number) {
15-
const URL = `${Routes.WORKFLOW}/${appId}/${workflowId}`
31+
export function deleteWorkflow(appId: string, workflowId: number, isTemplateView: AppConfigProps['isTemplateView']) {
32+
const URL = isTemplateView
33+
? getTemplateAPIRoute({
34+
type: GetTemplateAPIRouteType.WORKFLOW,
35+
queryParams: { id: appId, appWorkflowId: workflowId },
36+
})
37+
: `${Routes.WORKFLOW}/${appId}/${workflowId}`
1638
return trash(URL)
1739
}

0 commit comments

Comments
 (0)