From eb9465907ecd47b6d6d0aaea26d1ad18188b0bf1 Mon Sep 17 00:00:00 2001 From: Kelani Tolulope Date: Mon, 16 Oct 2023 20:02:53 +0100 Subject: [PATCH] apply review changes --- .../compose/src/views/Admin/Charts/Edit.vue | 22 +++---- .../compose/src/views/Admin/Modules/Edit.vue | 60 ++++--------------- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/client/web/compose/src/views/Admin/Charts/Edit.vue b/client/web/compose/src/views/Admin/Charts/Edit.vue index d1245e7ea7..a10b53b03c 100644 --- a/client/web/compose/src/views/Admin/Charts/Edit.vue +++ b/client/web/compose/src/views/Admin/Charts/Edit.vue @@ -528,9 +528,8 @@ export default { const { namespaceID } = this.namespace if (chartID === NoID) { - const chartClone = this.$attrs.chart || {} + let c = new compose.Chart({ namespaceID: this.namespace.namespaceID }) - let c = new compose.Chart({ namespaceID: this.namespace.namespaceID, ...chartClone }) switch (this.category) { case 'gauge': c = new compose.GaugeChart(c) @@ -616,16 +615,18 @@ export default { this.processing = false }, - handleSave ({ closeOnSuccess = false } = {}) { + handleSave ({ closeOnSuccess = false, chart } = {}) { /** * Pass a special tag alongside payload that * instructs store layer to add content-language header to the API request */ const resourceTranslationLanguage = this.currentLanguage - const c = Object.assign({}, this.chart, resourceTranslationLanguage) + const selectedChart = chart || this.chart - if (this.chart.chartID === NoID) { + const c = Object.assign({}, selectedChart, resourceTranslationLanguage) + + if (selectedChart.chartID === NoID) { this.createChart(c).then(({ chartID }) => { this.toastSuccess(this.$t('notification:chart.saved')) this.initialChartState = cloneDeep(chartConstructor(this.chart)) @@ -660,16 +661,7 @@ export default { chart.name = `${this.chart.name} (copy)` chart.handle = `${this.chart.handle}_copy` - const resourceTranslationLanguage = this.currentLanguage - - const c = Object.assign({}, chart, resourceTranslationLanguage) - - this.createChart(c).then(({ chartID }) => { - this.toastSuccess(this.$t('notification:chart.saved')) - this.initialChartState = cloneDeep(chartConstructor(this.chart)) - - this.$router.push({ name: 'admin.charts.edit', params: { chartID: chartID } }) - }).catch(this.toastErrorHandler(this.$t('notification:chart.saveFailed'))) + this.handleSave({ chart }) }, redirect () { diff --git a/client/web/compose/src/views/Admin/Modules/Edit.vue b/client/web/compose/src/views/Admin/Modules/Edit.vue index 6040968e71..8b83a8eacf 100644 --- a/client/web/compose/src/views/Admin/Modules/Edit.vue +++ b/client/web/compose/src/views/Admin/Modules/Edit.vue @@ -658,14 +658,10 @@ export default { this.activeTab = 0 if (moduleID === NoID) { - if (this.$attrs.module) { - this.module = new compose.Module(this.$attrs.module, this.namespace) - } else { - this.module = new compose.Module( - { fields: [new compose.ModuleFieldString({ fieldID: NoID, name: this.$t('general.placeholder.sample') })] }, - this.namespace, - ) - } + this.module = new compose.Module( + { fields: [new compose.ModuleFieldString({ fieldID: NoID, name: this.$t('general.placeholder.sample') })] }, + this.namespace, + ) this.initialModuleState = this.module.clone() } else { @@ -766,7 +762,7 @@ export default { this.module.config = { ...this.module.config, ...changes } }, - handleSave ({ closeOnSuccess = false } = {}) { + handleSave ({ closeOnSuccess = false, module } = {}) { /** * Pass a special tag alongside payload that * instructs store layer to add content-language header to the API request @@ -774,11 +770,13 @@ export default { const resourceTranslationLanguage = this.currentLanguage this.processing = true - if (!this.isEdit) { + const selectedModule = module || this.module + + if (selectedModule.moduleID === NoID) { // Filter out record fields that reference this not yet created module let fields = [] const toBeUpdatedFields = [] - this.module.fields.forEach(f => { + selectedModule.fields.forEach(f => { if (f.kind === 'Record' && f.options.moduleID === '-1') { toBeUpdatedFields.push(f) } else { @@ -788,7 +786,7 @@ export default { // If such fields exist , after module is created add fields, map moduleID and update module // Unfortunately this ruins the initial field order, but we can improve this later - this.createModule({ ...this.module, fields, resourceTranslationLanguage }).then(async module => { + this.createModule({ ...selectedModule, fields, resourceTranslationLanguage }).then(async module => { if (toBeUpdatedFields.length) { fields = [ ...module.fields, @@ -815,7 +813,7 @@ export default { this.processing = false }) } else { - this.updateModule({ ...this.module, resourceTranslationLanguage }).then(module => { + this.updateModule({ ...selectedModule, resourceTranslationLanguage }).then(module => { this.module = new compose.Module({ ...module }, this.namespace) this.initialModuleState = this.module.clone() @@ -852,41 +850,7 @@ export default { module.name = `${this.module.name} (copy)` module.handle = `${this.module.handle}_copy` - const resourceTranslationLanguage = this.currentLanguage - this.processing = true - - // Filter out record fields that reference this not yet created module - let fields = [] - const toBeUpdatedFields = [] - module.fields.forEach(f => { - if (f.kind === 'Record' && f.options.moduleID === '-1') { - toBeUpdatedFields.push(f) - } else { - fields.push(f) - } - }) - - // If such fields exist , after module is created add fields, map moduleID and update module - // Unfortunately this ruins the initial field order, but we can improve this later - this.createModule({ ...module, fields, resourceTranslationLanguage }).then(async module => { - if (toBeUpdatedFields.length) { - fields = [ - ...module.fields, - ...toBeUpdatedFields.map(f => { - f.options.moduleID = module.moduleID - return f - }), - ] - - module = await this.updateModule({ ...module, fields }) - } - - this.toastSuccess(this.$t('notification:module.created')) - this.$router.push({ name: 'admin.modules.edit', params: { moduleID: module.moduleID } }) - }).catch(this.toastErrorHandler(this.$t('notification:module.saveFailed'))) - .finally(() => { - this.processing = false - }) + this.handleSave({ module }) }, async fetchConnection (connectionID) {