diff --git a/client/web/compose/src/views/Admin/Charts/Edit.vue b/client/web/compose/src/views/Admin/Charts/Edit.vue index 7f4472db36..d1245e7ea7 100644 --- a/client/web/compose/src/views/Admin/Charts/Edit.vue +++ b/client/web/compose/src/views/Admin/Charts/Edit.vue @@ -660,14 +660,16 @@ export default { chart.name = `${this.chart.name} (copy)` chart.handle = `${this.chart.handle}_copy` - this.$router.push({ - name: 'admin.charts.create', - params: { - chartID: NoID, - category: this.category || 'generic', - chart, - }, - }) + 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'))) }, redirect () { diff --git a/client/web/compose/src/views/Admin/Modules/Edit.vue b/client/web/compose/src/views/Admin/Modules/Edit.vue index a25ac816fe..6040968e71 100644 --- a/client/web/compose/src/views/Admin/Modules/Edit.vue +++ b/client/web/compose/src/views/Admin/Modules/Edit.vue @@ -852,7 +852,41 @@ export default { module.name = `${this.module.name} (copy)` module.handle = `${this.module.handle}_copy` - this.$router.push({ name: 'admin.modules.create', params: { module, moduleID: NoID } }) + 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 + }) }, async fetchConnection (connectionID) {