refactor(web): extract preview target setup

This commit is contained in:
2026-04-01 11:59:10 +02:00
parent 2a7769a0de
commit e103174d39
5 changed files with 245 additions and 41 deletions
+31
View File
@@ -255,6 +255,25 @@ export const rules = [
],
forbidden: [],
},
{
file: "apps/web/src/hooks/timelinePreviewSession.ts",
maxLines: 80,
required: [
{
pattern: /\bexport function createProjectPreviewSession\b/,
message: "timeline preview session helpers must keep project preview target resolution centralized",
},
{
pattern: /\bexport function createAllocationPreviewSession\b/,
message: "timeline preview session helpers must keep allocation preview target resolution centralized",
},
{
pattern: /from "\.\/timelineLivePreview\.js"/,
message: "timeline preview session helpers must keep target capture delegated to the live preview helper module",
},
],
forbidden: [],
},
{
file: "apps/web/src/hooks/timelineAllocationFinalize.ts",
maxLines: 100,
@@ -492,6 +511,10 @@ export const rules = [
pattern: /from "\.\/timelineOptimisticAllocations\.js"/,
message: "timeline drag must keep optimistic allocation reconciliation delegated to the extracted helper module",
},
{
pattern: /from "\.\/timelinePreviewSession\.js"/,
message: "timeline drag must keep preview target setup delegated to the extracted helper module",
},
{
pattern: /from "\.\/timelineDragCleanup\.js"/,
message: "timeline drag must keep unmount teardown delegated to the extracted helper module",
@@ -594,6 +617,14 @@ export const rules = [
pattern: /\bconst mutationInput = buildProjectShiftMutationInput\(finalDrag\)\b[\s\S]*applyShiftMutation\.(?:mutate|mutateAsync)\(/,
message: "timeline drag must not re-inline extracted project drag finalize flow",
},
{
pattern: /\bdocument\.querySelectorAll<HTMLElement>\([\s\S]*data-timeline-project-id/,
message: "timeline drag must not re-inline extracted project preview target lookup",
},
{
pattern: /\bcurrentTarget\.closest<HTMLElement>\('\[data-timeline-drag-preview~=\"allocation\"\]'\)/,
message: "timeline drag must not re-inline extracted allocation preview target lookup",
},
{
pattern: /\bconst selection = finalizeRangeSelection\(/,
message: "timeline drag must not re-inline extracted range release resolution",
@@ -79,6 +79,7 @@ describe("architecture guardrails", () => {
const rangeRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineRangeSelection.ts");
const rangeReleaseRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineRangeRelease.ts");
const optimisticRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineOptimisticAllocations.ts");
const previewSessionRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelinePreviewSession.ts");
const allocationFinalizeRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineAllocationFinalize.ts");
const allocationMultiDragRule = rules.find((rule) => rule.file === "apps/web/src/hooks/timelineAllocationMultiDrag.ts");
const allocationMultiDragSessionRule = rules.find(
@@ -110,6 +111,7 @@ describe("architecture guardrails", () => {
assert.ok(rangeRule);
assert.ok(rangeReleaseRule);
assert.ok(optimisticRule);
assert.ok(previewSessionRule);
assert.ok(allocationFinalizeRule);
assert.ok(allocationMultiDragRule);
assert.ok(allocationMultiDragSessionRule);
@@ -133,6 +135,7 @@ describe("architecture guardrails", () => {
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep range preview and finalization delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep range release and cancel delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep optimistic allocation reconciliation delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep preview target setup delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep unmount teardown delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep project and allocation drag position derivation delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep document mouse listener lifecycle delegated to the extracted helper module",
@@ -192,6 +195,11 @@ describe("architecture guardrails", () => {
"apps/web/src/hooks/timelineOptimisticAllocations.ts: missing guardrail anchor: timeline optimistic helpers must keep server-reconciliation logic centralized",
]);
assert.deepEqual(evaluateRule(previewSessionRule, "export function createProjectPreviewSession() {}\n"), [
"apps/web/src/hooks/timelinePreviewSession.ts: missing guardrail anchor: timeline preview session helpers must keep allocation preview target resolution centralized",
"apps/web/src/hooks/timelinePreviewSession.ts: missing guardrail anchor: timeline preview session helpers must keep target capture delegated to the live preview helper module",
]);
assert.deepEqual(evaluateRule(allocationFinalizeRule, "export function hasAllocationDateChange() {}\n"), [
"apps/web/src/hooks/timelineAllocationFinalize.ts: missing guardrail anchor: timeline allocation finalize helpers must keep click-vs-drag classification centralized",
"apps/web/src/hooks/timelineAllocationFinalize.ts: missing guardrail anchor: timeline allocation finalize helpers must keep segment extraction rules centralized",
@@ -269,6 +277,7 @@ describe("architecture guardrails", () => {
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep range preview and finalization delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep range release and cancel delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep optimistic allocation reconciliation delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep preview target setup delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep unmount teardown delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep project and allocation drag position derivation delegated to the extracted helper module",
"apps/web/src/hooks/useTimelineDrag.ts: missing guardrail anchor: timeline drag must keep document mouse listener lifecycle delegated to the extracted helper module",