import { useRef, useState, type FC, type ReactNode } from 'react'; import { Box, styled, Typography } from '@mui/material'; import type { ChangeRequestState, IChangeRequestAddReleasePlan, IChangeRequestDeleteReleasePlan, IChangeRequestStartMilestone, } from 'component/changeRequest/changeRequest.types'; import { useReleasePlanPreview } from 'hooks/useReleasePlanPreview'; import { useReleasePlans } from 'hooks/api/getters/useReleasePlans/useReleasePlans'; import { TooltipLink } from 'component/common/TooltipLink/TooltipLink'; import { EventDiff } from 'component/events/EventDiff/EventDiff'; import { ReleasePlan } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlan'; import { ReleasePlanMilestone } from 'component/feature/FeatureView/FeatureOverview/ReleasePlan/ReleasePlanMilestone/ReleasePlanMilestone'; import type { IReleasePlan } from 'interfaces/releasePlans'; import { Tab, TabList, TabPanel, Tabs } from './ChangeTabComponents.tsx'; import { ChangeItemInfo } from './Change.styles.tsx'; export const ChangeItemWrapper = styled(Box)({ display: 'flex', justifyContent: 'space-between', alignItems: 'center', }); const ChangeItemCreateEditDeleteWrapper = styled(Box)(({ theme }) => ({ display: 'grid', gridTemplateColumns: 'auto auto', justifyContent: 'space-between', gap: theme.spacing(1), alignItems: 'center', marginBottom: theme.spacing(2), width: '100%', })); const DeleteReleasePlan: FC<{ change: IChangeRequestDeleteReleasePlan; currentReleasePlan?: IReleasePlan; changeRequestState: ChangeRequestState; actions?: ReactNode; }> = ({ change, currentReleasePlan, changeRequestState, actions }) => { const releasePlan = changeRequestState === 'Applied' && change.payload.snapshot ? change.payload.snapshot : currentReleasePlan; if (!releasePlan) return; return ( <> ({ color: theme.palette.error.main, })} > - Deleting release plan {releasePlan.name}
{actions}
); }; const StartMilestone: FC<{ change: IChangeRequestStartMilestone; currentReleasePlan?: IReleasePlan; changeRequestState: ChangeRequestState; actions?: ReactNode; }> = ({ change, currentReleasePlan, changeRequestState, actions }) => { const releasePlan = changeRequestState === 'Applied' && change.payload.snapshot ? change.payload.snapshot : currentReleasePlan; if (!releasePlan) return; const previousMilestone = releasePlan.milestones.find( (milestone) => milestone.id === releasePlan.activeMilestoneId, ); const newMilestone = releasePlan.milestones.find( (milestone) => milestone.id === change.payload.milestoneId, ); if (!newMilestone) return; return ( + Start milestone {newMilestone.name}
Change View diff {actions}
); }; const AddReleasePlan: FC<{ change: IChangeRequestAddReleasePlan; currentReleasePlan?: IReleasePlan; environmentName: string; featureName: string; actions?: ReactNode; }> = ({ change, currentReleasePlan, environmentName, featureName, actions, }) => { const [currentTooltipOpen, setCurrentTooltipOpen] = useState(false); const currentTooltipCloseTimeoutRef = useRef(); const openCurrentTooltip = () => { if (currentTooltipCloseTimeoutRef.current) { clearTimeout(currentTooltipCloseTimeoutRef.current); } setCurrentTooltipOpen(true); }; const closeCurrentTooltip = () => { currentTooltipCloseTimeoutRef.current = setTimeout(() => { setCurrentTooltipOpen(false); }, 100); }; const planPreview = useReleasePlanPreview( change.payload.templateId, featureName, environmentName, ); const planPreviewDiff = { ...planPreview, discriminator: 'plan', releasePlanTemplateId: change.payload.templateId, }; if (!currentReleasePlan) { return ( <> + Adding release plan {planPreview.name}
{actions}
); } return ( Replacing{' '} openCurrentTooltip()} onMouseLeave={() => closeCurrentTooltip()} > } tooltipProps={{ open: currentTooltipOpen, maxWidth: 500, maxHeight: 600, }} > openCurrentTooltip()} onMouseLeave={() => closeCurrentTooltip()} > current {' '} release plan with {planPreview.name}
Changes View diff {actions}
); }; export const ReleasePlanChange: FC<{ actions?: ReactNode; change: | IChangeRequestAddReleasePlan | IChangeRequestDeleteReleasePlan | IChangeRequestStartMilestone; environmentName: string; featureName: string; projectId: string; changeRequestState: ChangeRequestState; }> = ({ actions, change, featureName, environmentName, projectId, changeRequestState, }) => { const { releasePlans } = useReleasePlans( projectId, featureName, environmentName, ); const currentReleasePlan = releasePlans[0]; return ( <> {change.action === 'addReleasePlan' && ( )} {change.action === 'deleteReleasePlan' && ( )} {change.action === 'startMilestone' && ( )} ); };