Show circuit protection in saved layouts
This commit is contained in:
@@ -30,8 +30,10 @@ import {
|
|||||||
formatPhaseTypeLabel,
|
formatPhaseTypeLabel,
|
||||||
formatValue,
|
formatValue,
|
||||||
getCircuitSectionLabel,
|
getCircuitSectionLabel,
|
||||||
|
getLegacyProjectColumnLayoutStorageKey,
|
||||||
getProjectColumnLayoutStorageKey,
|
getProjectColumnLayoutStorageKey,
|
||||||
isGridEditorControlTarget,
|
isGridEditorControlTarget,
|
||||||
|
migrateLegacyColumnLayout,
|
||||||
normalizeColumnOrder,
|
normalizeColumnOrder,
|
||||||
parseStoredColumnLayout,
|
parseStoredColumnLayout,
|
||||||
} from "../utils/circuit-grid-model";
|
} from "../utils/circuit-grid-model";
|
||||||
@@ -374,14 +376,23 @@ export function CircuitTreeEditor(props: { projectId: string; circuitListId: str
|
|||||||
setColumnOrder(allColumns.map((column) => column.key));
|
setColumnOrder(allColumns.map((column) => column.key));
|
||||||
setVisibleColumnKeys(defaultVisibleColumnKeys);
|
setVisibleColumnKeys(defaultVisibleColumnKeys);
|
||||||
try {
|
try {
|
||||||
const parsed = parseStoredColumnLayout(
|
const currentLayout = parseStoredColumnLayout(
|
||||||
localStorage.getItem(
|
localStorage.getItem(getProjectColumnLayoutStorageKey(projectId))
|
||||||
getProjectColumnLayoutStorageKey(projectId)
|
|
||||||
) ??
|
|
||||||
localStorage.getItem(
|
|
||||||
LEGACY_COLUMN_LAYOUT_STORAGE_KEY
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
const legacyLayout =
|
||||||
|
parseStoredColumnLayout(
|
||||||
|
localStorage.getItem(
|
||||||
|
getLegacyProjectColumnLayoutStorageKey(projectId)
|
||||||
|
)
|
||||||
|
) ??
|
||||||
|
parseStoredColumnLayout(
|
||||||
|
localStorage.getItem(LEGACY_COLUMN_LAYOUT_STORAGE_KEY)
|
||||||
|
);
|
||||||
|
const parsed =
|
||||||
|
currentLayout ??
|
||||||
|
(legacyLayout
|
||||||
|
? migrateLegacyColumnLayout(legacyLayout)
|
||||||
|
: null);
|
||||||
if (!parsed) {
|
if (!parsed) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ export const defaultVisibleColumnKeys = allColumns
|
|||||||
.map((column) => column.key);
|
.map((column) => column.key);
|
||||||
|
|
||||||
const projectColumnLayoutStoragePrefix =
|
const projectColumnLayoutStoragePrefix =
|
||||||
|
"circuitTreeEditor.columnLayout.v3";
|
||||||
|
const legacyProjectColumnLayoutStoragePrefix =
|
||||||
"circuitTreeEditor.columnLayout.v2";
|
"circuitTreeEditor.columnLayout.v2";
|
||||||
|
|
||||||
export interface CircuitColumnLayout {
|
export interface CircuitColumnLayout {
|
||||||
@@ -162,6 +164,12 @@ export function getProjectColumnLayoutStorageKey(
|
|||||||
return `${projectColumnLayoutStoragePrefix}.${projectId}`;
|
return `${projectColumnLayoutStoragePrefix}.${projectId}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getLegacyProjectColumnLayoutStorageKey(
|
||||||
|
projectId: string
|
||||||
|
): string {
|
||||||
|
return `${legacyProjectColumnLayoutStoragePrefix}.${projectId}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizeColumnOrder(keys: CellKey[]): CellKey[] {
|
export function normalizeColumnOrder(keys: CellKey[]): CellKey[] {
|
||||||
const unique = [...new Set(keys)];
|
const unique = [...new Set(keys)];
|
||||||
const allKeys = allColumns.map((column) => column.key);
|
const allKeys = allColumns.map((column) => column.key);
|
||||||
@@ -225,6 +233,28 @@ export function parseStoredColumnLayout(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function migrateLegacyColumnLayout(
|
||||||
|
layout: CircuitColumnLayout
|
||||||
|
): CircuitColumnLayout {
|
||||||
|
const newlyVisibleKey: CellKey = "protectionSummary";
|
||||||
|
const order = layout.order.filter(
|
||||||
|
(key) => key !== newlyVisibleKey
|
||||||
|
) as CellKey[];
|
||||||
|
const totalPowerIndex = order.indexOf("rowTotalPower");
|
||||||
|
order.splice(
|
||||||
|
totalPowerIndex >= 0 ? totalPowerIndex + 1 : order.length,
|
||||||
|
0,
|
||||||
|
newlyVisibleKey
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
order,
|
||||||
|
visible: layout.visible.includes(newlyVisibleKey)
|
||||||
|
? layout.visible
|
||||||
|
: [...layout.visible, newlyVisibleKey],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const deviceOnlyColumns = new Set<CellKey>([
|
const deviceOnlyColumns = new Set<CellKey>([
|
||||||
"quantity",
|
"quantity",
|
||||||
"powerPerUnit",
|
"powerPerUnit",
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import {
|
|||||||
buildDeviceRowEditPatch,
|
buildDeviceRowEditPatch,
|
||||||
formatValue,
|
formatValue,
|
||||||
getCircuitSectionLabel,
|
getCircuitSectionLabel,
|
||||||
|
getLegacyProjectColumnLayoutStorageKey,
|
||||||
getProjectColumnLayoutStorageKey,
|
getProjectColumnLayoutStorageKey,
|
||||||
isGridEditorControlTarget,
|
isGridEditorControlTarget,
|
||||||
getBlockSortValue,
|
getBlockSortValue,
|
||||||
getCellKind,
|
getCellKind,
|
||||||
getCircuitValue,
|
getCircuitValue,
|
||||||
getDeviceValue,
|
getDeviceValue,
|
||||||
|
migrateLegacyColumnLayout,
|
||||||
parseStoredColumnLayout,
|
parseStoredColumnLayout,
|
||||||
parseNumeric,
|
parseNumeric,
|
||||||
} from "../src/frontend/utils/circuit-grid-model.js";
|
} from "../src/frontend/utils/circuit-grid-model.js";
|
||||||
@@ -79,6 +81,10 @@ describe("circuit grid model", () => {
|
|||||||
it("stores valid column layouts under a project-specific key", () => {
|
it("stores valid column layouts under a project-specific key", () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
getProjectColumnLayoutStorageKey("project-1"),
|
getProjectColumnLayoutStorageKey("project-1"),
|
||||||
|
"circuitTreeEditor.columnLayout.v3.project-1"
|
||||||
|
);
|
||||||
|
assert.equal(
|
||||||
|
getLegacyProjectColumnLayoutStorageKey("project-1"),
|
||||||
"circuitTreeEditor.columnLayout.v2.project-1"
|
"circuitTreeEditor.columnLayout.v2.project-1"
|
||||||
);
|
);
|
||||||
const layout = parseStoredColumnLayout(
|
const layout = parseStoredColumnLayout(
|
||||||
@@ -100,6 +106,39 @@ describe("circuit grid model", () => {
|
|||||||
assert.equal(parseStoredColumnLayout("{invalid"), null);
|
assert.equal(parseStoredColumnLayout("{invalid"), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("adds the circuit protection column to legacy project layouts", () => {
|
||||||
|
const legacyLayout = parseStoredColumnLayout(
|
||||||
|
JSON.stringify({
|
||||||
|
order: [
|
||||||
|
"equipmentIdentifier",
|
||||||
|
"displayName",
|
||||||
|
"rowTotalPower",
|
||||||
|
"remark",
|
||||||
|
],
|
||||||
|
visible: [
|
||||||
|
"equipmentIdentifier",
|
||||||
|
"displayName",
|
||||||
|
"rowTotalPower",
|
||||||
|
"remark",
|
||||||
|
],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
assert.ok(legacyLayout);
|
||||||
|
|
||||||
|
const migrated = migrateLegacyColumnLayout(legacyLayout);
|
||||||
|
assert.equal(
|
||||||
|
migrated.order.indexOf("protectionSummary"),
|
||||||
|
migrated.order.indexOf("rowTotalPower") + 1
|
||||||
|
);
|
||||||
|
assert.deepEqual(migrated.visible, [
|
||||||
|
"equipmentIdentifier",
|
||||||
|
"displayName",
|
||||||
|
"rowTotalPower",
|
||||||
|
"remark",
|
||||||
|
"protectionSummary",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("shows stable circuit sections with German labels", () => {
|
it("shows stable circuit sections with German labels", () => {
|
||||||
assert.equal(
|
assert.equal(
|
||||||
getCircuitSectionLabel({
|
getCircuitSectionLabel({
|
||||||
|
|||||||
Reference in New Issue
Block a user