Skip to content

Commit

Permalink
apply review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelanik8 committed Oct 16, 2023
1 parent ea5d9ac commit 92b5125
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 63 deletions.
22 changes: 7 additions & 15 deletions client/web/compose/src/views/Admin/Charts/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 () {
Expand Down
60 changes: 12 additions & 48 deletions client/web/compose/src/views/Admin/Modules/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -766,19 +762,21 @@ 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
*/
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 {
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 92b5125

Please sign in to comment.