From 520a7de62139a5a4321cfd8fee5c1e003ba86b65 Mon Sep 17 00:00:00 2001 From: Kelani Tolulope Date: Wed, 4 Oct 2023 08:22:30 +0100 Subject: [PATCH] Fix unsaved changes logic when a resources is deleted --- client/web/compose/src/views/Admin/Charts/Edit.vue | 7 ++++++- .../web/compose/src/views/Admin/Modules/Edit.vue | 8 +++++++- client/web/compose/src/views/Admin/Pages/Edit.vue | 12 +++++++++--- client/web/compose/src/views/Namespace/Edit.vue | 14 ++++++++++---- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/client/web/compose/src/views/Admin/Charts/Edit.vue b/client/web/compose/src/views/Admin/Charts/Edit.vue index 60304cbe9a..a3daa399a8 100644 --- a/client/web/compose/src/views/Admin/Charts/Edit.vue +++ b/client/web/compose/src/views/Admin/Charts/Edit.vue @@ -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'))) @@ -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() }, }, } diff --git a/client/web/compose/src/views/Admin/Modules/Edit.vue b/client/web/compose/src/views/Admin/Modules/Edit.vue index a16c17f7d4..701a3db48e 100644 --- a/client/web/compose/src/views/Admin/Modules/Edit.vue +++ b/client/web/compose/src/views/Admin/Modules/Edit.vue @@ -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 () { @@ -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' }) diff --git a/client/web/compose/src/views/Admin/Pages/Edit.vue b/client/web/compose/src/views/Admin/Pages/Edit.vue index 82c8a2b56d..6723082666 100644 --- a/client/web/compose/src/views/Admin/Pages/Edit.vue +++ b/client/web/compose/src/views/Admin/Pages/Edit.vue @@ -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'))) }, @@ -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 () { diff --git a/client/web/compose/src/views/Namespace/Edit.vue b/client/web/compose/src/views/Namespace/Edit.vue index 8bc919133b..1c26061554 100644 --- a/client/web/compose/src/views/Namespace/Edit.vue +++ b/client/web/compose/src/views/Namespace/Edit.vue @@ -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 }) } @@ -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 () {