Skip to content

Commit

Permalink
Fix unsaved changes logic when a resources is deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
kelanik8 committed Oct 19, 2023
1 parent 0073c0b commit 520a7de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
7 changes: 6 additions & 1 deletion client/web/compose/src/views/Admin/Charts/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ export default {
handleDelete () {
this.deleteChart(this.chart).then(() => {
this.chart.deletedAt = new Date()
this.toastSuccess(this.$t('notification:chart.deleted'))
this.$router.push({ name: 'admin.charts' })
}).catch(this.toastErrorHandler(this.$t('notification:chart.deleteFailed')))
Expand Down Expand Up @@ -675,7 +677,10 @@ export default {
},
checkUnsavedChart (next) {
next(!isEqual(this.chart, this.initialChartState) ? window.confirm(this.$t('notification.unsavedChanges')) : true)
if (!this.chart.deletedAt) {
return next(!isEqual(this.chart, this.initialChartState) ? window.confirm(this.$t('notification.unsavedChanges')) : true)
}
next()
},
},
}
Expand Down
8 changes: 7 additions & 1 deletion client/web/compose/src/views/Admin/Modules/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,11 @@ export default {
}),
checkUnsavedModule (next) {
next(!isEqual(this.module.clone(), this.initialModuleState.clone()) ? window.confirm(this.$t('general.unsavedChanges')) : true)
if (!this.module.deletedAt) {
return next(!isEqual(this.module.clone(), this.initialModuleState.clone()) ? window.confirm(this.$t('general.unsavedChanges')) : true)
}
next()
},
handleNewField () {
Expand Down Expand Up @@ -828,6 +832,8 @@ export default {
this.processing = true
this.deleteModule(this.module).then(() => {
this.module.deletedAt = new Date()
const moduleRecordPage = this.pages.find(p => p.moduleID === this.module.moduleID)
if (moduleRecordPage) {
return this.deletePage({ ...moduleRecordPage, strategy: 'rebase' })
Expand Down
12 changes: 9 additions & 3 deletions client/web/compose/src/views/Admin/Pages/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,8 @@ export default {
handleDeletePage (strategy = 'abort') {
this.deletePage({ ...this.page, strategy }).then(() => {
this.page.deletedAt = new Date()
this.$router.push({ name: 'admin.pages' })
}).catch(this.toastErrorHandler(this.$t('notification:page.deleteFailed')))
},
Expand Down Expand Up @@ -1314,10 +1316,14 @@ export default {
},
checkUnsavedComposePage (next) {
const layoutsStateChange = this.layouts.some((layout) => layout.meta.updated)
const pageStateChange = !isEqual(this.page, this.initialPageState)
if (!this.page.deletedAt) {
const layoutsStateChange = this.layouts.some((layout) => layout.meta.updated)
const pageStateChange = !isEqual(this.page, this.initialPageState)
return next((layoutsStateChange || pageStateChange) ? window.confirm(this.$t('unsavedChanges')) : true)
}
next((layoutsStateChange || pageStateChange) ? window.confirm(this.$t('unsavedChanges')) : true)
next()
},
setDefaultValues () {
Expand Down
14 changes: 10 additions & 4 deletions client/web/compose/src/views/Namespace/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,8 @@ export default {
this.deleteNamespace({ namespaceID })
.catch(this.toastErrorHandler(this.$t('notification:namespace.deleteFailed')))
.then(() => {
this.namespace.deletedAt = new Date()
if (applicationID) {
return this.$SystemAPI.applicationDelete({ applicationID })
}
Expand Down Expand Up @@ -739,11 +741,15 @@ export default {
},
checkUnsavedNamespace (next) {
const namespaceState = !isEqual(this.namespace.clone(), this.initialNamespaceState.clone())
const isApplicationState = !(this.isApplication === this.isApplicationInitialState)
const namespaceAssetsState = !isEqual(this.namespaceAssets, this.namespaceAssetsInitialState)
if (!this.namespace.deletedAt) {
const namespaceState = !isEqual(this.namespace.clone(), this.initialNamespaceState.clone())
const isApplicationState = !(this.isApplication === this.isApplicationInitialState)
const namespaceAssetsState = !isEqual(this.namespaceAssets, this.namespaceAssetsInitialState)
return next((namespaceState || isApplicationState || namespaceAssetsState) ? window.confirm(this.$t('manage.unsavedChanges')) : true)
}
next((namespaceState || isApplicationState || namespaceAssetsState) ? window.confirm(this.$t('manage.unsavedChanges')) : true)
next()
},
setDefaultValues () {
Expand Down

0 comments on commit 520a7de

Please sign in to comment.