diff --git a/frontend/src/component/releases/ReleasePlanTemplate/MilestoneCard.tsx b/frontend/src/component/releases/ReleasePlanTemplate/MilestoneCard.tsx index c077c0d58d6d..a0a324112884 100644 --- a/frontend/src/component/releases/ReleasePlanTemplate/MilestoneCard.tsx +++ b/frontend/src/component/releases/ReleasePlanTemplate/MilestoneCard.tsx @@ -54,11 +54,10 @@ const StyledMilestoneCardTitle = styled('span')(({ theme }) => ({ })); interface IMilestoneCardProps { - index: number; milestone: IReleasePlanMilestonePayload; - milestoneNameChanged: (index: number, name: string) => void; + milestoneNameChanged: (milestoneId: string, name: string) => void; showAddStrategyDialog: ( - index: number, + milestoneId: string, strategy: IReleasePlanMilestoneStrategy, ) => void; errors: { [key: string]: string }; @@ -66,7 +65,6 @@ interface IMilestoneCardProps { } export const MilestoneCard = ({ - index, milestone, milestoneNameChanged, showAddStrategyDialog, @@ -88,7 +86,7 @@ export const MilestoneCard = ({ milestoneId: string, strategy: IReleasePlanMilestoneStrategy, ) => { - showAddStrategyDialog(index, strategy); + showAddStrategyDialog(milestone.id, strategy); }; return ( @@ -101,7 +99,10 @@ export const MilestoneCard = ({ label='' value={milestone.name} onChange={(e) => - milestoneNameChanged(index, e.target.value) + milestoneNameChanged( + milestone.id, + e.target.value, + ) } error={Boolean(errors?.name)} errorText={errors?.name} @@ -151,7 +152,7 @@ export const MilestoneCard = ({ }} > diff --git a/frontend/src/component/releases/ReleasePlanTemplate/MilestoneList.tsx b/frontend/src/component/releases/ReleasePlanTemplate/MilestoneList.tsx index afd1ea2699c2..a628ab2a1941 100644 --- a/frontend/src/component/releases/ReleasePlanTemplate/MilestoneList.tsx +++ b/frontend/src/component/releases/ReleasePlanTemplate/MilestoneList.tsx @@ -6,6 +6,7 @@ import { MilestoneCard } from './MilestoneCard'; import { styled } from '@mui/material'; import { Button } from '@mui/material'; import Add from '@mui/icons-material/Add'; +import { v4 as uuidv4 } from 'uuid'; interface IMilestoneListProps { milestones: IReleasePlanMilestonePayload[]; @@ -13,7 +14,7 @@ interface IMilestoneListProps { React.SetStateAction >; openAddStrategyForm: ( - index: number, + milestoneId: string, strategy: IReleasePlanMilestoneStrategy, ) => void; errors: { [key: string]: string }; @@ -32,20 +33,21 @@ export const MilestoneList = ({ errors, clearErrors, }: IMilestoneListProps) => { - const milestoneNameChanged = (index: number, name: string) => { + const milestoneNameChanged = (milestoneId: string, name: string) => { setMilestones((prev) => - prev.map((milestone, i) => - i === index ? { ...milestone, name } : milestone, + prev.map((milestone) => + milestone.id === milestoneId + ? { ...milestone, name } + : milestone, ), ); }; return ( <> - {milestones.map((milestone, index) => ( + {milestones.map((milestone) => ( [ ...prev, { + id: uuidv4(), name: `Milestone ${prev.length + 1}`, sortOrder: prev.length, }, diff --git a/frontend/src/component/releases/ReleasePlanTemplate/TemplateForm.tsx b/frontend/src/component/releases/ReleasePlanTemplate/TemplateForm.tsx index ef2b28390119..9098843190db 100644 --- a/frontend/src/component/releases/ReleasePlanTemplate/TemplateForm.tsx +++ b/frontend/src/component/releases/ReleasePlanTemplate/TemplateForm.tsx @@ -59,8 +59,8 @@ export const TemplateForm: React.FC = ({ children, }) => { const [addStrategyOpen, setAddStrategyOpen] = useState(false); - const [activeMilestoneIndex, setActiveMilestoneIndex] = useState< - number | undefined + const [activeMilestoneId, setActiveMilestoneId] = useState< + string | undefined >(); const [strategy, setStrategy] = useState({ name: 'flexibleRollout', @@ -70,14 +70,33 @@ export const TemplateForm: React.FC = ({ id: '', }); const openAddStrategyForm = ( - index: number, + milestoneId: string, strategy: IReleasePlanMilestoneStrategy, ) => { - setActiveMilestoneIndex(index); + setActiveMilestoneId(milestoneId); setStrategy(strategy); setAddStrategyOpen(true); }; + const addStrategy = ( + milestoneId: string, + strategy: IReleasePlanMilestoneStrategy, + ) => { + setMilestones((prev) => + prev.map((milestone, i) => + milestone.id === milestoneId + ? { + ...milestone, + strategies: [ + ...(milestone.strategies || []), + strategy, + ], + } + : milestone, + ), + ); + }; + return ( { const [name, setName] = useState(initialName); diff --git a/frontend/src/interfaces/releasePlans.ts b/frontend/src/interfaces/releasePlans.ts index bd1332529e2c..09ad8b910f81 100644 --- a/frontend/src/interfaces/releasePlans.ts +++ b/frontend/src/interfaces/releasePlans.ts @@ -41,7 +41,7 @@ export interface IReleasePlanTemplatePayload { } export interface IReleasePlanMilestonePayload { - id?: string; + id: string; name: string; sortOrder: number; strategies?: IReleasePlanStrategyPayload[];