From 97c8516b0bdf258143ced96fe961448d29f778f8 Mon Sep 17 00:00:00 2001 From: Kelani Tolulope Date: Wed, 16 Nov 2022 19:08:56 +0100 Subject: [PATCH] Add configuration update for system fields --- .../Admin/Module/DalFieldStoreEncoding.vue | 14 ++++ .../components/Admin/Module/DalSettings.vue | 65 +++++++++++++++---- .../components/Admin/Module/FieldRowView.vue | 7 ++ .../compose/src/views/Admin/Modules/Edit.vue | 7 +- locale/en/corteza-webapp-compose/module.yaml | 8 +++ 5 files changed, 85 insertions(+), 16 deletions(-) diff --git a/client/web/compose/src/components/Admin/Module/DalFieldStoreEncoding.vue b/client/web/compose/src/components/Admin/Module/DalFieldStoreEncoding.vue index dc19fa47d..bc69bf17d 100644 --- a/client/web/compose/src/components/Admin/Module/DalFieldStoreEncoding.vue +++ b/client/web/compose/src/components/Admin/Module/DalFieldStoreEncoding.vue @@ -10,8 +10,17 @@ {{ label }} + + + {{ $t('unavailable') }} +
+
+ + +
+
@@ -93,18 +109,18 @@ export default { data () { const systemFieldEncoding = this.module.config.dal.systemFieldEncoding || {} const systemFields = [ - { field: 'id', storeIdent: 'id' }, - { field: 'namespaceID', storeIdent: 'rel_namespace' }, - { field: 'moduleID', storeIdent: 'rel_module' }, - { field: 'revision', storeIdent: 'revision' }, - { field: 'meta', storeIdent: 'meta' }, - { field: 'ownedBy', storeIdent: 'owned_by' }, - { field: 'createdAt', storeIdent: 'created_at' }, - { field: 'createdBy', storeIdent: 'created_by' }, - { field: 'updatedAt', storeIdent: 'updated_at' }, - { field: 'updatedBy', storeIdent: 'updated_by' }, - { field: 'deletedAt', storeIdent: 'deleted_at' }, - { field: 'deletedBy', storeIdent: 'deleted_by' }, + { field: 'id', storeIdent: 'id', disabled: true }, + { field: 'namespaceID', storeIdent: 'rel_namespace', group: 'partition' }, + { field: 'moduleID', storeIdent: 'rel_module', group: 'partition' }, + { field: 'revision', storeIdent: 'revision', group: 'extras' }, + { field: 'meta', storeIdent: 'meta', group: 'extras' }, + { field: 'ownedBy', storeIdent: 'owned_by', group: 'user_reference' }, + { field: 'createdAt', storeIdent: 'created_at', group: 'timestamps' }, + { field: 'createdBy', storeIdent: 'created_by', group: 'user_reference' }, + { field: 'updatedAt', storeIdent: 'updated_at', group: 'timestamps' }, + { field: 'updatedBy', storeIdent: 'updated_by', group: 'user_reference' }, + { field: 'deletedAt', storeIdent: 'deleted_at', group: 'timestamps' }, + { field: 'deletedBy', storeIdent: 'deleted_by', group: 'user_reference' }, ].map(sf => ({ ...sf, label: this.$t(`field:system.${sf.field}`) })) return { @@ -113,12 +129,20 @@ export default { moduleFields: [], moduleFieldEncoding: [], + selectedGroup: '', systemFields, systemFieldEncoding: systemFields.reduce((enc, { field }) => { enc[field] = systemFieldEncoding[field] || {} return enc }, {}), + optionsGroups: [ + { text: this.$t('system-fields.grouptypes.all'), value: 'all' }, + { text: this.$t('system-fields.grouptypes.partition'), value: 'partition' }, + { text: this.$t('system-fields.grouptypes.userReference'), value: 'user_reference' }, + { text: this.$t('system-fields.grouptypes.timestamps'), value: 'timestamps' }, + { text: this.$t('system-fields.grouptypes.extras'), value: 'extras' }, + ], } }, @@ -218,6 +242,19 @@ export default { return enc }, {}) }, + + applySelectedSystemFields (selectedOption) { + this.systemFieldEncoding = this.systemFields.reduce((enc, { field, group }) => { + if (field !== 'id') { + if (selectedOption === 'all') { + enc[field] = {} + } else { + enc[field] = group === selectedOption ? {} : { omit: true } + } + } + return enc + }, {}) + }, }, } diff --git a/client/web/compose/src/components/Admin/Module/FieldRowView.vue b/client/web/compose/src/components/Admin/Module/FieldRowView.vue index b95f9260c..d2cbd4924 100644 --- a/client/web/compose/src/components/Admin/Module/FieldRowView.vue +++ b/client/web/compose/src/components/Admin/Module/FieldRowView.vue @@ -3,6 +3,13 @@ {{ field.name }} + + {{ $t('unavailable') }} + {{ field.label }} diff --git a/client/web/compose/src/views/Admin/Modules/Edit.vue b/client/web/compose/src/views/Admin/Modules/Edit.vue index 2747cddbe..e245232ea 100644 --- a/client/web/compose/src/views/Admin/Modules/Edit.vue +++ b/client/web/compose/src/views/Admin/Modules/Edit.vue @@ -581,10 +581,13 @@ export default { }, systemFields () { + const systemFieldEncoding = this.module.config.dal.systemFieldEncoding || {} + return this.module.systemFields().map(sf => { + if (!sf) return sf.label = this.$t(`field:system.${sf.name}`) - return sf - }) + return { ...sf, ...(systemFieldEncoding[sf.name] || {}) } + }).filter(sf => sf) }, editModalTitle () { diff --git a/locale/en/corteza-webapp-compose/module.yaml b/locale/en/corteza-webapp-compose/module.yaml index a7174fb6a..b4c20e227 100644 --- a/locale/en/corteza-webapp-compose/module.yaml +++ b/locale/en/corteza-webapp-compose/module.yaml @@ -111,8 +111,16 @@ edit: System fields are used to store metadata about the record. Configure to skip or store them into a column with the same name (Column), a different column (Alias) or encode them into JSON. + grouptypes: + all: All + partition: Partition + userReference: User reference + timestamps: Timestamps + extras: Extras + encoding-strategy: + unavailable: unavailable ident: placeholder: Field or database table column name