From 57b636a10198bc9f98f302072674effe5e506086 Mon Sep 17 00:00:00 2001 From: Teisha McRae Date: Mon, 15 Jun 2026 16:45:07 -0400 Subject: [PATCH] Prefer collection schema fields when available Use a forwarded `fields` array (when present on the v-model payload) to populate column/field options in inspector components instead of inferring columns from the first record. --- .../inspector/collection-data-source.vue | 21 ++++++++++++++----- .../inspector/collection-records-list.vue | 19 +++++++---------- src/components/inspector/column-setup.vue | 19 +++++++++++++---- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/components/inspector/collection-data-source.vue b/src/components/inspector/collection-data-source.vue index 92fe0154..cf217abb 100644 --- a/src/components/inspector/collection-data-source.vue +++ b/src/components/inspector/collection-data-source.vue @@ -185,13 +185,24 @@ export default { } }, getCollectionColumns(records) { - const [firstRecord] = records?.dataRecordList || []; + this.singleFieldOptions = []; - if (firstRecord?.data) { - this.singleFieldOptions = []; - const dataObject = firstRecord.data; + // Prefer the collection schema when CollectionRecordsList has + // forwarded it on the v-model payload. + if (Array.isArray(records?.fields) && records.fields.length > 0) { + records.fields.forEach((field) => { + this.singleFieldOptions.push({ + text: field.text || field.value, + value: field.value + }); + }); + return; + } - for (const [key] of Object.entries(dataObject)) { + // Fallback: get columns from the first record's populated keys. + const [firstRecord] = records?.dataRecordList || []; + if (firstRecord?.data) { + for (const [key] of Object.entries(firstRecord.data)) { this.singleFieldOptions.push({ text: key, value: key }); } } diff --git a/src/components/inspector/collection-records-list.vue b/src/components/inspector/collection-records-list.vue index 097222e5..a894e16e 100644 --- a/src/components/inspector/collection-records-list.vue +++ b/src/components/inspector/collection-records-list.vue @@ -35,7 +35,8 @@ import ScreenVariableSelector from "../screen-variable-selector.vue"; const CONFIG_FIELDS = [ "collectionId", "pmql", - "dataRecordList" + "dataRecordList", + "fields" ]; export default { @@ -144,22 +145,18 @@ export default { }, getFields() { if (!this.collectionId) { + this.fields = []; return; } this.$dataProvider .getCollectionFields(this.collectionId) .then((response) => { - this.fields = [ - { value: null, text: this.$t("Select a field") }, - { value: "id", text: this.$t("Collection Record ID") }, - ...response.data.data.map((field) => { - return { - text: field.label, - value: field.field - }; - }) - ]; + const dataColumns = response?.data?.data || []; + this.fields = dataColumns.map((field) => ({ + text: field.label || field.field, + value: field.field + })); this.onCollectionChange(); }); diff --git a/src/components/inspector/column-setup.vue b/src/components/inspector/column-setup.vue index f7aa4f6c..89daf59c 100644 --- a/src/components/inspector/column-setup.vue +++ b/src/components/inspector/column-setup.vue @@ -395,12 +395,23 @@ export default { }, getCollectionColumns(collection) { this.collectionOptions = [{ text: "All columns", value: "all" }]; - const [firstRecord] = collection?.dataRecordList || []; - if (firstRecord?.data) { - const dataObject = firstRecord.data; + // Prefer the collection schema when CollectionRecordsList + // has forwarded it on the v-model payload. + if (Array.isArray(collection?.fields) && collection.fields.length > 0) { + collection.fields.forEach((field) => { + this.collectionOptions.push({ + text: field.text || field.value, + value: field.value + }); + }); + return; + } - for (const [key, value] of Object.entries(dataObject)) { + // Fallback: get columns from the first record's populated keys. + const [firstRecord] = collection?.dataRecordList || []; + if (firstRecord?.data) { + for (const [key] of Object.entries(firstRecord.data)) { this.collectionOptions.push({ text: key, value: key }); } }