Validate project device drop targets

This commit is contained in:
2026-07-22 20:07:09 +02:00
parent b2f5ce77a5
commit fd62bf2e15
6 changed files with 231 additions and 30 deletions
@@ -0,0 +1,29 @@
export interface ProjectDevicePlacementSource {
category?: string | null;
phaseType: "single_phase" | "three_phase";
}
export interface ProjectDevicePlacementSection {
key: string;
}
export type DefaultCircuitSectionKey = "lighting" | "single_phase" | "three_phase";
// Lighting classification takes precedence over the electrical phase because
// lighting devices use their dedicated numbering section by default.
export function inferProjectDeviceSectionKey(
device: ProjectDevicePlacementSource
): DefaultCircuitSectionKey {
const category = (device.category ?? "").trim().toLowerCase();
if (category.includes("light") || category.includes("beleuchtung")) {
return "lighting";
}
return device.phaseType;
}
export function isProjectDevicePlacementValid(
device: ProjectDevicePlacementSource,
section: ProjectDevicePlacementSection
): boolean {
return section.key === inferProjectDeviceSectionKey(device);
}