File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -87,10 +87,23 @@ class ChallengePhaseHelper {
8787 timelineTemplateId ,
8888 isBeingActivated
8989 ) {
90- const { timelineTemplateMap } = await this . getTemplateAndTemplateMap ( timelineTemplateId ) ;
90+ const { timelineTemplateMap, timelineTempate } = await this . getTemplateAndTemplateMap (
91+ timelineTemplateId
92+ ) ;
9193 const { phaseDefinitionMap } = await this . getPhaseDefinitionsAndMap ( ) ;
94+
95+ // Ensure deterministic processing order based on the timeline template sequence
96+ // DB returns phases ordered by dates, which can cause "fixedStartDate" logic below
97+ // to incorrectly push earlier phases forward. Sorting by template order prevents that.
98+ const orderIndex = new Map ( ) ;
99+ _ . each ( timelineTempate , ( tplPhase , idx ) => orderIndex . set ( tplPhase . phaseId , idx ) ) ;
100+ const challengePhasesOrdered = _ . sortBy (
101+ challengePhases ,
102+ ( p ) => orderIndex . get ( p . phaseId ) ?? Number . MAX_SAFE_INTEGER
103+ ) ;
104+
92105 let fixedStartDate = undefined ;
93- const updatedPhases = _ . map ( challengePhases , ( phase ) => {
106+ const updatedPhases = _ . map ( challengePhasesOrdered , ( phase ) => {
94107 const phaseFromTemplate = timelineTemplateMap . get ( phase . phaseId ) ;
95108 const phaseDefinition = phaseDefinitionMap . get ( phase . phaseId ) ;
96109 const newPhase = _ . find ( newPhases , ( p ) => p . phaseId === phase . phaseId ) ;
You can’t perform that action at this time.
0 commit comments