filter out extension layers on load

This commit is contained in:
vcoppe committed 2026-11-08 17:34:35 +01:00
1 parent 4050420b3c
commit 57c34b388b
4 files changed
+52 -42

No files matched your search

+7 -5
View File
@@ -141,11 +141,13 @@ describe('layer trees', () => {
assert.deepEqual(filterLayerTree({}, allowed), allowed);
});
it('drops the layers that are not allowed anymore, but not the custom ones', () => {
it('drops the layers that are not allowed anymore and those of extensions, not the custom ones', () => {
const filtered = filterLayerTree(
{
world: { a: true, gone: true, 'custom-1': true, 'extension-x': false },
world: { a: true, gone: true, 'custom-1': true, 'extension-x': true },
old: { x: true },
extension: { 'extension-Name/y': true },
custom: { 'custom-2': false },
},
allowed
);
@@ -153,10 +155,10 @@ describe('layer trees', () => {
a: true,
b: false,
'custom-1': true,
'extension-x': false,
});
assert.equal('old' in filtered, true);
assert.deepEqual(filtered.old, {});
assert.equal('old' in filtered, false);
assert.equal('extension' in filtered, false);
assert.deepEqual(filtered.custom, { 'custom-2': false });
});
it('does not take a branch for a layer, or a layer for a branch', () => {
+8 -3
View File
@@ -196,7 +196,9 @@ function isRecord(value: unknown): value is Record<string, unknown> {
/**
* The saved tree `t`, with the layers of `allowed`: the choices saved for them are kept, the new
* ones have their default, and of the others only the custom and extension layers are kept.
* ones have their default, and of the others only the custom layers are kept. The layers of
* extensions are saved with the others, but not read back: they come again when an extension sets
* them, if it is still there.
*/
export function filterLayerTree(t: unknown, allowed: LayerTreeType | undefined): LayerTreeType {
const tree = isRecord(t) ? t : {};
@@ -214,11 +216,14 @@ export function filterLayerTree(t: unknown, allowed: LayerTreeType | undefined):
Object.entries(tree).forEach(([key, value]) => {
if (!Object.hasOwn(filtered, key)) {
if (typeof value === 'boolean') {
if (key.startsWith('custom-') || key.startsWith('extension-')) {
if (key.startsWith('custom-')) {
filtered[key] = value;
}
} else if (isRecord(value)) {
filtered[key] = filterLayerTree(value, undefined);
const group = filterLayerTree(value, undefined);
if (Object.keys(group).length > 0) {
filtered[key] = group;
}
}
}
});