Skip to content

Commit 7d9b6a7

Browse files
committed
feat: Refactor DeployImageModal and ImageSelectionCTA to improve state initialization and streamline image selection handling
1 parent 9b3d43a commit 7d9b6a7

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

src/components/app/details/triggerView/DeployImageModal/DeployImageModal.tsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
AnimatedDeployButton,
77
API_STATUS_CODES,
88
ArtifactInfo,
9-
CDMaterialSidebarType,
109
ConditionalWrap,
1110
DEFAULT_ROUTE_PROMPT_MESSAGE,
1211
DEPLOYMENT_CONFIG_DIFF_SORT_KEY,
@@ -51,7 +50,8 @@ import { CDButtonLabelMap } from '../config'
5150
import { TRIGGER_VIEW_GA_EVENTS } from '../Constants'
5251
import { PipelineConfigDiff, usePipelineDeploymentConfig } from '../PipelineConfigDiff'
5352
import { PipelineConfigDiffStatusTile } from '../PipelineConfigDiff/PipelineConfigDiffStatusTile'
54-
import { FilterConditionViews, MATERIAL_TYPE } from '../types'
53+
import { MATERIAL_TYPE } from '../types'
54+
import { INITIAL_DEPLOY_VIEW_STATE } from './constants'
5555
import DeployImageContent from './DeployImageContent'
5656
import DeployImageHeader from './DeployImageHeader'
5757
import MaterialListSkeleton from './MaterialListSkeleton'
@@ -148,21 +148,9 @@ const DeployImageModal = ({
148148
const [deploymentStrategy, setDeploymentStrategy] = useState<DeploymentStrategyType | null>(null)
149149
const [showPluginWarningOverlay, setShowPluginWarningOverlay] = useState<boolean>(false)
150150
const [showDeploymentWindowConfirmation, setShowDeploymentWindowConfirmation] = useState(false)
151-
const [deployViewState, setDeployViewState] = useState<Omit<DeployViewStateType, 'appliedSearchText'>>({
152-
searchText: searchImageTag,
153-
filterView: FilterConditionViews.ALL,
154-
showConfiguredFilters: false,
155-
currentSidebarTab: CDMaterialSidebarType.IMAGE,
156-
runtimeParamsErrorState: {
157-
isValid: true,
158-
cellError: {},
159-
},
160-
materialInEditModeMap: new Map(),
161-
showAppliedFilters: false,
162-
appliedFilterList: [],
163-
isLoadingOlderImages: false,
164-
showSearchBar: false,
165-
})
151+
const [deployViewState, setDeployViewState] = useState<Omit<DeployViewStateType, 'appliedSearchText'>>(
152+
structuredClone(INITIAL_DEPLOY_VIEW_STATE),
153+
)
166154

167155
const isPreOrPostCD = stageType === DeploymentNodeType.PRECD || stageType === DeploymentNodeType.POSTCD
168156
const materialResponse = initialDataResponse?.[0] || null

src/components/app/details/triggerView/DeployImageModal/ImageSelectionCTA.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const ImageSelectionCTA = ({
2525
pipelineId,
2626
canApproverDeploy,
2727
isExceptionUser,
28-
handleImageSelection,
28+
handleImageSelection: handleImageSelectionProp,
2929
}: ImageSelectionCTAProps) => {
3030
const isApprovalRequester =
3131
material.userApprovalMetadata?.requestedUserData &&
@@ -40,16 +40,14 @@ const ImageSelectionCTA = ({
4040
isMaterialApproved &&
4141
material.userApprovalMetadata?.canCurrentUserApprove
4242

43+
const handleImageSelection = () => {
44+
handleImageSelectionProp(material.index)
45+
}
46+
4347
const renderMaterialCTA = () => {
4448
if (material.filterState !== FilterStates.ALLOWED) {
4549
return (
46-
<Tooltip
47-
alwaysShowTippyOnHover
48-
className="default-tt w-200"
49-
arrow={false}
50-
placement="top"
51-
content={EXCLUDED_IMAGE_TOOLTIP}
52-
>
50+
<Tooltip alwaysShowTippyOnHover placement="top" content={EXCLUDED_IMAGE_TOOLTIP}>
5351
<i className="cr-5 fs-13 fw-4 lh-24 m-0 cursor-not-allowed">Excluded</i>
5452
</Tooltip>
5553
)
@@ -92,7 +90,7 @@ const ImageSelectionCTA = ({
9290
return (
9391
<Button
9492
dataTestId={`cd-artifact-select-${material.index}`}
95-
onClick={() => handleImageSelection(material.index)}
93+
onClick={handleImageSelection}
9694
text="SELECT"
9795
size={ComponentSizeType.medium}
9896
variant={ButtonVariantType.text}

0 commit comments

Comments
 (0)