Skip to content

Commit a7bcf5f

Browse files
committed
feat: DeploymentConfigDiff - logic refactor for resolving deployment template data as per API changes
1 parent 0c15444 commit a7bcf5f

File tree

6 files changed

+48
-119
lines changed

6 files changed

+48
-119
lines changed

src/Shared/Components/CICDHistory/DeploymentHistoryConfigDiff/DeploymentHistoryConfigDiff.tsx

Lines changed: 15 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
import { useMemo, useRef, useState } from 'react'
1+
import { useMemo, useState } from 'react'
22
import { generatePath, Route, Switch, useLocation, useRouteMatch } from 'react-router-dom'
33

4-
import { getAppEnvDeploymentConfigList, getDeploymentTemplateValues } from '@Shared/Components/DeploymentConfigDiff'
4+
import { getAppEnvDeploymentConfigList } from '@Shared/Components/DeploymentConfigDiff'
55
import { useAsync } from '@Common/Helper'
66
import { EnvResourceType, getAppEnvDeploymentConfig } from '@Shared/Services'
77
import { groupArrayByObjectKey } from '@Shared/Helpers'
88
import ErrorScreenManager from '@Common/ErrorScreenManager'
99
import { Progressing } from '@Common/Progressing'
1010
import { useUrlFilters } from '@Common/Hooks'
1111

12-
import { abortPreviousRequests, getIsRequestAborted } from '@Common/Api'
1312
import { DeploymentHistoryConfigDiffCompare } from './DeploymentHistoryConfigDiffCompare'
1413
import { DeploymentHistoryConfigDiffProps, DeploymentHistoryConfigDiffQueryParams } from './types'
1514
import { getPipelineDeploymentsWfrIds, getPipelineDeployments, parseDeploymentHistoryDiffSearchParams } from './utils'
@@ -38,9 +37,6 @@ export const DeploymentHistoryConfigDiff = ({
3837
)
3938
const isPreviousDeploymentConfigAvailable = !!previousWfrId
4039

41-
// REFS
42-
const deploymentTemplateResolvedDataAbortControllerRef = useRef(new AbortController())
43-
4440
// URL FILTERS
4541
const { compareWfrId } = useUrlFilters<string, DeploymentHistoryConfigDiffQueryParams>({
4642
parseSearchParams: parseDeploymentHistoryDiffSearchParams(previousWfrId),
@@ -83,68 +79,13 @@ export const DeploymentHistoryConfigDiff = ({
8379
[currentWfrId, compareWfrId],
8480
)
8581

86-
const [
87-
deploymentTemplateResolvedDataLoader,
88-
deploymentTemplateResolvedData,
89-
deploymentTemplateResolvedDataErr,
90-
reloadDeploymentTemplateResolvedData,
91-
] = useAsync(
92-
() =>
93-
abortPreviousRequests(
94-
() =>
95-
Promise.all([
96-
getAppEnvDeploymentConfig({
97-
params: {
98-
configArea: 'ResolveData',
99-
appName,
100-
envName,
101-
},
102-
payload: {
103-
values: getDeploymentTemplateValues(
104-
compareDeploymentConfig[0].result?.deploymentTemplate,
105-
),
106-
},
107-
signal: deploymentTemplateResolvedDataAbortControllerRef.current?.signal,
108-
}),
109-
getAppEnvDeploymentConfig({
110-
params: {
111-
configArea: 'ResolveData',
112-
appName,
113-
envName,
114-
},
115-
payload: {
116-
values: getDeploymentTemplateValues(
117-
compareDeploymentConfig[1].result?.deploymentTemplate,
118-
),
119-
},
120-
signal: deploymentTemplateResolvedDataAbortControllerRef.current?.signal,
121-
}),
122-
]),
123-
deploymentTemplateResolvedDataAbortControllerRef,
124-
),
125-
[convertVariables, compareDeploymentConfig],
126-
convertVariables && !!compareDeploymentConfig,
127-
)
128-
12982
// METHODS
130-
const reload = () => {
131-
reloadCompareDeploymentConfig()
132-
reloadDeploymentTemplateResolvedData()
133-
}
134-
13583
const getNavItemHref = (resourceType: EnvResourceType, resourceName: string) =>
13684
`${generatePath(path, { ...params })}/${resourceType}${resourceName ? `/${resourceName}` : ''}${search}`
13785

13886
// Generate the deployment history config list
13987
const deploymentConfigList = useMemo(() => {
140-
const isDeploymentTemplateLoaded = !deploymentTemplateResolvedDataLoader && deploymentTemplateResolvedData
141-
const isComparisonDataLoaded = !compareDeploymentConfigLoader && compareDeploymentConfig
142-
143-
const shouldLoadData = convertVariables
144-
? isComparisonDataLoaded && isDeploymentTemplateLoaded
145-
: isComparisonDataLoaded
146-
147-
if (shouldLoadData) {
88+
if (!compareDeploymentConfigLoader && compareDeploymentConfig) {
14889
const compareList = isPreviousDeploymentConfigAvailable
14990
? compareDeploymentConfig[1].result
15091
: {
@@ -160,46 +101,29 @@ export const DeploymentHistoryConfigDiff = ({
160101
compareList,
161102
getNavItemHref,
162103
convertVariables,
163-
...(convertVariables
164-
? {
165-
currentDeploymentTemplateResolvedData: deploymentTemplateResolvedData[0].result,
166-
compareDeploymentTemplateResolvedData: deploymentTemplateResolvedData[1].result,
167-
}
168-
: {}),
169104
})
170105
return configData
171106
}
172107

173108
return null
174-
}, [
175-
isPreviousDeploymentConfigAvailable,
176-
compareDeploymentConfigErr,
177-
compareDeploymentConfig,
178-
convertVariables,
179-
deploymentTemplateResolvedDataLoader,
180-
deploymentTemplateResolvedData,
181-
])
109+
}, [isPreviousDeploymentConfigAvailable, compareDeploymentConfigErr, compareDeploymentConfig, convertVariables])
182110

183111
const groupedDeploymentConfigList = useMemo(
184112
() => (deploymentConfigList ? groupArrayByObjectKey(deploymentConfigList.configList, 'groupHeader') : []),
185113
[deploymentConfigList],
186114
)
187115

188-
const isLoading = compareDeploymentConfigLoader || deploymentTemplateResolvedDataLoader
189-
const isError =
190-
compareDeploymentConfigErr ||
191-
(deploymentTemplateResolvedDataErr && !getIsRequestAborted(deploymentTemplateResolvedDataErr))
192-
116+
const isLoading = compareDeploymentConfigLoader || (!compareDeploymentConfigErr && !deploymentConfigList)
193117
return (
194118
<Switch>
195119
<Route path={`${path}/:resourceType(${Object.values(EnvResourceType).join('|')})/:resourceName?`}>
196120
<DeploymentHistoryConfigDiffCompare
197121
{...deploymentConfigList}
198-
isLoading={isLoading || (!isError && !deploymentConfigList)}
122+
isLoading={isLoading}
199123
errorConfig={{
200-
code: compareDeploymentConfigErr?.code || deploymentTemplateResolvedDataErr?.code,
201-
error: isError && !isLoading,
202-
reload,
124+
code: compareDeploymentConfigErr?.code,
125+
error: compareDeploymentConfigErr && !compareDeploymentConfigLoader,
126+
reload: reloadCompareDeploymentConfig,
203127
}}
204128
envName={envName}
205129
wfrId={wfrId}
@@ -214,11 +138,14 @@ export const DeploymentHistoryConfigDiff = ({
214138
/>
215139
</Route>
216140
<Route>
217-
{isError && !isLoading ? (
218-
<ErrorScreenManager code={compareDeploymentConfigErr?.code} reload={reload} />
141+
{compareDeploymentConfigErr && !compareDeploymentConfigLoader ? (
142+
<ErrorScreenManager
143+
code={compareDeploymentConfigErr?.code}
144+
reload={reloadCompareDeploymentConfig}
145+
/>
219146
) : (
220147
<div className="p-16 flexbox-col dc__gap-16 bcn-0 h-100">
221-
{isLoading || (!isError && !deploymentConfigList) ? (
148+
{isLoading ? (
222149
<Progressing fullHeight size={48} />
223150
) : (
224151
<>

src/Shared/Components/CICDHistory/DeploymentHistoryConfigDiff/DeploymentHistoryDiffView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const DeploymentHistoryDiffView = ({
8686

8787
const renderDeploymentDiffViaCodeEditor = () => (
8888
<CodeEditor
89-
key={`${sortBy}-${sortOrder}`}
89+
key={JSON.stringify(editorValuesLHS)}
9090
value={editorValuesRHS}
9191
defaultValue={editorValuesLHS}
9292
adjustEditorHeightToContent

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,4 @@ export type AppEnvDeploymentConfigListParams<IsManifestView> = (IsManifestView e
151151
getNavItemHref: (resourceType: EnvResourceType, resourceName: string) => string
152152
isManifestView?: IsManifestView
153153
convertVariables?: boolean
154-
currentDeploymentTemplateResolvedData?: AppEnvDeploymentConfigDTO
155-
compareDeploymentTemplateResolvedData?: AppEnvDeploymentConfigDTO
156154
}

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.utils.tsx

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -515,20 +515,42 @@ const getConfigMapSecretData = (
515515
return deploymentConfig
516516
}
517517

518+
const getDeploymentTemplateResolvedData = (deploymentTemplate: DeploymentTemplateDTO) => {
519+
try {
520+
if (deploymentTemplate.deploymentDraftData) {
521+
return JSON.parse(deploymentTemplate.deploymentDraftData.configData[0].draftMetadata.draftResolvedValue)
522+
}
523+
return deploymentTemplate.resolvedValue
524+
} catch {
525+
return null
526+
}
527+
}
528+
518529
const getConfigDataWithResolvedDeploymentTemplate = (
519-
data: AppEnvDeploymentConfigListParams<false>['currentList'],
520-
resolvedData: AppEnvDeploymentConfigListParams<false>['currentDeploymentTemplateResolvedData'],
521-
) =>
522-
data && resolvedData?.deploymentTemplate
530+
data: AppEnvDeploymentConfigListParams<false>['compareList'],
531+
convertVariables: boolean,
532+
) => {
533+
if (!data.deploymentTemplate) {
534+
return data
535+
}
536+
537+
const deploymentTemplateResolvedData = getDeploymentTemplateResolvedData(data.deploymentTemplate)
538+
539+
return convertVariables
523540
? {
524541
...data,
525542
deploymentTemplate: {
526543
...data.deploymentTemplate,
527-
deploymentDraftData: null,
528-
data: resolvedData.deploymentTemplate.resolvedValue,
544+
...(deploymentTemplateResolvedData
545+
? {
546+
data: deploymentTemplateResolvedData,
547+
deploymentDraftData: null,
548+
}
549+
: {}),
529550
},
530551
}
531552
: data
553+
}
532554

533555
/**
534556
* Generates a list of deployment configurations for application environments and identifies changes between the current and compare lists.
@@ -548,8 +570,6 @@ export const getAppEnvDeploymentConfigList = <ManifestView extends boolean = fal
548570
getNavItemHref,
549571
isManifestView,
550572
convertVariables = false,
551-
currentDeploymentTemplateResolvedData,
552-
compareDeploymentTemplateResolvedData,
553573
}: AppEnvDeploymentConfigListParams<ManifestView>): {
554574
configList: DeploymentConfigDiffProps['configList']
555575
navList: DeploymentConfigDiffProps['navList']
@@ -558,11 +578,11 @@ export const getAppEnvDeploymentConfigList = <ManifestView extends boolean = fal
558578
if (!isManifestView) {
559579
const compareToObject = getConfigDataWithResolvedDeploymentTemplate(
560580
currentList as AppEnvDeploymentConfigListParams<false>['currentList'],
561-
currentDeploymentTemplateResolvedData,
581+
convertVariables,
562582
)
563583
const compareWithObject = getConfigDataWithResolvedDeploymentTemplate(
564584
compareList as AppEnvDeploymentConfigListParams<false>['compareList'],
565-
compareDeploymentTemplateResolvedData,
585+
convertVariables,
566586
)
567587
const currentDeploymentData = getDeploymentTemplateDiffViewData(compareToObject.deploymentTemplate)
568588
const compareDeploymentData = getDeploymentTemplateDiffViewData(compareWithObject.deploymentTemplate)
@@ -736,15 +756,6 @@ export const getAppEnvDeploymentConfigList = <ManifestView extends boolean = fal
736756
}
737757
}
738758

739-
export const getDeploymentTemplateValues = (deploymentTemplate: DeploymentTemplateDTO) => {
740-
try {
741-
const data = getDeploymentTemplateData(deploymentTemplate)
742-
return JSON.stringify(data)
743-
} catch {
744-
return null
745-
}
746-
}
747-
748759
export const getDefaultVersionAndPreviousDeploymentOptions = (data: TemplateListDTO[]) =>
749760
data.reduce<{ previousDeployments: TemplateListDTO[]; defaultVersions: TemplateListDTO[] }>(
750761
(acc, curr) => ({

src/Shared/Services/app.service.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { ROUTES, ResponseType, get, getUrlWithSearchParams, post, showError } from '../../Common'
17+
import { ROUTES, ResponseType, get, getUrlWithSearchParams, showError } from '../../Common'
1818
import {
1919
CIMaterialInfoDTO,
2020
CIMaterialInfoType,
@@ -57,11 +57,9 @@ export const getArtifactInfo = async (
5757

5858
export const getAppEnvDeploymentConfig = ({
5959
params,
60-
payload,
6160
signal,
6261
}: {
6362
params: AppEnvDeploymentConfigPayloadType
64-
payload?: { values: string }
6563
signal?: AbortSignal
6664
}): Promise<ResponseType<AppEnvDeploymentConfigDTO>> =>
67-
post(getUrlWithSearchParams(ROUTES.CONFIG_DATA, params), payload, { signal })
65+
get(getUrlWithSearchParams(ROUTES.CONFIG_DATA, params), { signal })

src/Shared/Services/app.types.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,6 @@ export type AppEnvDeploymentConfigPayloadType =
252252
resourceName?: string
253253
configArea?: 'AppConfiguration'
254254
}
255-
| {
256-
appName: string
257-
envName: string
258-
configArea: 'ResolveData'
259-
}
260255
| {
261256
appName: string
262257
envName: string

0 commit comments

Comments
 (0)