Skip to content

Commit 95606a3

Browse files
committed
feat: add runtime params on CDMaterial service
1 parent 9208f06 commit 95606a3

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/Common/Common.service.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616

1717
import moment from 'moment'
18+
import { RuntimeParamsAPIResponseType } from '@Shared/types'
19+
import { stringComparatorBySortOrder } from '@Shared/Helpers'
1820
import { get, post } from './Api'
1921
import { ROUTES } from './Constants'
2022
import { getUrlWithSearchParams, sortCallback } from './Helper'
@@ -80,7 +82,13 @@ export function setImageTags(request, pipelineId: number, artifactId: number) {
8082
return post(`${ROUTES.IMAGE_TAGGING}/${pipelineId}/${artifactId}`, request)
8183
}
8284

83-
const cdMaterialListModal = (artifacts: any[], offset: number, artifactId?: number, artifactStatus?: string, disableDefaultSelection?: boolean) => {
85+
const cdMaterialListModal = (
86+
artifacts: any[],
87+
offset: number,
88+
artifactId?: number,
89+
artifactStatus?: string,
90+
disableDefaultSelection?: boolean,
91+
) => {
8492
if (!artifacts || !artifacts.length) return []
8593

8694
const markFirstSelected = offset === 0
@@ -185,6 +193,11 @@ const processCDMaterialsApprovalInfo = (enableApproval: boolean, cdMaterialsResu
185193
}
186194
}
187195

196+
export const parseRuntimeParams = (response: RuntimeParamsAPIResponseType) =>
197+
Object.entries(response?.envVariables || {})
198+
.map(([key, value], index) => ({ key, value, id: index }))
199+
.sort((a, b) => stringComparatorBySortOrder(a.key, b.key))
200+
188201
const processCDMaterialsMetaInfo = (cdMaterialsResult): CDMaterialsMetaInfo => {
189202
if (!cdMaterialsResult) {
190203
return {
@@ -194,6 +207,7 @@ const processCDMaterialsMetaInfo = (cdMaterialsResult): CDMaterialsMetaInfo => {
194207
resourceFilters: [],
195208
totalCount: 0,
196209
requestedUserId: 0,
210+
runtimeParams: [],
197211
}
198212
}
199213

@@ -204,6 +218,8 @@ const processCDMaterialsMetaInfo = (cdMaterialsResult): CDMaterialsMetaInfo => {
204218
resourceFilters: cdMaterialsResult.resourceFilters ?? [],
205219
totalCount: cdMaterialsResult.totalCount ?? 0,
206220
requestedUserId: cdMaterialsResult.requestedUserId,
221+
// TODO: Get this casing fixed from API
222+
runtimeParams: parseRuntimeParams(cdMaterialsResult.runtime_params),
207223
}
208224
}
209225

@@ -366,8 +382,8 @@ export const getResourceGroupListRaw = (clusterId: string): Promise<ResponseType
366382
}
367383

368384
export function getNamespaceListMin(clusterIdsCsv: string): Promise<EnvironmentListHelmResponse> {
369-
const URL = `${ROUTES.NAMESPACE}/autocomplete?ids=${clusterIdsCsv}`
370-
return get(URL)
385+
const URL = `${ROUTES.NAMESPACE}/autocomplete?ids=${clusterIdsCsv}`
386+
return get(URL)
371387
}
372388
export function getWebhookEventsForEventId(eventId: string | number) {
373389
const URL = `${ROUTES.GIT_HOST_EVENT}/${eventId}`

src/Common/Types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React, { ReactNode, CSSProperties } from 'react'
1818
import { Placement } from 'tippy.js'
1919
import { ImageComment, ReleaseTag } from './ImageTags.Types'
2020
import { ACTION_STATE, DEPLOYMENT_WINDOW_TYPE, DockerConfigOverrideType, SortingOrder, TaskErrorObj } from '.'
21-
import { RegistryType } from '../Shared'
21+
import { RegistryType, RuntimeParamsListItemType } from '../Shared'
2222

2323
/**
2424
* Generic response type object with support for overriding the result type
@@ -629,6 +629,7 @@ export interface CDMaterialsMetaInfo {
629629
* This is the ID of user that has request the material
630630
*/
631631
requestedUserId: number
632+
runtimeParams: RuntimeParamsListItemType[]
632633
}
633634

634635
export interface ImagePromotionMaterialInfo {

src/Shared/types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
ServerErrors,
2525
SortingParams,
2626
} from '../Common'
27+
import { KeyValueListType } from './Components'
2728
import { EnvironmentTypeEnum, PatchOperationType } from './constants'
2829

2930
export enum EnvType {
@@ -340,6 +341,11 @@ export enum CIMaterialSidebarType {
340341
PARAMETERS = 'Parameters',
341342
}
342343

344+
export enum CDMaterialSidebarType {
345+
IMAGE = 'Image',
346+
PARAMETERS = 'Parameters',
347+
}
348+
343349
/**
344350
* @example Usage with specific enum for path & `unknown` type for value
345351
* ```ts
@@ -650,3 +656,12 @@ export type BaseFilterQueryParams<T> = {
650656
*/
651657
showAll?: boolean
652658
} & SortingParams<T>
659+
660+
export interface RuntimeParamsListItemType extends KeyValueListType {
661+
id: number
662+
}
663+
664+
export enum RuntimeParamsHeadingType {
665+
KEY = 'Key',
666+
VALUE = 'Value',
667+
}

0 commit comments

Comments
 (0)