Skip to content

Commit 44a9515

Browse files
authored
Merge pull request #472 from devtron-labs/fix/deployment-history-config-compare
fix: Deployment history doesn't let us compare the values from history not fetched still
2 parents be016be + 7c85080 commit 44a9515

File tree

5 files changed

+82
-11
lines changed

5 files changed

+82
-11
lines changed

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

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
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'
5-
import { SortingOrder } from '@Common/Constants'
5+
import { DEFAULT_BASE_PAGE_SIZE, SortingOrder } from '@Common/Constants'
66
import { useUrlFilters } from '@Common/Hooks'
77
import {
88
getSelectPickerOptionByValue,
99
SelectPickerOptionType,
1010
SelectPickerVariantType,
1111
} from '@Shared/Components/SelectPicker'
1212
import { ComponentSizeType } from '@Shared/constants'
13+
import { Button, ButtonVariantType } from '@Shared/Components/Button'
1314

1415
import {
1516
DeploymentHistoryDiffDetailedProps,
1617
DeploymentHistoryConfigDiffQueryParams,
1718
DeploymentHistoryConfigDiffRouteParams,
1819
} from './types'
19-
import { getPipelineDeploymentsOptions, parseDeploymentHistoryDiffSearchParams } from './utils'
20+
import { getPipelineDeployments, getPipelineDeploymentsOptions, parseDeploymentHistoryDiffSearchParams } from './utils'
21+
import { getTriggerHistory } from '../service'
2022

2123
export const DeploymentHistoryConfigDiffCompare = ({
2224
envName,
2325
setFullScreenView,
24-
pipelineDeployments,
26+
pipelineDeployments: initialPipelineDeployments,
2527
wfrId,
2628
previousWfrId,
2729
convertVariables,
2830
setConvertVariables,
29-
triggerHistory,
31+
triggerHistory: initialTriggerHistory,
3032
renderRunSource,
3133
resourceId,
3234
isCompareDeploymentConfigNotAvailable,
3335
...props
3436
}: DeploymentHistoryDiffDetailedProps) => {
3537
// HOOKS
3638
const { path, params } = useRouteMatch<DeploymentHistoryConfigDiffRouteParams>()
37-
const { resourceType, resourceName } = params
39+
const { resourceType, resourceName, appId, envId } = params
3840

3941
// URL FILTERS
4042
const { compareWfrId, updateSearchParams, sortBy, sortOrder, handleSorting } = useUrlFilters<
@@ -44,6 +46,14 @@ export const DeploymentHistoryConfigDiffCompare = ({
4446
parseSearchParams: parseDeploymentHistoryDiffSearchParams(previousWfrId),
4547
})
4648

49+
// STATES
50+
const [triggerHistory, setTriggerHistory] = useState({
51+
isLoading: false,
52+
data: initialTriggerHistory,
53+
hasMore: initialTriggerHistory.size >= DEFAULT_BASE_PAGE_SIZE,
54+
})
55+
const [pipelineDeployments, setPipelineDeployments] = useState(initialPipelineDeployments)
56+
4757
useEffect(() => {
4858
// Default Search Params Update
4959
updateSearchParams({ compareWfrId })
@@ -56,11 +66,53 @@ export const DeploymentHistoryConfigDiffCompare = ({
5666
}
5767
}, [])
5868

69+
// METHODS
70+
const fetchDeploymentHistory = async (paginationOffset: number) => {
71+
setTriggerHistory({ ...triggerHistory, isLoading: true })
72+
73+
try {
74+
const { result } = await getTriggerHistory({
75+
appId: +appId,
76+
envId: +envId,
77+
pagination: { offset: paginationOffset, size: DEFAULT_BASE_PAGE_SIZE },
78+
})
79+
const nextTriggerHistory = new Map((result.cdWorkflows || []).map((item) => [item.id, item]))
80+
const updatedTriggerHistory = new Map([...triggerHistory.data, ...nextTriggerHistory])
81+
82+
setTriggerHistory({
83+
isLoading: false,
84+
data: updatedTriggerHistory,
85+
hasMore: result.cdWorkflows?.length === DEFAULT_BASE_PAGE_SIZE,
86+
})
87+
setPipelineDeployments(getPipelineDeployments(updatedTriggerHistory))
88+
} catch {
89+
setTriggerHistory({ ...triggerHistory, isLoading: false })
90+
}
91+
}
92+
93+
const handleLoadMore = () => fetchDeploymentHistory(triggerHistory.data.size)
94+
95+
// RENDERERS
96+
const renderOptionsFooter = () =>
97+
triggerHistory.hasMore ? (
98+
<div className="px-4">
99+
<Button
100+
isLoading={triggerHistory.isLoading}
101+
onClick={handleLoadMore}
102+
dataTestId="load-more-previous-deployments"
103+
variant={ButtonVariantType.borderLess}
104+
text="Load more"
105+
size={ComponentSizeType.small}
106+
fullWidth
107+
/>
108+
</div>
109+
) : null
110+
59111
// DEPLOYMENT_CONFIG_DIFF_PROPS
60112
const { currentDeployment, pipelineDeploymentsOptions } = getPipelineDeploymentsOptions({
61113
pipelineDeployments,
62114
wfrId,
63-
triggerHistory,
115+
triggerHistory: triggerHistory.data,
64116
renderRunSource,
65117
resourceId,
66118
})
@@ -88,6 +140,7 @@ export const DeploymentHistoryConfigDiffCompare = ({
88140
onChange: deploymentSelectorOnChange,
89141
showSelectedOptionIcon: false,
90142
menuSize: ComponentSizeType.large,
143+
renderOptionsFooter,
91144
},
92145
},
93146
]

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
}

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
214214
onCreateOption,
215215
closeMenuOnSelect = false,
216216
shouldShowNoOptionsMessage = true,
217-
formatCreateLabel,
218217
...props
219218
}: SelectPickerProps<OptionValue, IsMulti>) => {
220219
const { inputId, required, isDisabled, controlShouldRenderValue = true, value, options, getOptionValue } = props
@@ -408,7 +407,6 @@ const SelectPicker = <OptionValue, IsMulti extends boolean>({
408407
onInputChange={onInputChange}
409408
icon={icon}
410409
showSelectedOptionIcon={shouldShowSelectedOptionIcon}
411-
formatCreateLabel={formatCreateLabel}
412410
onKeyDown={handleKeyDown}
413411
/>
414412
</div>

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,29 @@ export const SelectPickerOption = <OptionValue, IsMulti extends boolean>({
203203
export const SelectPickerMenuList = <OptionValue,>(props: MenuListProps<SelectPickerOptionType<OptionValue>>) => {
204204
const {
205205
children,
206-
selectProps: { inputValue, renderMenuListFooter, shouldRenderCustomOptions, renderCustomOptions },
206+
selectProps: {
207+
inputValue,
208+
renderMenuListFooter,
209+
shouldRenderCustomOptions,
210+
renderCustomOptions,
211+
renderOptionsFooter,
212+
},
207213
} = props
208214

209215
return (
210216
<>
211217
{/* added key here to explicitly re-render the list on input change so that the top option is rendered */}
212218
<components.MenuList {...props} key={inputValue}>
213-
<div className="py-4 cursor">{shouldRenderCustomOptions ? renderCustomOptions() : children}</div>
219+
<div className="py-4 cursor">
220+
{shouldRenderCustomOptions ? (
221+
renderCustomOptions()
222+
) : (
223+
<>
224+
{children}
225+
{renderOptionsFooter?.()}
226+
</>
227+
)}
228+
</div>
214229
{/* Added to the bottom of menu list to prevent from hiding when the menu is opened close to the bottom of the screen */}
215230
</components.MenuList>
216231
{!shouldRenderCustomOptions && renderMenuListFooter && (

src/Shared/Components/SelectPicker/type.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ declare module 'react-select/base' {
8484
* @default 'true'
8585
*/
8686
showSelectedOptionIcon?: boolean
87+
/** Render function for the footer at the end of the options list. */
88+
renderOptionsFooter?: () => ReactNode
8789
}
8890
}
8991

@@ -131,6 +133,7 @@ export type SelectPickerProps<OptionValue = number | string, IsMulti extends boo
131133
| 'renderCustomOptions'
132134
| 'icon'
133135
| 'showSelectedOptionIcon'
136+
| 'renderOptionsFooter'
134137
>
135138
> &
136139
Required<Pick<SelectProps<OptionValue, IsMulti>, 'inputId'>> &

0 commit comments

Comments
 (0)