From bf8dd9b92d6710a9b9099f2857c5f57960e5fedc Mon Sep 17 00:00:00 2001 From: Eleazar Resendez Date: Wed, 12 Aug 2026 16:11:49 -0600 Subject: [PATCH 1/2] FOUR-32638: Fix Collection record list fields and values --- src/collectionFieldUtils.js | 89 +++++++++ .../inspector/collection-data-source.vue | 23 +-- src/components/inspector/column-setup.vue | 26 +-- src/components/renderer/form-record-list.vue | 40 ++-- .../specs/CollectionRecordListColumns.spec.js | 182 ++++++++++++++++++ tests/unit/CollectionFieldUtils.spec.js | 115 +++++++++++ 6 files changed, 409 insertions(+), 66 deletions(-) create mode 100644 src/collectionFieldUtils.js create mode 100644 tests/e2e/specs/CollectionRecordListColumns.spec.js create mode 100644 tests/unit/CollectionFieldUtils.spec.js diff --git a/src/collectionFieldUtils.js b/src/collectionFieldUtils.js new file mode 100644 index 00000000..2131adcd --- /dev/null +++ b/src/collectionFieldUtils.js @@ -0,0 +1,89 @@ +const COLLECTION_DATA_PREFIX = "data."; + +export function normalizeCollectionFieldPath(fieldPath) { + if (typeof fieldPath !== "string") { + return fieldPath; + } + + return fieldPath.startsWith(COLLECTION_DATA_PREFIX) + ? fieldPath.slice(COLLECTION_DATA_PREFIX.length) + : fieldPath; +} + +export function getCollectionFieldOptions(collection = {}) { + const options = []; + const values = new Set(); + + const addOption = ({ text, value }) => { + const normalizedValue = normalizeCollectionFieldPath(value); + + if (!normalizedValue || values.has(normalizedValue)) { + return; + } + + values.add(normalizedValue); + options.push({ + text: text || normalizedValue, + value: normalizedValue + }); + }; + + if (Array.isArray(collection?.fields) && collection.fields.length > 0) { + collection.fields.forEach((field) => { + if (!field) { + return; + } + + addOption({ + text: field.text || field.value, + value: field.value + }); + }); + } else { + const [firstRecord] = collection?.dataRecordList || []; + + if (firstRecord?.data) { + Object.keys(firstRecord.data).forEach((field) => { + addOption({ text: field, value: field }); + }); + } + } + + addOption({ text: "id", value: "id" }); + + return options; +} + +export function mapCollectionRecordData(data = {}, options = []) { + if (!data || typeof data !== "object" || Array.isArray(data)) { + return {}; + } + + if (!Array.isArray(options) || options.length === 0) { + return { ...data }; + } + + const mappedData = {}; + + options.forEach((option) => { + if (!option) { + return; + } + + const targetKey = normalizeCollectionFieldPath( + option.key || option.content + ); + const sourceKey = [option.content, option.key] + .map(normalizeCollectionFieldPath) + .find( + (candidate) => + candidate && Object.prototype.hasOwnProperty.call(data, candidate) + ); + + if (sourceKey && targetKey) { + mappedData[targetKey] = data[sourceKey]; + } + }); + + return mappedData; +} diff --git a/src/components/inspector/collection-data-source.vue b/src/components/inspector/collection-data-source.vue index cf217abb..0ebf1a80 100644 --- a/src/components/inspector/collection-data-source.vue +++ b/src/components/inspector/collection-data-source.vue @@ -60,6 +60,7 @@