From 36160d36252177c931dd9605e217c48d74b74a3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Bascop=C3=A9?= Date: Thu, 14 Nov 2024 11:49:43 -0400 Subject: [PATCH] Added a method to obtain the screen id for editing collections --- .../inspector/collection-records-list.vue | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/components/inspector/collection-records-list.vue b/src/components/inspector/collection-records-list.vue index 5b0f5693c..0b48f6c45 100644 --- a/src/components/inspector/collection-records-list.vue +++ b/src/components/inspector/collection-records-list.vue @@ -54,7 +54,8 @@ export default { dataRecordList: [], idCollectionScreenView: null, idCollectionScreenEdit: null, - screenMode: null + screenMode: null, + collectionsMap: {} }; }, computed: { @@ -76,6 +77,7 @@ export default { }, collectionId: { handler() { + this.updateScreenIds(); this.getFields(); } }, @@ -114,17 +116,20 @@ export default { }, getCollections() { this.$dataProvider.getCollections().then((response) => { - const [firstItem = {}] = response.data.data || []; - this.idCollectionScreenView = firstItem.read_screen_id; - this.idCollectionScreenEdit = firstItem.create_screen_id; + this.collectionsMap = response.data.data.reduce((acc, collection) => { + acc[collection.id] = { + read_screen_id: collection.read_screen_id, + create_screen_id: collection.create_screen_id + }; + return acc; + }, {}); + this.collections = [ { value: null, text: this.$t("Select a collection") }, - ...response.data.data.map((collection) => { - return { - text: collection.name, - value: collection.id - }; - }) + ...response.data.data.map((collection) => ({ + text: collection.name, + value: collection.id + })) ]; }); }, @@ -155,6 +160,16 @@ export default { }, onPmqlChange(pmql) { this.pmql = pmql; + }, + updateScreenIds() { + if (this.collectionId && this.collectionsMap[this.collectionId]) { + const selectedCollection = this.collectionsMap[this.collectionId]; + this.idCollectionScreenView = selectedCollection.read_screen_id; + this.idCollectionScreenEdit = selectedCollection.create_screen_id; + } else { + this.idCollectionScreenView = null; + this.idCollectionScreenEdit = null; + } } } };