1
- import { useEffect } from 'react'
1
+ import { useEffect , useState } from 'react'
2
2
import { generatePath , useRouteMatch } from 'react-router-dom'
3
3
4
4
import { DeploymentConfigDiff , DeploymentConfigDiffProps } from '@Shared/Components/DeploymentConfigDiff'
@@ -16,25 +16,28 @@ import {
16
16
DeploymentHistoryConfigDiffQueryParams ,
17
17
DeploymentHistoryConfigDiffRouteParams ,
18
18
} 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
20
23
21
24
export const DeploymentHistoryConfigDiffCompare = ( {
22
25
envName,
23
26
setFullScreenView,
24
- pipelineDeployments,
27
+ pipelineDeployments : initialPipelineDeployments ,
25
28
wfrId,
26
29
previousWfrId,
27
30
convertVariables,
28
31
setConvertVariables,
29
- triggerHistory,
32
+ triggerHistory : initialTriggerHistory ,
30
33
renderRunSource,
31
34
resourceId,
32
35
isCompareDeploymentConfigNotAvailable,
33
36
...props
34
37
} : DeploymentHistoryDiffDetailedProps ) => {
35
38
// HOOKS
36
39
const { path, params } = useRouteMatch < DeploymentHistoryConfigDiffRouteParams > ( )
37
- const { resourceType, resourceName } = params
40
+ const { resourceType, resourceName, appId , envId } = params
38
41
39
42
// URL FILTERS
40
43
const { compareWfrId, updateSearchParams, sortBy, sortOrder, handleSorting } = useUrlFilters <
@@ -44,6 +47,14 @@ export const DeploymentHistoryConfigDiffCompare = ({
44
47
parseSearchParams : parseDeploymentHistoryDiffSearchParams ( previousWfrId ) ,
45
48
} )
46
49
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
+
47
58
useEffect ( ( ) => {
48
59
// Default Search Params Update
49
60
updateSearchParams ( { compareWfrId } )
@@ -56,11 +67,37 @@ export const DeploymentHistoryConfigDiffCompare = ({
56
67
}
57
68
} , [ ] )
58
69
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
+
59
96
// DEPLOYMENT_CONFIG_DIFF_PROPS
60
97
const { currentDeployment, pipelineDeploymentsOptions } = getPipelineDeploymentsOptions ( {
61
98
pipelineDeployments,
62
99
wfrId,
63
- triggerHistory,
100
+ triggerHistory : triggerHistory . data ,
64
101
renderRunSource,
65
102
resourceId,
66
103
} )
@@ -88,6 +125,11 @@ export const DeploymentHistoryConfigDiffCompare = ({
88
125
onChange : deploymentSelectorOnChange ,
89
126
showSelectedOptionIcon : false ,
90
127
menuSize : ComponentSizeType . large ,
128
+ loadMoreButtonConfig : {
129
+ show : triggerHistory . hasMore ,
130
+ isLoading : triggerHistory . isLoading ,
131
+ onClick : handleLoadMore ,
132
+ } ,
91
133
} ,
92
134
} ,
93
135
]
0 commit comments