forked from jappel/leistungsbilanz-ts
Restore circuit drag placement
This commit is contained in:
parent
7c8d4a7ddf
commit
2d97fafce9
6 changed files with 194 additions and 25 deletions
|
|
@ -87,3 +87,26 @@ export function getInsertionSortOrder(
|
|||
const next = entries[index + 1]?.sortOrder;
|
||||
return next === undefined ? current + 10 : current + (next - current) / 2;
|
||||
}
|
||||
|
||||
export function getAdjacentInsertionSortOrder(
|
||||
orderedEntries: Array<{ id: string; sortOrder: number }>,
|
||||
targetId: string,
|
||||
placement: "before" | "after"
|
||||
): number {
|
||||
const entries = [...orderedEntries].sort(
|
||||
(left, right) =>
|
||||
left.sortOrder - right.sortOrder ||
|
||||
left.id.localeCompare(right.id)
|
||||
);
|
||||
const index = entries.findIndex((entry) => entry.id === targetId);
|
||||
if (index < 0) {
|
||||
throw new Error("Der Zielstromkreis wurde nicht gefunden.");
|
||||
}
|
||||
if (placement === "after") {
|
||||
return getInsertionSortOrder(entries, targetId);
|
||||
}
|
||||
const previous = entries[index - 1];
|
||||
return previous
|
||||
? getInsertionSortOrder(entries, previous.id)
|
||||
: entries[index].sortOrder - 10;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,8 +144,15 @@ const circuitSectionLabels: Record<string, string> = {
|
|||
};
|
||||
|
||||
export function getCircuitSectionLabel(
|
||||
section: { key: string; displayName: string }
|
||||
section: {
|
||||
key: string;
|
||||
displayName: string;
|
||||
category?: string;
|
||||
}
|
||||
): string {
|
||||
if (section.category) {
|
||||
return section.displayName;
|
||||
}
|
||||
return circuitSectionLabels[section.key] ?? section.displayName;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue