Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/components/inspector/collection-data-source.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
Expand Down
19 changes: 8 additions & 11 deletions src/components/inspector/collection-records-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ import ScreenVariableSelector from "../screen-variable-selector.vue";
const CONFIG_FIELDS = [
"collectionId",
"pmql",
"dataRecordList"
"dataRecordList",
"fields"
];

export default {
Expand Down Expand Up @@ -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();
});
Expand Down
19 changes: 15 additions & 4 deletions src/components/inspector/column-setup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
Expand Down
Loading