Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/common/phase-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class ChallengePhaseHelper {
timelineTemplateId
);
const { phaseDefinitionMap } = await this.getPhaseDefinitionsAndMap();
const challengePhaseIds = new Set(_.map(challengePhases, "phaseId"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[💡 performance]
Using _.map to create a Set of phaseIds is efficient for lookups, but ensure that challengePhases is not excessively large, as this could impact performance. Consider profiling if performance issues arise.


// Ensure deterministic processing order based on the timeline template sequence
// DB returns phases ordered by dates, which can cause "fixedStartDate" logic below
Expand All @@ -107,9 +108,18 @@ class ChallengePhaseHelper {
const phaseFromTemplate = timelineTemplateMap.get(phase.phaseId);
const phaseDefinition = phaseDefinitionMap.get(phase.phaseId);
const newPhase = _.find(newPhases, (p) => p.phaseId === phase.phaseId);
const templatePredecessor = _.get(phaseFromTemplate, "predecessor");
// Prefer template predecessor only when that phase exists on the challenge, otherwise keep the stored link.
const resolvedPredecessor = _.isNil(phaseFromTemplate)
? phase.predecessor
: _.isNil(templatePredecessor)
? null
: challengePhaseIds.has(templatePredecessor)
? templatePredecessor
: phase.predecessor;
const updatedPhase = {
...phase,
predecessor: phaseFromTemplate && phaseFromTemplate.predecessor,
predecessor: resolvedPredecessor,
description: phaseDefinition.description,
};
if (updatedPhase.name === "Post-Mortem") {
Expand Down Expand Up @@ -157,6 +167,9 @@ class ChallengePhaseHelper {
const predecessorPhase = _.find(updatedPhases, {
phaseId: phase.predecessor,
});
if (_.isNil(predecessorPhase)) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[⚠️ correctness]
The check for _.isNil(predecessorPhase) and subsequent continue statement ensures that phases without valid predecessors are skipped. However, this could potentially hide logical errors if a phase is expected to have a predecessor. Consider logging or handling this scenario explicitly if it's not expected.

continue;
}
if (phase.name === "Iterative Review") {
if (!iterativeReviewSet) {
if (_.isNil(phase.actualStartDate)) {
Expand Down