1- import { useMemo , useRef , useState } from 'react'
1+ import { useMemo , useState } from 'react'
22import { 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'
55import { useAsync } from '@Common/Helper'
66import { EnvResourceType , getAppEnvDeploymentConfig } from '@Shared/Services'
77import { groupArrayByObjectKey } from '@Shared/Helpers'
88import ErrorScreenManager from '@Common/ErrorScreenManager'
99import { Progressing } from '@Common/Progressing'
1010import { useUrlFilters } from '@Common/Hooks'
1111
12- import { abortPreviousRequests , getIsRequestAborted } from '@Common/Api'
1312import { DeploymentHistoryConfigDiffCompare } from './DeploymentHistoryConfigDiffCompare'
1413import { DeploymentHistoryConfigDiffProps , DeploymentHistoryConfigDiffQueryParams } from './types'
1514import { 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 < >
0 commit comments