Skip to content

Commit 34f6bcb

Browse files
committed
feat(service): move triggerCDNode from dashboard
1 parent 9f76396 commit 34f6bcb

File tree

9 files changed

+94
-10
lines changed

9 files changed

+94
-10
lines changed

src/Common/Common.service.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
} from './Types'
4444
import { ApiResourceType } from '../Pages'
4545
import { RefVariableType } from './CIPipeline.Types'
46+
import { STAGE_MAP } from '@Pages/App/Trigger/constants'
4647

4748
export const getTeamListMin = (): Promise<TeamList> => {
4849
// ignore active field
@@ -68,13 +69,6 @@ interface UserRole extends ResponseType {
6869
}
6970
}
7071

71-
const stageMap = {
72-
PRECD: 'PRE',
73-
CD: 'DEPLOY',
74-
POSTCD: 'POST',
75-
APPROVAL: 'APPROVAL',
76-
}
77-
7872
export const SourceTypeMap = {
7973
BranchFixed: 'SOURCE_TYPE_BRANCH_FIXED',
8074
WEBHOOK: 'WEBHOOK',
@@ -369,7 +363,7 @@ export const genericCDMaterialsService = (
369363
default:
370364
URL = getUrlWithSearchParams(`${ROUTES.CD_MATERIAL_GET}/${cdMaterialID}/material`, {
371365
...manipulatedParams,
372-
stage: stageMap[stage],
366+
stage: STAGE_MAP[stage],
373367
})
374368
break
375369
}

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ export const ROUTES = {
128128
FILE_UPLOAD: 'file/upload',
129129
PLUGIN_GLOBAL_VARIABLES: 'plugin/global/list/global-variable',
130130
CONFIG_COMPARE_SECRET: 'config/compare/secret',
131+
CD_TRIGGER_POST: 'app/cd-pipeline/trigger',
131132
}
132133

133134
export enum KEY_VALUE {

src/Pages/App/Trigger/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const STAGE_MAP = {
2+
PRECD: 'PRE',
3+
CD: 'DEPLOY',
4+
POSTCD: 'POST',
5+
APPROVAL: 'APPROVAL',
6+
}

src/Pages/App/Trigger/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { triggerCDNode } from './service'
2+
export { getAPIOptionsWithTriggerTimeout } from './utils'
3+
export type { TriggerCDNodeServiceProps, TriggerCDPipelinePayloadType } from './types'

src/Pages/App/Trigger/service.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { post } from '@Common/Api'
2+
import { DeploymentNodeType } from '@Common/Types'
3+
import { DeploymentWithConfigType } from '@Shared/constants'
4+
import { ROUTES } from '@Common/Constants'
5+
import { TriggerCDNodeServiceProps, TriggerCDPipelinePayloadType } from './types'
6+
import { getAPIOptionsWithTriggerTimeout } from './utils'
7+
import { STAGE_MAP } from './constants'
8+
9+
export const triggerCDNode = ({
10+
pipelineId,
11+
ciArtifactId,
12+
appId,
13+
stageType,
14+
deploymentWithConfig,
15+
wfrId,
16+
runtimeParamsPayload,
17+
abortControllerRef,
18+
}: TriggerCDNodeServiceProps) => {
19+
const areRuntimeParamsConfigured =
20+
runtimeParamsPayload && (stageType === DeploymentNodeType.POSTCD || stageType === DeploymentNodeType.PRECD)
21+
22+
const request: TriggerCDPipelinePayloadType = {
23+
pipelineId,
24+
appId,
25+
ciArtifactId,
26+
cdWorkflowType: STAGE_MAP[stageType],
27+
...(areRuntimeParamsConfigured && runtimeParamsPayload),
28+
}
29+
30+
if (deploymentWithConfig) {
31+
request.deploymentWithConfig =
32+
deploymentWithConfig === DeploymentWithConfigType.LAST_SAVED_CONFIG
33+
? deploymentWithConfig
34+
: DeploymentWithConfigType.SPECIFIC_TRIGGER_CONFIG
35+
36+
if (deploymentWithConfig !== DeploymentWithConfigType.LAST_SAVED_CONFIG) {
37+
request.wfrIdForDeploymentWithSpecificTrigger = wfrId
38+
}
39+
}
40+
41+
return post(ROUTES.CD_TRIGGER_POST, request, { ...getAPIOptionsWithTriggerTimeout(), abortControllerRef })
42+
}

src/Pages/App/Trigger/types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { DeploymentNodeType } from '@Common/Types'
2+
import { RuntimeParamsTriggerPayloadType } from '@Shared/types'
3+
import { MutableRefObject } from 'react'
4+
5+
export interface TriggerCDNodeServiceProps {
6+
pipelineId: number
7+
ciArtifactId: number
8+
appId: number
9+
stageType: DeploymentNodeType
10+
deploymentWithConfig?: string
11+
wfrId?: number
12+
abortControllerRef?: MutableRefObject<AbortController>
13+
/**
14+
* Would be available only case of PRE/POST CD
15+
*/
16+
runtimeParamsPayload?: RuntimeParamsTriggerPayloadType
17+
}
18+
19+
export interface TriggerCDPipelinePayloadType
20+
extends Pick<
21+
TriggerCDNodeServiceProps,
22+
'pipelineId' | 'appId' | 'ciArtifactId' | 'runtimeParamsPayload' | 'deploymentWithConfig'
23+
> {
24+
cdWorkflowType: string
25+
wfrIdForDeploymentWithSpecificTrigger?: number
26+
}

src/Pages/App/Trigger/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { APIOptions } from '@Common/Types'
2+
3+
export const getAPIOptionsWithTriggerTimeout = (options?: APIOptions): APIOptions => {
4+
const _options: APIOptions = options ? JSON.parse(JSON.stringify(options)) : {}
5+
6+
if (window._env_.TRIGGER_API_TIMEOUT) {
7+
_options.timeout = window._env_.TRIGGER_API_TIMEOUT
8+
}
9+
10+
return _options
11+
}

src/Pages/App/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './AppConfiguration'
2+
export * from './Trigger'

src/Pages/ResourceBrowser/ResourceBrowser.Types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { NodeType, Nodes } from '@Shared/types'
18-
import { RefObject } from 'react'
18+
import { MutableRefObject, RefObject } from 'react'
1919

2020
export interface GVKType {
2121
Group: string
@@ -92,7 +92,7 @@ export interface BulkOperation {
9292
* Would these keys beside the name
9393
*/
9494
additionalKeys?: BulkOperationAdditionalKeysType[]
95-
operation: (signal: AbortSignal, data?: unknown) => Promise<void>
95+
operation: (abortControllerRef: MutableRefObject<AbortController>, data?: unknown) => Promise<void>
9696
}
9797

9898
export type BulkOperationModalProps = {

0 commit comments

Comments
 (0)