From 5b5af1a7b9e1cd084a2e748741a7743e3fe57ab9 Mon Sep 17 00:00:00 2001 From: Mark Rapson Date: Mon, 26 Oct 2026 01:38:09 +0000 Subject: [PATCH] Preserve API item paths while building editor context --- src/web/public/js/regions/type/api.js | 4 +++- test/api-region-sort.test.js | 13 +++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/web/public/js/regions/type/api.js b/src/web/public/js/regions/type/api.js index dae5168..10f08df 100644 --- a/src/web/public/js/regions/type/api.js +++ b/src/web/public/js/regions/type/api.js @@ -306,7 +306,9 @@ var sourceOptions = String(context.sourceOptions || ''); var itemsPathValue = context.itemsPath !== undefined ? String(context.itemsPath === null ? '' : context.itemsPath) - : String(config.default_items_path || ''); + : config.items_path !== undefined + ? String(config.items_path === null ? '' : config.items_path) + : String(config.default_items_path || ''); var sampleDataPreview = String(context.sampleDataPreview || ''); return { diff --git a/test/api-region-sort.test.js b/test/api-region-sort.test.js index c50ab98..ff7ab02 100644 --- a/test/api-region-sort.test.js +++ b/test/api-region-sort.test.js @@ -256,15 +256,20 @@ test('API editor preserves saved item paths instead of replacing them with the s }; for (const [savedPath, expectedPath] of [['data.players', 'data.players'], ['', ''], [null, ''], [undefined, 'data']]) { - const markup = editor.renderEditorCard({ ...context, config: { ...context.config, items_path: savedPath } }); - assert.match(markup, new RegExp('name="region_api_items_path_23"[^>]*value="' + expectedPath.replace('.', '\\.') + '"')); + const savedContext = { ...context, config: { ...context.config, items_path: savedPath } }; + const builtContext = editor.buildEditorCardContext(savedContext, {}, []); + assert.equal(builtContext.itemsPath, expectedPath); + for (const cardContext of [savedContext, builtContext]) { + const markup = editor.renderEditorCard(cardContext); + assert.match(markup, new RegExp('name="region_api_items_path_23"[^>]*value="' + expectedPath.replace('.', '\\.') + '"')); + } } - const explicitContext = editor.renderEditorCard({ + const explicitContext = editor.renderEditorCard(editor.buildEditorCardContext({ ...context, itemsPath: 'other.players', config: { ...context.config, items_path: 'data.players' } - }); + }, {}, [])); assert.match(explicitContext, /name="region_api_items_path_23"[^>]*value="other\.players"/); });