forked from jappel/leistungsbilanz-ts
Reorder circuit groups
This commit is contained in:
parent
8898117ed4
commit
0cb280ddb2
7 changed files with 180 additions and 1 deletions
|
|
@ -57,6 +57,7 @@ import type {
|
|||
} from "../../domain/models/distribution-board-component-structure-project-command.model";
|
||||
import type {
|
||||
CircuitGroupSnapshot,
|
||||
CircuitGroupReorderAssignment,
|
||||
} from "../../domain/models/circuit-group-structure-project-command.model";
|
||||
import type {
|
||||
CircuitProtectionSnapshot,
|
||||
|
|
@ -433,6 +434,24 @@ export function deleteCircuitGroupCommand(
|
|||
);
|
||||
}
|
||||
|
||||
export function reorderCircuitGroupsCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
circuitListId: string,
|
||||
assignments: CircuitGroupReorderAssignment[]
|
||||
) {
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
schemaVersion: 1,
|
||||
type: "circuit-group.reorder",
|
||||
payload: { circuitListId, assignments },
|
||||
},
|
||||
"Stromkreisgruppen sortieren"
|
||||
);
|
||||
}
|
||||
|
||||
export function updateCircuitProtectionCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ import {
|
|||
type CircuitGroupCategory,
|
||||
} from "../../shared/constants/circuit-group";
|
||||
import type { CircuitTreeSectionDto } from "../types";
|
||||
import type {
|
||||
CircuitGroupReorderAssignment,
|
||||
} from "../../domain/models/circuit-group-structure-project-command.model";
|
||||
|
||||
export function toCircuitGroupSnapshot(
|
||||
section: CircuitTreeSectionDto,
|
||||
|
|
@ -77,6 +80,41 @@ export function canDeleteCircuitGroup(
|
|||
return section.circuits.length === 0 && section.components.length === 0;
|
||||
}
|
||||
|
||||
export function buildCircuitGroupReorderAssignments(
|
||||
sections: readonly CircuitTreeSectionDto[],
|
||||
groupId: string,
|
||||
direction: -1 | 1
|
||||
): CircuitGroupReorderAssignment[] | null {
|
||||
const current = sections.find((section) => section.id === groupId);
|
||||
if (!current?.category) {
|
||||
return null;
|
||||
}
|
||||
const categoryGroups = sections
|
||||
.filter((section) => section.category === current.category)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
left.sortOrder - right.sortOrder ||
|
||||
left.id.localeCompare(right.id)
|
||||
);
|
||||
const currentIndex = categoryGroups.findIndex(
|
||||
(section) => section.id === groupId
|
||||
);
|
||||
const target = categoryGroups[currentIndex + direction];
|
||||
if (!target) {
|
||||
return null;
|
||||
}
|
||||
return sections.map((section) => ({
|
||||
groupId: section.id,
|
||||
expectedSortOrder: section.sortOrder,
|
||||
targetSortOrder:
|
||||
section.id === current.id
|
||||
? target.sortOrder
|
||||
: section.id === target.id
|
||||
? current.sortOrder
|
||||
: section.sortOrder,
|
||||
}));
|
||||
}
|
||||
|
||||
function getNewGroupSortOrder(
|
||||
category: CircuitGroupCategory,
|
||||
sections: readonly (CircuitTreeSectionDto & {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue