|
| 1 | +import { useState } from 'react' |
| 2 | +import { useHistory, useParams } from 'react-router-dom' |
| 3 | + |
| 4 | +import { useQuery } from '@Common/API' |
| 5 | +import { URLS } from '@Common/Constants' |
| 6 | +import { Drawer } from '@Common/Drawer' |
| 7 | +import { showError, stopPropagation } from '@Common/Helper' |
| 8 | +import { ComponentSizeType } from '@Shared/constants' |
| 9 | + |
| 10 | +import { APIResponseHandler } from '../APIResponseHandler' |
| 11 | +import { Button, ButtonStyleType, ButtonVariantType } from '../Button' |
| 12 | +import { Icon } from '../Icon' |
| 13 | +import ConflictedResourcesTable from './ConflictedResourcesTable' |
| 14 | +import { getResourceConflictDetails, resourceConflictRedeploy } from './service' |
| 15 | +import { |
| 16 | + ResourceConflictDeployDialogURLParamsType, |
| 17 | + ResourceConflictDetailsModalProps, |
| 18 | + ResourceConflictItemType, |
| 19 | +} from './types' |
| 20 | + |
| 21 | +const ResourceConflictDetailsModal = ({ appName, environmentName, handleClose }: ResourceConflictDetailsModalProps) => { |
| 22 | + const { appId, envId, pipelineId, triggerId } = useParams<ResourceConflictDeployDialogURLParamsType>() |
| 23 | + const history = useHistory() |
| 24 | + |
| 25 | + const { |
| 26 | + isFetching: isLoadingResourceData, |
| 27 | + data: resourceConflictDetails, |
| 28 | + refetch: refetchResourceConflictDetails, |
| 29 | + error: resourceConflictDetailsError, |
| 30 | + } = useQuery<ResourceConflictItemType[], ResourceConflictItemType[], [string, string, string, string], false>({ |
| 31 | + queryKey: ['getResourceConflictDetails', pipelineId, triggerId, appId], |
| 32 | + queryFn: ({ signal }) => getResourceConflictDetails({ pipelineId, triggerId, appId, signal }), |
| 33 | + }) |
| 34 | + |
| 35 | + const [isDeploying, setIsDeploying] = useState(false) |
| 36 | + |
| 37 | + const handleDeploy = async () => { |
| 38 | + setIsDeploying(true) |
| 39 | + try { |
| 40 | + await resourceConflictRedeploy({ |
| 41 | + pipelineId, |
| 42 | + triggerId, |
| 43 | + appId, |
| 44 | + }) |
| 45 | + setIsDeploying(false) |
| 46 | + history.push(`${URLS.APP}/${appId}/details/${envId}`) |
| 47 | + } catch (error) { |
| 48 | + showError(error) |
| 49 | + setIsDeploying(false) |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + return ( |
| 54 | + <Drawer width="800px" onClose={handleClose} onEscape={handleClose} position="right"> |
| 55 | + <div |
| 56 | + className="flexbox-col dc__content-space h-100 bg__modal--primary shadow__modal dc__overflow-auto" |
| 57 | + onClick={stopPropagation} |
| 58 | + > |
| 59 | + <div className="flexbox-col dc__overflow-auto flex-grow-1"> |
| 60 | + <div className="px-20 py-12 flexbox dc__content-space dc__align-items-center border__primary--bottom"> |
| 61 | + <h2 className="m-0 fs-16 fw-6 lh-24 cn-9">Resources with conflict</h2> |
| 62 | + |
| 63 | + <Button |
| 64 | + dataTestId="header-close-button" |
| 65 | + ariaLabel="Close" |
| 66 | + showAriaLabelInTippy={false} |
| 67 | + onClick={handleClose} |
| 68 | + variant={ButtonVariantType.borderLess} |
| 69 | + style={ButtonStyleType.negativeGrey} |
| 70 | + icon={<Icon name="ic-close-large" color={null} />} |
| 71 | + size={ComponentSizeType.xs} |
| 72 | + /> |
| 73 | + </div> |
| 74 | + |
| 75 | + <div className="flexbox-col flex-grow-1 dc__overflow-auto w-100"> |
| 76 | + <APIResponseHandler |
| 77 | + isLoading={isLoadingResourceData} |
| 78 | + progressingProps={{ |
| 79 | + pageLoader: true, |
| 80 | + }} |
| 81 | + error={resourceConflictDetailsError} |
| 82 | + errorScreenManagerProps={{ |
| 83 | + code: resourceConflictDetailsError?.code, |
| 84 | + reload: refetchResourceConflictDetails, |
| 85 | + on404Redirect: handleClose, |
| 86 | + }} |
| 87 | + > |
| 88 | + <ConflictedResourcesTable resourceConflictDetails={resourceConflictDetails} /> |
| 89 | + </APIResponseHandler> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + |
| 93 | + <div className="flexbox dc__align-items-center dc__content-space dc__gap-20 py-16 px-20 border__primary--top dc__no-shrink"> |
| 94 | + <div className="flexbox dc__gap-8"> |
| 95 | + <Icon name="ic-warning" size={20} color={null} /> |
| 96 | + <div className="flexbox-col"> |
| 97 | + <span className="cn-9 fs-13 fw-6 lh-1-5">Take resource ownership and redeploy</span> |
| 98 | + <span> |
| 99 | + Ensure all resources strictly belong to the {appName} application and the |
| 100 | + {environmentName} |
| 101 | + environment. Any resource outside this Helm release may cause incorrect associations and |
| 102 | + potentially destructive changes. |
| 103 | + </span> |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + <div className="dc__no-shrink"> |
| 107 | + <Button |
| 108 | + dataTestId="footer-redeploy-button" |
| 109 | + variant={ButtonVariantType.primary} |
| 110 | + style={ButtonStyleType.warning} |
| 111 | + size={ComponentSizeType.large} |
| 112 | + text="Re-deploy" |
| 113 | + startIcon={<Icon name="ic-rocket-launch" color={null} />} |
| 114 | + isLoading={isDeploying} |
| 115 | + disabled={!resourceConflictDetails?.length} |
| 116 | + onClick={handleDeploy} |
| 117 | + /> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + </div> |
| 121 | + </Drawer> |
| 122 | + ) |
| 123 | +} |
| 124 | + |
| 125 | +export default ResourceConflictDetailsModal |
0 commit comments