Skip to content

Commit f390085

Browse files
committed
feat: add runtime params
1 parent ee88a9e commit f390085

File tree

9 files changed

+392
-58
lines changed

9 files changed

+392
-58
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"homepage": "/dashboard",
66
"dependencies": {
7-
"@devtron-labs/devtron-fe-common-lib": "0.0.65",
7+
"@devtron-labs/devtron-fe-common-lib": "0.0.66-beta-3",
88
"@esbuild-plugins/node-globals-polyfill": "0.2.3",
99
"@rjsf/core": "^5.13.3",
1010
"@rjsf/utils": "^5.13.3",

src/components/ApplicationGroup/AppGroup.types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
CDModalTabType,
33
DeploymentNodeType,
44
FilterConditionsListType,
5+
KeyValueListType,
56
ResponseType,
67
UserApprovalConfigType,
78
WorkflowNodeType,
@@ -85,6 +86,8 @@ export interface BulkCITriggerType {
8586
responseList: ResponseRowType[]
8687
isLoading: boolean
8788
setLoading: React.Dispatch<React.SetStateAction<boolean>>
89+
runtimeParams: Record<string, KeyValueListType[]>
90+
setRuntimeParams: React.Dispatch<React.SetStateAction<Record<string, KeyValueListType[]>>>
8891
}
8992

9093
export interface BulkCDTriggerType {

src/components/ApplicationGroup/Details/TriggerView/BulkCITrigger.tsx

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
ConsequenceAction,
1111
useAsync,
1212
GenericEmptyState,
13+
KeyValueListType,
14+
KeyValueListActionType,
15+
HandleKeyValueChangeType,
16+
CIMaterialSidebarType,
1317
} from '@devtron-labs/devtron-fe-common-lib'
1418
import Tippy from '@tippyjs/react'
1519
import { importComponentFromFELibrary } from '../../../common'
@@ -42,6 +46,8 @@ import { getIsAppUnorthodox } from './utils'
4246

4347
const PolicyEnforcementMessage = importComponentFromFELibrary('PolicyEnforcementMessage')
4448
const getCIBlockState = importComponentFromFELibrary('getCIBlockState', null, 'function')
49+
const getRuntimeParams = importComponentFromFELibrary('getRuntimeParams', null, 'function')
50+
const GitInfoMaterialTabs = importComponentFromFELibrary('GitInfoMaterialTabs', null, 'function')
4551

4652
export default function BulkCITrigger({
4753
appList,
@@ -57,13 +63,16 @@ export default function BulkCITrigger({
5763
responseList,
5864
isLoading,
5965
setLoading,
66+
runtimeParams,
67+
setRuntimeParams,
6068
}: BulkCITriggerType) {
6169
const [showRegexModal, setShowRegexModal] = useState(false)
6270
const [isChangeBranchClicked, setChangeBranchClicked] = useState(false)
6371
const [regexValue, setRegexValue] = useState<Record<number, RegexValueType>>({})
6472
const [appIgnoreCache, setAppIgnoreCache] = useState<Record<number, boolean>>({})
6573
const [appPolicy, setAppPolicy] = useState<Record<number, ConsequenceType>>({})
6674
const [selectedApp, setSelectedApp] = useState<BulkCIDetailType>(appList[0])
75+
const [currentSidebarTab, setCurrentSidebarTab] = useState<string>(CIMaterialSidebarType.CODE_SOURCE)
6776

6877
const [blobStorageConfigurationLoading, blobStorageConfiguration] = useAsync(
6978
() => getModuleConfigured(ModuleNameMap.BLOB_STORAGE),
@@ -143,6 +152,9 @@ export default function BulkCITrigger({
143152
if (getCIBlockState) {
144153
getPolicyEnforcementData(_materialListMap)
145154
}
155+
if (getRuntimeParams) {
156+
getRunTimeParamsData(_materialListMap)
157+
}
146158
updateBulkInputMaterial(_materialListMap)
147159
if (!getIsAppUnorthodox(selectedApp)) {
148160
setShowRegexModal(
@@ -166,6 +178,68 @@ export default function BulkCITrigger({
166178
}
167179
}
168180

181+
const handleRuntimeParametersChange = ({ action, data }: HandleKeyValueChangeType) => {
182+
let _runtimeParams = runtimeParams[selectedApp.ciPipelineId] ?? []
183+
184+
switch (action) {
185+
case KeyValueListActionType.ADD:
186+
_runtimeParams.unshift({ key: '', value: '' })
187+
break
188+
189+
case KeyValueListActionType.UPDATE_KEY:
190+
_runtimeParams[data.index].key = data.value
191+
break
192+
193+
case KeyValueListActionType.UPDATE_VALUE:
194+
_runtimeParams[data.index].value = data.value
195+
break
196+
197+
case KeyValueListActionType.DELETE:
198+
_runtimeParams = _runtimeParams.filter((_, index) => index !== data.index)
199+
break
200+
}
201+
202+
setRuntimeParams({
203+
...runtimeParams,
204+
[selectedApp.ciPipelineId]: _runtimeParams,
205+
})
206+
}
207+
208+
const handleSidebarTabChange = (e: React.ChangeEvent<HTMLInputElement>) => {
209+
setCurrentSidebarTab(e.target.value as CIMaterialSidebarType)
210+
}
211+
212+
const getRunTimeParamsData = (_materialListMap: Record<string, any[]>): void => {
213+
const runTimeParamsPromiseList = appList.map((appDetails) => {
214+
if (getIsAppUnorthodox(appDetails) || !_materialListMap[appDetails.appId]) {
215+
return {
216+
[appDetails.ciPipelineId]: [],
217+
}
218+
}
219+
return getRuntimeParams(appDetails.ciPipelineId)
220+
})
221+
222+
if (runTimeParamsPromiseList?.length) {
223+
Promise.allSettled(runTimeParamsPromiseList)
224+
.then((responses) => {
225+
const _runtimeParams: Record<string, KeyValueListType[]> = {}
226+
responses.forEach((res, index) => {
227+
if (res.status === 'fulfilled') {
228+
_runtimeParams[appList[index]?.ciPipelineId] = res?.['value'] || []
229+
}
230+
else {
231+
// TODO: Add null
232+
_runtimeParams[appList[index]?.ciPipelineId] = []
233+
}
234+
})
235+
setRuntimeParams(_runtimeParams)
236+
})
237+
.catch((error) => {
238+
showError(error)
239+
})
240+
}
241+
}
242+
169243
const getPolicyEnforcementData = (_materialListMap: Record<string, any[]>): void => {
170244
const policyPromiseList = appList.map((appDetails) => {
171245
if (getIsAppUnorthodox(appDetails) || !_materialListMap[appDetails.appId]) {
@@ -398,6 +472,11 @@ export default function BulkCITrigger({
398472
isCITriggerBlocked={appPolicy[selectedApp.appId]?.action === ConsequenceAction.BLOCK}
399473
ciBlockState={appPolicy[selectedApp.appId]}
400474
isJobCI={selectedApp.isJobCI}
475+
currentSidebarTab={currentSidebarTab}
476+
handleSidebarTabChange={handleSidebarTabChange}
477+
runtimeParams={runtimeParams[selectedApp.ciPipelineId] || []}
478+
handleRuntimeParametersChange={handleRuntimeParametersChange}
479+
appName={selectedApp?.name}
401480
/>
402481
)
403482
}
@@ -525,6 +604,11 @@ export default function BulkCITrigger({
525604
return <Progressing pageLoader />
526605
}
527606
const selectedMaterialList = appList.find((app) => app.appId === selectedApp.appId)?.material || []
607+
const sidebarTabs = Object.values(CIMaterialSidebarType).map((tabValue)=>({
608+
value: tabValue,
609+
label: tabValue,
610+
}))
611+
528612
return (
529613
<div className={`bulk-ci-trigger ${showWebhookModal ? 'webhook-modal' : ''}`}>
530614
{!showWebhookModal && (
@@ -533,8 +617,17 @@ export default function BulkCITrigger({
533617
className="dc__position-sticky dc__top-0 bcn-0 dc__border-bottom fw-6 fs-13 cn-9 p-12 "
534618
style={{ zIndex: 1 }}
535619
>
536-
Applications
620+
{GitInfoMaterialTabs ? (
621+
<GitInfoMaterialTabs
622+
tabs={sidebarTabs}
623+
initialTab={currentSidebarTab}
624+
onChange={handleSidebarTabChange}
625+
/>
626+
) : (
627+
'Applications'
628+
)}
537629
</div>
630+
538631
{appList.map((app, index) => (
539632
<div
540633
className={`material-list pr-12 pl-12 pb-12 ${

src/components/ApplicationGroup/Details/TriggerView/EnvTriggerView.tsx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import {
1515
CHECKBOX_VALUE,
1616
VisibleModal,
1717
WorkflowNodeType,
18+
KeyValueListType,
19+
HandleKeyValueChangeType,
20+
KeyValueListActionType,
1821
} from '@devtron-labs/devtron-fe-common-lib'
1922
import { toast } from 'react-toastify'
2023
import Tippy from '@tippyjs/react'
@@ -84,9 +87,11 @@ import GitCommitInfoGeneric from '../../../common/GitCommitInfoGeneric'
8487
import { getDefaultConfig } from '../../../notifications/notifications.service'
8588
import BulkSourceChange from './BulkSourceChange'
8689
import { CIPipelineBuildType } from '../../../ciPipeline/types'
90+
import { validateAndGetValidRuntimeParams } from '../../../app/details/triggerView/TriggerView.utils'
8791

8892
const ApprovalMaterialModal = importComponentFromFELibrary('ApprovalMaterialModal')
8993
const getCIBlockState = importComponentFromFELibrary('getCIBlockState', null, 'function')
94+
const getRuntimeParams = importComponentFromFELibrary('getRuntimeParams', null, 'function')
9095

9196
// FIXME: IN CIMaterials we are sending isCDLoading while in CD materials we are sending isCILoading
9297
let inprogressStatusTimer
@@ -130,6 +135,8 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
130135
const [selectAllValue, setSelectAllValue] = useState<CHECKBOX_VALUE>(CHECKBOX_VALUE.CHECKED)
131136
const [isConfigPresent, setConfigPresent] = useState<boolean>(false)
132137
const [isDefaultConfigPresent, setDefaultConfig] = useState<boolean>(false)
138+
// Mapping pipelineId to runtime params
139+
const [runtimeParams, setRuntimeParams] = useState<Record<string, KeyValueListType[]>>({})
133140

134141
// ref to make sure that on initial mount after we fetch workflows we handle modal based on url
135142
const handledLocation = useRef(false)
@@ -767,6 +774,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
767774
getBranchValues(ciNodeId, filteredWorkflows, filteredCIPipelines.get(_appID)),
768775
)
769776
: { result: null },
777+
getRuntimeParams ? getRuntimeParams(ciNodeId) : null,
770778
])
771779
.then((resp) => {
772780
// need to set result for getCIBlockState call only as for updateCIMaterialList
@@ -786,11 +794,18 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
786794
})
787795
setFilteredWorkflows(workflows)
788796
}
797+
798+
if (resp[2]) {
799+
setRuntimeParams({
800+
[ciNodeId]: resp[2],
801+
})
802+
}
789803
})
790804
.catch((errors: ServerErrors) => {
791805
if (!abortControllerRef.current.signal.aborted) {
792806
showError(errors)
793807
setErrorCode(errors.code)
808+
setPageViewType(ViewType.ERROR)
794809
}
795810
})
796811
.finally(() => {
@@ -947,11 +962,22 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
947962
return
948963
}
949964

965+
const runtimeParamsValidationResponse = validateAndGetValidRuntimeParams(
966+
runtimeParams?.[selectedCINode?.id] ?? [],
967+
)
968+
969+
if (!runtimeParamsValidationResponse.isValid) {
970+
setCDLoading(false)
971+
toast.error(runtimeParamsValidationResponse.message)
972+
return
973+
}
974+
950975
const payload = {
951976
pipelineId: +selectedCINode.id,
952977
ciPipelineMaterials,
953978
invalidateCache,
954979
pipelineType: node.isJobCI ? CIPipelineBuildType.CI_JOB : CIPipelineBuildType.CI_BUILD,
980+
...(!node.isJobCI ? { runtimeParams: runtimeParamsValidationResponse.validParams } : {}),
955981
}
956982

957983
triggerCINode(payload)
@@ -1132,6 +1158,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
11321158
preventBodyScroll(false)
11331159
setShowCIModal(false)
11341160
setShowMaterialRegexModal(false)
1161+
setRuntimeParams({})
11351162
}
11361163

11371164
const closeCDModal = (e: React.MouseEvent): void => {
@@ -1198,6 +1225,7 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
11981225
setCDLoading(false)
11991226
setShowBulkCDModal(false)
12001227
setResponseList([])
1228+
setRuntimeParams({})
12011229

12021230
history.push({
12031231
search: '',
@@ -1521,11 +1549,22 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
15211549
})
15221550
}
15231551

1552+
const runtimeParamsValidationResponse = validateAndGetValidRuntimeParams(
1553+
runtimeParams?.[selectedCINode?.id] ?? [],
1554+
)
1555+
if (!runtimeParamsValidationResponse.isValid) {
1556+
setCDLoading(false)
1557+
setCILoading(false)
1558+
toast.error(runtimeParamsValidationResponse.message)
1559+
return
1560+
}
1561+
15241562
const payload = {
15251563
pipelineId: +node.id,
15261564
ciPipelineMaterials,
15271565
invalidateCache: appIgnoreCache[+node.id],
15281566
pipelineType: node.isJobCI ? CIPipelineBuildType.CI_JOB : CIPipelineBuildType.CI_BUILD,
1567+
...(!node.isJobCI ? { runtimeParams: runtimeParamsValidationResponse?.validParams } : {}),
15291568
}
15301569
_CITriggerPromiseList.push(triggerCINode(payload))
15311570
})
@@ -1666,6 +1705,35 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
16661705
return errorMessage
16671706
}
16681707

1708+
/**
1709+
* For CI Material only since don't have selectedApp here
1710+
*/
1711+
const handleRuntimeParametersChange = ({ action, data }: HandleKeyValueChangeType) => {
1712+
let _runtimeParams = selectedCINode?.id ? runtimeParams[selectedCINode.id] : []
1713+
1714+
switch (action) {
1715+
case KeyValueListActionType.ADD:
1716+
_runtimeParams.unshift({ key: '', value: '' })
1717+
break
1718+
1719+
case KeyValueListActionType.UPDATE_KEY:
1720+
_runtimeParams[data.index].key = data.value
1721+
break
1722+
1723+
case KeyValueListActionType.UPDATE_VALUE:
1724+
_runtimeParams[data.index].value = data.value
1725+
break
1726+
1727+
case KeyValueListActionType.DELETE:
1728+
_runtimeParams = _runtimeParams.filter((_, index) => index !== data.index)
1729+
break
1730+
}
1731+
1732+
if (selectedCINode?.id) {
1733+
setRuntimeParams({ [selectedCINode.id]: _runtimeParams })
1734+
}
1735+
}
1736+
16691737
const createBulkCITriggerData = (): BulkCIDetailType[] => {
16701738
const _selectedAppWorkflowList: BulkCIDetailType[] = []
16711739
filteredWorkflows.forEach((wf) => {
@@ -1818,6 +1886,8 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
18181886
isCITriggerBlocked={nd?.isCITriggerBlocked}
18191887
ciBlockState={nd?.ciBlockState}
18201888
isJobCI={!!nd?.isJobCI}
1889+
runtimeParams={runtimeParams[nd?.id] ?? []}
1890+
handleRuntimeParametersChange={handleRuntimeParametersChange}
18211891
/>
18221892
)}
18231893
</div>
@@ -1875,6 +1945,8 @@ export default function EnvTriggerView({ filteredAppIds, isVirtualEnv }: AppGrou
18751945
responseList={responseList}
18761946
isLoading={isCILoading}
18771947
setLoading={setCILoading}
1948+
runtimeParams={runtimeParams}
1949+
setRuntimeParams={setRuntimeParams}
18781950
/>
18791951
)
18801952
}

0 commit comments

Comments
 (0)