Keep Revit and manual row quantities consistent

Editing "Anzahl" on a row with linked Revit objects set manualQuantity to
the new total, so the row no longer matched its objects and detaching
them failed with "row.manualQuantity must not exceed row.quantity".

Such rows now lock "Anzahl" in the editor. The new optional columns
"Anz. manuell" (editable) and "Anz. Revit" (read-only) show both shares;
stored column layouts get them hidden next to "Anzahl". The device-row
update derives the total from a manual-only edit and rejects any change
that breaks quantity = manual + Revit, for every source. Two history
fixtures inserted rows with quantity 1 and the column default
manualQuantity 0, a state no runtime path creates; they now insert 1/1.

Undoing "Revit-Objekte lösen" re-validated planning-value conflicts that
the user had confirmed on the original assignment and was rejected.
Undo/redo of row assignments now restores the accepted state without a
new confirmation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Julian Appel 2026-10-29 14:03:29 +01:00
parent 01312b89fe
commit 898be43ebc
12 changed files with 272 additions and 21 deletions

View file

@ -7,6 +7,7 @@ import { createDatabaseContext, type AppDatabase } from "../src/db/database-cont
import { ExternalObjectRowAssignmentProjectCommandRepository } from "../src/db/repositories/external-object-row-assignment-project-command.repository.js";
import { ExternalObjectNewRowProjectCommandRepository } from "../src/db/repositories/external-object-new-row-project-command.repository.js";
import { ExternalObjectNewCircuitProjectCommandRepository } from "../src/db/repositories/external-object-new-circuit-project-command.repository.js";
import { CircuitDeviceRowProjectCommandRepository } from "../src/db/repositories/circuit-device-row-project-command.repository.js";
import { CircuitDeviceRowStructureProjectCommandRepository } from "../src/db/repositories/circuit-device-row-structure-project-command.repository.js";
import { CircuitStructureProjectCommandRepository } from "../src/db/repositories/circuit-structure-project-command.repository.js";
import { CircuitGroupSubtreeProjectCommandRepository } from "../src/db/repositories/circuit-group-subtree-project-command.repository.js";
@ -24,6 +25,7 @@ import { externalRoomMappings } from "../src/db/schema/external-room-mappings.js
import { floors } from "../src/db/schema/floors.js";
import { projects } from "../src/db/schema/projects.js";
import { rooms } from "../src/db/schema/rooms.js";
import { createCircuitDeviceRowUpdateProjectCommand } from "../src/domain/models/circuit-device-row-project-command.model.js";
import { createExternalObjectRowAssignmentProjectCommand } from "../src/domain/models/external-object-row-assignment-project-command.model.js";
import {
createExternalObjectNewRowProjectCommand,
@ -223,6 +225,36 @@ describe("external object row assignment project command", () => {
}
});
it("re-links a detached object on undo although its planning values differ from the row", () => {
const context = createFixture();
try {
// The original assignment confirmed this planning-value conflict.
context.db.update(circuitDeviceRows).set({ displayName: "Abweichend" }).where(eq(circuitDeviceRows.id, "row-1")).run();
const currentRow = row(context.db, "row-1");
const object = objectSnapshot("row-1");
const repository = new ExternalObjectRowAssignmentProjectCommandRepository(context.db);
const detached = repository.execute({
projectId: "project-1",
expectedRevision: 0,
source: "user",
command: createExternalObjectRowAssignmentProjectCommand({
rows: [{ expected: currentRow, target: { ...currentRow, quantity: 1 } }],
objects: [{ expected: object, target: { ...object, circuitDeviceRowId: null } }],
confirmedConflictObjectIds: [],
}),
});
const undone = repository.execute({ projectId: "project-1", expectedRevision: 1, source: "undo", historyTargetChangeSetId: detached.revision.changeSetId, command: detached.inverse });
assert.equal(context.db.select().from(externalModelObjects).get()!.circuitDeviceRowId, "row-1");
assert.deepEqual([row(context.db, "row-1").quantity, row(context.db, "row-1").manualQuantity], [3, 1]);
repository.execute({ projectId: "project-1", expectedRevision: 2, source: "redo", historyTargetChangeSetId: detached.revision.changeSetId, command: undone.inverse });
assert.equal(context.db.select().from(externalModelObjects).get()!.circuitDeviceRowId, null);
} finally {
context.close();
}
});
it("rolls back row quantities and links when history persistence fails", () => {
const context = createFixture();
try {
@ -245,6 +277,54 @@ describe("external object row assignment project command", () => {
});
});
describe("device-row quantity edits with linked Revit objects", () => {
const quantities = (database: AppDatabase, id: string) => {
const current = row(database, id);
return [current.quantity, current.manualQuantity];
};
it("rejects a total edit on a linked row and keeps Revit and manual share consistent", () => {
const context = createFixture();
try {
const store = new CircuitDeviceRowProjectCommandRepository(context.db);
assert.throws(
() => store.executeUpdate({ projectId: "project-1", expectedRevision: 0, source: "user", command: createCircuitDeviceRowUpdateProjectCommand("row-1", { quantity: 4 }) }),
/mit Revit-Objekten verknüpft/
);
assert.deepEqual(quantities(context.db, "row-1"), [3, 1]);
} finally {
context.close();
}
});
it("derives the total from a manual-share edit through undo and redo", () => {
const context = createFixture();
try {
const store = new CircuitDeviceRowProjectCommandRepository(context.db);
const edited = store.executeUpdate({ projectId: "project-1", expectedRevision: 0, source: "user", command: createCircuitDeviceRowUpdateProjectCommand("row-1", { manualQuantity: 2 }) });
assert.deepEqual(quantities(context.db, "row-1"), [4, 2]);
const undone = store.executeUpdate({ projectId: "project-1", expectedRevision: 1, source: "undo", historyTargetChangeSetId: edited.revision.changeSetId, command: edited.inverse });
assert.deepEqual(quantities(context.db, "row-1"), [3, 1]);
store.executeUpdate({ projectId: "project-1", expectedRevision: 2, source: "redo", historyTargetChangeSetId: edited.revision.changeSetId, command: undone.inverse });
assert.deepEqual(quantities(context.db, "row-1"), [4, 2]);
} finally {
context.close();
}
});
it("keeps editing the total of a row without Revit objects", () => {
const context = createFixture(null);
try {
new CircuitDeviceRowProjectCommandRepository(context.db).executeUpdate({ projectId: "project-1", expectedRevision: 0, source: "user", command: createCircuitDeviceRowUpdateProjectCommand("row-1", { quantity: 5 }) });
assert.deepEqual(quantities(context.db, "row-1"), [5, 5]);
} finally {
context.close();
}
});
});
describe("external object new-row project command", () => {
it("creates an external-only row and supports exact persisted undo and redo", () => {
const context = createFixture(null);