Skip to content

Commit eb24d40

Browse files
committed
feat: SelectPicker - add renderOptionsFooter prop, DeploymentHistoryConfigDiffCompare - code refactor
1 parent e5a5133 commit eb24d40

File tree

3 files changed

+27
-33
lines changed

3 files changed

+27
-33
lines changed

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

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ 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,
@@ -19,8 +20,6 @@ import {
1920
import { getPipelineDeployments, getPipelineDeploymentsOptions, parseDeploymentHistoryDiffSearchParams } from './utils'
2021
import { getTriggerHistory } from '../service'
2122

22-
const paginationSize = 20
23-
2423
export const DeploymentHistoryConfigDiffCompare = ({
2524
envName,
2625
setFullScreenView,
@@ -51,7 +50,7 @@ export const DeploymentHistoryConfigDiffCompare = ({
5150
const [triggerHistory, setTriggerHistory] = useState({
5251
isLoading: false,
5352
data: initialTriggerHistory,
54-
hasMore: initialTriggerHistory.size >= paginationSize,
53+
hasMore: initialTriggerHistory.size >= DEFAULT_BASE_PAGE_SIZE,
5554
})
5655
const [pipelineDeployments, setPipelineDeployments] = useState(initialPipelineDeployments)
5756

@@ -75,15 +74,15 @@ export const DeploymentHistoryConfigDiffCompare = ({
7574
const { result } = await getTriggerHistory({
7675
appId: +appId,
7776
envId: +envId,
78-
pagination: { offset: paginationOffset, size: paginationSize },
77+
pagination: { offset: paginationOffset, size: DEFAULT_BASE_PAGE_SIZE },
7978
})
8079
const nextTriggerHistory = new Map((result.cdWorkflows || []).map((item) => [item.id, item]))
8180
const updatedTriggerHistory = new Map([...triggerHistory.data, ...nextTriggerHistory])
8281

8382
setTriggerHistory({
8483
isLoading: false,
8584
data: updatedTriggerHistory,
86-
hasMore: result.cdWorkflows?.length === paginationSize,
85+
hasMore: result.cdWorkflows?.length === DEFAULT_BASE_PAGE_SIZE,
8786
})
8887
setPipelineDeployments(getPipelineDeployments(updatedTriggerHistory))
8988
} catch {
@@ -93,6 +92,22 @@ export const DeploymentHistoryConfigDiffCompare = ({
9392

9493
const handleLoadMore = () => fetchDeploymentHistory(triggerHistory.data.size)
9594

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+
96111
// DEPLOYMENT_CONFIG_DIFF_PROPS
97112
const { currentDeployment, pipelineDeploymentsOptions } = getPipelineDeploymentsOptions({
98113
pipelineDeployments,
@@ -125,11 +140,7 @@ export const DeploymentHistoryConfigDiffCompare = ({
125140
onChange: deploymentSelectorOnChange,
126141
showSelectedOptionIcon: false,
127142
menuSize: ComponentSizeType.large,
128-
loadMoreButtonConfig: {
129-
show: triggerHistory.hasMore,
130-
isLoading: triggerHistory.isLoading,
131-
onClick: handleLoadMore,
132-
},
143+
renderOptionsFooter,
133144
},
134145
},
135146
]

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ import { ReactSelectInputAction } from '@Common/Constants'
3838
import { isNullOrUndefined } from '@Shared/Helpers'
3939
import { Tooltip } from '@Common/Tooltip'
4040
import { TooltipProps } from '@Common/Tooltip/types'
41-
import { ComponentSizeType } from '@Shared/constants'
42-
import { Button, ButtonVariantType } from '../Button'
4341
import { SelectPickerGroupHeadingProps, SelectPickerOptionType, SelectPickerProps } from './type'
4442
import { getGroupCheckboxValue } from './utils'
4543

@@ -210,7 +208,7 @@ export const SelectPickerMenuList = <OptionValue,>(props: MenuListProps<SelectPi
210208
renderMenuListFooter,
211209
shouldRenderCustomOptions,
212210
renderCustomOptions,
213-
loadMoreButtonConfig,
211+
renderOptionsFooter,
214212
},
215213
} = props
216214

@@ -224,18 +222,7 @@ export const SelectPickerMenuList = <OptionValue,>(props: MenuListProps<SelectPi
224222
) : (
225223
<>
226224
{children}
227-
{loadMoreButtonConfig?.show && (
228-
<div className="px-4">
229-
<Button
230-
{...loadMoreButtonConfig}
231-
dataTestId="load-more-previous-deployments"
232-
variant={ButtonVariantType.borderLess}
233-
text="Load more"
234-
size={ComponentSizeType.small}
235-
fullWidth
236-
/>
237-
</div>
238-
)}
225+
{renderOptionsFooter?.()}
239226
</>
240227
)}
241228
</div>

src/Shared/Components/SelectPicker/type.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import { CreatableProps } from 'react-select/creatable'
2323
// This import allows to extend the base interface in react-select module via module augmentation
2424
import type {} from 'react-select/base'
2525
import { TooltipProps } from '@Common/Tooltip/types'
26-
import { ButtonProps } from '../Button'
2726

2827
export interface SelectPickerOptionType<OptionValue = string | number> extends OptionType<OptionValue, ReactNode> {
2928
/**
@@ -85,11 +84,8 @@ declare module 'react-select/base' {
8584
* @default 'true'
8685
*/
8786
showSelectedOptionIcon?: boolean
88-
/** Renders "Load more" button at the end of the menu list. */
89-
loadMoreButtonConfig?: Pick<ButtonProps, 'isLoading' | 'disabled'> & {
90-
show?: boolean
91-
onClick?: () => void
92-
}
87+
/** Render function for the footer at the end of the options list. */
88+
renderOptionsFooter?: () => ReactNode
9389
}
9490
}
9591

@@ -137,7 +133,7 @@ export type SelectPickerProps<OptionValue = number | string, IsMulti extends boo
137133
| 'renderCustomOptions'
138134
| 'icon'
139135
| 'showSelectedOptionIcon'
140-
| 'loadMoreButtonConfig'
136+
| 'renderOptionsFooter'
141137
>
142138
> &
143139
Required<Pick<SelectProps<OptionValue, IsMulti>, 'inputId'>> &

0 commit comments

Comments
 (0)