Skip to content

Commit 6dda3ad

Browse files
committed
Update for bug where F2F phases aren't saving dates properly
1 parent 66ce323 commit 6dda3ad

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/common/phase-helper.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)