Persist device row moves
This commit is contained in:
+37
-24
@@ -33,6 +33,9 @@ import type {
|
||||
import type {
|
||||
CircuitSnapshot,
|
||||
} from "../../domain/models/circuit-structure-project-command.model";
|
||||
import type {
|
||||
CircuitDeviceRowMoveAssignment,
|
||||
} from "../../domain/models/circuit-device-row-move-project-command.model";
|
||||
|
||||
async function request<T>(url: string, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(url, {
|
||||
@@ -212,12 +215,6 @@ export function deleteCircuitCommand(
|
||||
);
|
||||
}
|
||||
|
||||
export function deleteCircuitById(circuitId: string) {
|
||||
return request<void>(`/api/circuits/${circuitId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export function getNextCircuitIdentifier(sectionId: string) {
|
||||
return request<{ sectionId: string; nextIdentifier: string }>(
|
||||
`/api/circuit-sections/${sectionId}/next-identifier`
|
||||
@@ -275,28 +272,44 @@ export function deleteCircuitDeviceRowCommand(
|
||||
);
|
||||
}
|
||||
|
||||
export function moveCircuitDeviceRowById(
|
||||
rowId: string,
|
||||
input: { targetCircuitId?: string; targetSectionId?: string; createNewCircuit?: boolean }
|
||||
export function moveCircuitDeviceRowsCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
moves: CircuitDeviceRowMoveAssignment[],
|
||||
description: string
|
||||
) {
|
||||
return request(`/api/circuit-device-rows/${rowId}/move`, {
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(input),
|
||||
});
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
schemaVersion: 1,
|
||||
type: "circuit-device-row.move",
|
||||
payload: { moves },
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
export function moveCircuitDeviceRowsBulk(input: {
|
||||
rowIds: string[];
|
||||
targetCircuitId?: string;
|
||||
targetSectionId?: string;
|
||||
createNewCircuit?: boolean;
|
||||
}) {
|
||||
return request<{ movedRowIds: string[]; targetCircuitId: string; createdCircuitId?: string }>(
|
||||
"/api/circuit-device-rows/move-bulk",
|
||||
export function moveCircuitDeviceRowsToNewCircuitCommand(
|
||||
projectId: string,
|
||||
expectedRevision: number,
|
||||
targetCircuit: CircuitSnapshot,
|
||||
moves: CircuitDeviceRowMoveAssignment[],
|
||||
description: string
|
||||
) {
|
||||
return executeProjectCommand(
|
||||
projectId,
|
||||
expectedRevision,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(input),
|
||||
}
|
||||
schemaVersion: 1,
|
||||
type: "circuit-device-row.move-with-new-circuit",
|
||||
payload: {
|
||||
targetCircuitAction: "create",
|
||||
targetCircuit,
|
||||
moves,
|
||||
},
|
||||
},
|
||||
description
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user