Skip to content

Commit ea07b1d

Browse files
committed
feat: add template view conditional checks
1 parent a5f5594 commit ea07b1d

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

src/Pages/Applications/DevtronApps/Details/AppConfigurations/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export enum GetTemplateAPIRouteType {
7575
WORKFLOW_LIST = 'workflow/list',
7676
OVERVIEW = 'overview',
7777
README = 'readme',
78+
CD_PIPELINE_LIST = 'cd-pipeline/list',
79+
EXTERNAL_CI_LIST = 'external-ci/list',
80+
EXTERNAL_CI = 'external-ci',
81+
CI_PIPELINE = 'ci-pipeline',
82+
CD_PIPELINE = 'cd-pipeline',
83+
CONFIG_STRATEGY = 'config/strategy',
7884
}
7985

8086
export interface GetTemplateAPIRouteProps {

src/Shared/Components/WorkflowOptionsModal/WorkflowOptionsModal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ const WorkflowOptionsModal = ({
4646
resetChangeCIPayload,
4747
linkedCDSourceVariant,
4848
isAppGroup = false,
49+
getTemplateAPIRoute,
50+
isTemplateView,
4951
}: Readonly<WorkflowOptionsModalProps>) => {
5052
const [currentCIPipelineType, setCurrentCIPipelineType] = useState<CIPipelineNodeType | WorkflowNodeType.WEBHOOK>(
5153
null,
@@ -112,7 +114,10 @@ const WorkflowOptionsModal = ({
112114
if (containsCDPipeline) {
113115
// Only need to disable it in case of error
114116
setLoadingWebhook(true)
115-
saveCDPipeline(getSwitchToWebhookPayload(changeCIPayload))
117+
saveCDPipeline(getSwitchToWebhookPayload(changeCIPayload), {
118+
getTemplateAPIRoute,
119+
isTemplateView,
120+
})
116121
.then((response) => {
117122
if (response.result) {
118123
ToastManager.showToast({

src/Shared/Components/WorkflowOptionsModal/types.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { AppConfigProps, GetTemplateAPIRouteProps } from '@Pages/index'
1718
import { ChangeCIPayloadType, CIPipelineNodeType, WorkflowType } from '@Shared/types'
1819

1920
interface LinkedCDSourceVariant {
@@ -31,7 +32,7 @@ export interface SourceTypeCardProps extends LinkedCDSourceVariant {
3132
isDisabled?: boolean
3233
}
3334

34-
export interface WorkflowOptionsModalProps {
35+
export interface WorkflowOptionsModalProps extends Required<Pick<AppConfigProps, 'isTemplateView'>> {
3536
handleCloseWorkflowOptionsModal: () => void
3637
addCIPipeline: (type: CIPipelineNodeType, workflowId?: number | string) => void
3738
addWebhookCD: (workflowId?: number | string) => void
@@ -44,4 +45,5 @@ export interface WorkflowOptionsModalProps {
4445
getWorkflows?: () => void
4546
linkedCDSourceVariant?: LinkedCDSourceVariant
4647
isAppGroup?: boolean
48+
getTemplateAPIRoute: (props: GetTemplateAPIRouteProps) => string
4749
}

src/Shared/Services/common.service.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* limitations under the License.
1515
*/
1616

17+
import { AppConfigProps, GetTemplateAPIRouteType } from '@Pages/index'
18+
import { WorkflowOptionsModalProps } from '@Shared/Components/WorkflowOptionsModal/types'
1719
import { getUrlWithSearchParams, post, ROUTES } from '../../Common'
1820
import { GetPolicyApiUrlProps, GetResourceApiUrlProps } from './types'
1921

@@ -23,4 +25,21 @@ export const getResourceApiUrl = <T>({ baseUrl, kind, version, suffix, queryPara
2325
export const getPolicyApiUrl = <T>({ kind, version, queryParams, suffix }: GetPolicyApiUrlProps<T>) =>
2426
getUrlWithSearchParams(`global/policy/${kind}/${version}${suffix ? `/${suffix}` : ''}`, queryParams)
2527

26-
export const saveCDPipeline = (request) => post(ROUTES.CD_CONFIG, request)
28+
export const saveCDPipeline = (
29+
request,
30+
{
31+
getTemplateAPIRoute,
32+
isTemplateView,
33+
}: Pick<WorkflowOptionsModalProps, 'getTemplateAPIRoute'> & Required<Pick<AppConfigProps, 'isTemplateView'>>,
34+
) => {
35+
const url = isTemplateView
36+
? getTemplateAPIRoute({
37+
type: GetTemplateAPIRouteType.CD_PIPELINE,
38+
queryParams: {
39+
id: request.appId,
40+
},
41+
})
42+
: ROUTES.CD_CONFIG
43+
44+
return post(url, request)
45+
}

0 commit comments

Comments
 (0)