refactor(web): extract allocation drag action plans

This commit is contained in:
2026-04-01 10:15:54 +02:00
parent 203bb8751d
commit c941b1e5cf
7 changed files with 246 additions and 40 deletions
@@ -0,0 +1,62 @@
import {
buildAllocationMovedSnapshot,
requiresAllocationFragmentExtraction,
type AllocationMovedSnapshotLike,
} from "./timelineAllocationFinalize.js";
type AllocationActionLike = {
allocationId: string | null;
mutationAllocationId: string | null;
projectId: string | null;
projectName: string | null;
scope: "allocation" | "segment";
allocationStartDate: Date | null;
allocationEndDate: Date | null;
originalStartDate: Date | null;
originalEndDate: Date | null;
currentStartDate: Date | null;
currentEndDate: Date | null;
};
export function buildAllocationBlockClickInfo(
alloc: Pick<
AllocationActionLike,
"allocationId" | "projectId" | "projectName" | "originalStartDate" | "originalEndDate"
>,
): { allocationId: string; projectId: string; projectName: string; startDate: Date; endDate: Date } | null {
if (!alloc.allocationId || !alloc.originalStartDate || !alloc.originalEndDate) {
return null;
}
return {
allocationId: alloc.allocationId,
projectId: alloc.projectId ?? "",
projectName: alloc.projectName ?? "",
startDate: alloc.originalStartDate,
endDate: alloc.originalEndDate,
};
}
export function buildAllocationMutationPlan(
alloc: AllocationActionLike,
): {
activeAllocationId: string;
currentStartDate: Date;
currentEndDate: Date;
baseMutationAllocationId: string;
requiresExtraction: boolean;
pendingSnapshot: AllocationMovedSnapshotLike | null;
} | null {
if (!alloc.allocationId || !alloc.currentStartDate || !alloc.currentEndDate) {
return null;
}
return {
activeAllocationId: alloc.allocationId,
currentStartDate: alloc.currentStartDate,
currentEndDate: alloc.currentEndDate,
baseMutationAllocationId: alloc.mutationAllocationId ?? alloc.allocationId,
requiresExtraction: requiresAllocationFragmentExtraction(alloc),
pendingSnapshot: buildAllocationMovedSnapshot(alloc),
};
}