Skip to content

Commit 62b55ec

Browse files
committed
fix: DeploymentHistoryConfigDiffCompare - not able to see previous pipeline deployments after the initial load fix
1 parent b3e590a commit 62b55ec

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

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

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect } from 'react'
1+
import { useEffect, useState } from 'react'
22
import { generatePath, useRouteMatch } from 'react-router-dom'
33

44
import { DeploymentConfigDiff, DeploymentConfigDiffProps } from '@Shared/Components/DeploymentConfigDiff'
@@ -16,25 +16,28 @@ import {
1616
DeploymentHistoryConfigDiffQueryParams,
1717
DeploymentHistoryConfigDiffRouteParams,
1818
} from './types'
19-
import { getPipelineDeploymentsOptions, parseDeploymentHistoryDiffSearchParams } from './utils'
19+
import { getPipelineDeployments, getPipelineDeploymentsOptions, parseDeploymentHistoryDiffSearchParams } from './utils'
20+
import { getTriggerHistory } from '../service'
21+
22+
const paginationSize = 20
2023

2124
export const DeploymentHistoryConfigDiffCompare = ({
2225
envName,
2326
setFullScreenView,
24-
pipelineDeployments,
27+
pipelineDeployments: initialPipelineDeployments,
2528
wfrId,
2629
previousWfrId,
2730
convertVariables,
2831
setConvertVariables,
29-
triggerHistory,
32+
triggerHistory: initialTriggerHistory,
3033
renderRunSource,
3134
resourceId,
3235
isCompareDeploymentConfigNotAvailable,
3336
...props
3437
}: DeploymentHistoryDiffDetailedProps) => {
3538
// HOOKS
3639
const { path, params } = useRouteMatch<DeploymentHistoryConfigDiffRouteParams>()
37-
const { resourceType, resourceName } = params
40+
const { resourceType, resourceName, appId, envId } = params
3841

3942
// URL FILTERS
4043
const { compareWfrId, updateSearchParams, sortBy, sortOrder, handleSorting } = useUrlFilters<
@@ -44,6 +47,14 @@ export const DeploymentHistoryConfigDiffCompare = ({
4447
parseSearchParams: parseDeploymentHistoryDiffSearchParams(previousWfrId),
4548
})
4649

50+
// STATES
51+
const [triggerHistory, setTriggerHistory] = useState({
52+
isLoading: false,
53+
data: initialTriggerHistory,
54+
hasMore: initialTriggerHistory.size === paginationSize,
55+
})
56+
const [pipelineDeployments, setPipelineDeployments] = useState(initialPipelineDeployments)
57+
4758
useEffect(() => {
4859
// Default Search Params Update
4960
updateSearchParams({ compareWfrId })
@@ -56,11 +67,37 @@ export const DeploymentHistoryConfigDiffCompare = ({
5667
}
5768
}, [])
5869

70+
// METHODS
71+
const fetchDeploymentHistory = async (paginationOffset: number) => {
72+
setTriggerHistory({ ...triggerHistory, isLoading: true })
73+
74+
try {
75+
const { result } = await getTriggerHistory({
76+
appId: +appId,
77+
envId: +envId,
78+
pagination: { offset: paginationOffset, size: paginationSize },
79+
})
80+
const nextTriggerHistory = new Map((result.cdWorkflows || []).map((item) => [item.id, item]))
81+
const updatedTriggerHistory = new Map([...triggerHistory.data, ...nextTriggerHistory])
82+
83+
setTriggerHistory({
84+
isLoading: false,
85+
data: updatedTriggerHistory,
86+
hasMore: result.cdWorkflows?.length === paginationSize,
87+
})
88+
setPipelineDeployments(getPipelineDeployments(updatedTriggerHistory))
89+
} catch {
90+
setTriggerHistory({ ...triggerHistory, isLoading: false })
91+
}
92+
}
93+
94+
const handleLoadMore = () => fetchDeploymentHistory(triggerHistory.data.size)
95+
5996
// DEPLOYMENT_CONFIG_DIFF_PROPS
6097
const { currentDeployment, pipelineDeploymentsOptions } = getPipelineDeploymentsOptions({
6198
pipelineDeployments,
6299
wfrId,
63-
triggerHistory,
100+
triggerHistory: triggerHistory.data,
64101
renderRunSource,
65102
resourceId,
66103
})
@@ -88,6 +125,11 @@ export const DeploymentHistoryConfigDiffCompare = ({
88125
onChange: deploymentSelectorOnChange,
89126
showSelectedOptionIcon: false,
90127
menuSize: ComponentSizeType.large,
128+
loadMoreButtonConfig: {
129+
show: triggerHistory.hasMore,
130+
isLoading: triggerHistory.isLoading,
131+
onClick: handleLoadMore,
132+
},
91133
},
92134
},
93135
]

src/Shared/Components/CICDHistory/DeploymentHistoryConfigDiff/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ export interface DeploymentHistoryConfigDiffQueryParams {
3737
}
3838

3939
export interface DeploymentHistoryConfigDiffRouteParams {
40+
appId: string
41+
envId: string
4042
resourceType: EnvResourceType
4143
resourceName: string
4244
}

0 commit comments

Comments
 (0)