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 24, 2023
1 parent f2527ef commit 84bfc13
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 23 deletions.
4 changes: 2 additions & 2 deletions client/web/admin/src/views/Automation/Workflow/Editor.vue
Expand Up @@ -206,7 +206,6 @@ export default {
this.$AutomationAPI.workflowUndelete({ workflowID: this.workflowID })
.then(() => {
this.fetchWorkflow()
this.toastSuccess(this.$t('notification:workflow.undelete.success'))
})
.catch(this.toastErrorHandler(this.$t('notification:workflow.undelete.error')))
Expand All @@ -217,6 +216,7 @@ export default {
this.$AutomationAPI.workflowDelete({ workflowID: this.workflowID })
.then(() => {
this.fetchWorkflow()
this.workflow.deletedAt = new Date()
this.toastSuccess(this.$t('notification:workflow.delete.success'))
this.$router.push({ name: 'automation.workflow' })
Expand All @@ -236,7 +236,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.workflow.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.workflow, this.initialWorkflowState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
4 changes: 3 additions & 1 deletion client/web/admin/src/views/Federation/Nodes/Editor.vue
Expand Up @@ -313,6 +313,8 @@ export default {
.then(() => {
this.fetchNode()
this.node.deletedAt = new Date()
this.toastSuccess(this.$t('notification:federation.delete.success'))
this.$router.push({ name: 'federation.nodes' })
})
Expand Down Expand Up @@ -363,7 +365,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.node.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.node, this.initialNodeState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
4 changes: 3 additions & 1 deletion client/web/admin/src/views/System/Apigw/Editor.vue
Expand Up @@ -226,6 +226,8 @@ export default {
.then(() => {
this.fetchRoute()
this.route.deletedAt = new Date()
this.toastSuccess(this.$t('notification:gateway.delete.success'))
this.$router.push({ name: 'system.apigw' })
})
Expand Down Expand Up @@ -347,7 +349,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.route.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
const routeState = !isEqual(this.route, this.initialRouteState)
Expand Down
4 changes: 3 additions & 1 deletion client/web/admin/src/views/System/Application/Editor.vue
Expand Up @@ -330,6 +330,8 @@ export default {
.then(() => {
this.fetchApplication()
this.application.deletedAt = new Date()
this.toastSuccess(this.$t('notification:application.delete.success'))
this.$router.push({ name: 'system.application' })
})
Expand All @@ -343,7 +345,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.application.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.application, this.initialApplicationState) || this.unifyAssetStateChange ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
4 changes: 3 additions & 1 deletion client/web/admin/src/views/System/AuthClient/Editor.vue
Expand Up @@ -188,6 +188,8 @@ export default {
.then(() => {
this.fetchAuthclient()
this.authclient.deletedAt = new Date()
this.toastSuccess(this.$t('notification:authclient.delete.success'))
this.$router.push({ name: 'system.authClient' })
})
Expand Down Expand Up @@ -223,7 +225,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.authclient.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.authclient, this.initialAuthclientState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
3 changes: 2 additions & 1 deletion client/web/admin/src/views/System/Connection/Editor.vue
Expand Up @@ -247,6 +247,7 @@ export default {
/**
* Resource deleted, move back to the list
*/
this.connection.deletedAt = new Date()
this.$router.push({ name: `system.connection` })
} else {
this.connection.deletedAt = null
Expand All @@ -261,7 +262,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.connection.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.connection, this.initialConnectionState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
7 changes: 5 additions & 2 deletions client/web/admin/src/views/System/Queue/Editor.vue
Expand Up @@ -197,7 +197,10 @@ export default {
.then(() => {
this.fetchQueue()
this.toastSuccess(this.$t(`notification:queue.${event}.success`))
if (!deletedAt) this.$router.push({ name: 'system.queue' })
if (!deletedAt) {
this.queue.deletedAt = new Date()
this.$router.push({ name: 'system.queue' })
}
})
.catch(this.toastErrorHandler(this.$t(`notification:queue.${event}.error`)))
.finally(() => {
Expand All @@ -208,7 +211,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.queue.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.queue, this.initialQueueState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
3 changes: 2 additions & 1 deletion client/web/admin/src/views/System/Role/Editor.vue
Expand Up @@ -229,6 +229,7 @@ export default {
.then(() => {
this.fetchRole()
this.role.deletedAt = new Date()
this.toastSuccess(this.$t('notification:role.delete.success'))
this.$router.push({ name: 'system.role' })
})
Expand Down Expand Up @@ -334,7 +335,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.role.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
const isDirty = (this.roleMembers || []).some(m => m.dirty !== m.current) || !isEqual(this.role, this.initialRoleState)
Expand Down
Expand Up @@ -188,6 +188,7 @@ export default {
.then(() => {
this.fetchSensitivityLevel()
this.sensitivityLevel.deletedAt = new Date()
this.toastSuccess(this.$t('notification:sensitivityLevel.delete.success'))
this.$router.push({ name: 'system.sensitivityLevel' })
})
Expand All @@ -199,7 +200,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.sensitivityLevel.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.sensitivityLevel, this.initialSensitivityLevelState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
3 changes: 2 additions & 1 deletion client/web/admin/src/views/System/Template/Editor.vue
Expand Up @@ -193,6 +193,7 @@ export default {
.then(() => {
this.fetchTemplate()
this.template.deletedAt = new Date()
this.toastSuccess(this.$t('notification:template.delete.success'))
this.$router.push({ name: 'system.template' })
})
Expand Down Expand Up @@ -240,7 +241,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.template.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
next(!isEqual(this.template, this.initialTemplateState) ? window.confirm(this.$t('general:editor.unsavedChanges')) : true)
Expand Down
3 changes: 2 additions & 1 deletion client/web/admin/src/views/System/User/Editor.vue
Expand Up @@ -349,6 +349,7 @@ export default {
.then(() => {
this.fetchUser()
this.user.deletedAt = new Date()
this.toastSuccess(this.$t('notification:user.delete.success'))
this.$router.push({ name: 'system.user' })
})
Expand Down Expand Up @@ -525,7 +526,7 @@ export default {
checkUnsavedChanges (next, to) {
const isNewPage = this.$route.path.includes('/new') && to.name.includes('edit')
if (isNewPage) {
if (isNewPage || this.user.deletedAt) {
next(true)
} else if (!to.name.includes('edit')) {
let userChangesStatus = !isEqual(this.user, this.initialUserState)
Expand Down
7 changes: 6 additions & 1 deletion client/web/compose/src/views/Admin/Charts/Edit.vue
Expand Up @@ -825,6 +825,8 @@ export default {
this.processingDelete = true
this.deleteChart(this.chart).then(() => {
this.chart.deletedAt = new Date()
this.toastSuccess(this.$t('notification:chart.deleted'))
this.$router.push({ name: 'admin.charts' })
})
Expand Down Expand Up @@ -953,7 +955,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
Expand Up @@ -735,7 +735,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 @@ -853,6 +857,8 @@ export default {
this.processingDelete = 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
Expand Up @@ -1283,6 +1283,8 @@ export default {
this.processingDelete = true
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 @@ -1403,10 +1405,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
Expand Up @@ -673,6 +673,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 @@ -780,11 +782,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
1 change: 1 addition & 0 deletions client/web/reporter/src/mixins/report.js
Expand Up @@ -80,6 +80,7 @@ export default {

return this.$SystemAPI.reportDelete(this.report)
.then(() => {
this.report.deletedAt = new Date()
this.toastSuccess(this.$t('notification:report.delete'))
this.$router.push({ name: 'report.list' })
})
Expand Down
4 changes: 4 additions & 0 deletions client/web/reporter/src/views/Report/Builder.vue
Expand Up @@ -975,6 +975,10 @@ export default {
// Trigger browser dialog on page leave to prevent unsaved changes
checkUnsavedBlocks (next) {
if (this.report.deletedAt) {
return next(true)
}
next(!this.unsavedBlocks.size || window.confirm(this.$t('builder:unsaved-changes')))
},
Expand Down
4 changes: 4 additions & 0 deletions client/web/reporter/src/views/Report/Edit.vue
Expand Up @@ -299,6 +299,10 @@ export default {
},
checkUnsavedChart (next) {
if (this.report.deletedAt) {
return next(true)
}
const reportState = {
handle: this.report.handle,
meta: {
Expand Down
3 changes: 2 additions & 1 deletion client/web/workflow/src/views/Workflow/Editor.vue
Expand Up @@ -94,7 +94,7 @@ export default {
},
beforeRouteLeave (to, from, next) {
if (this.changeDetected) {
if (this.changeDetected && !this.workflow.deletedAt) {
next(window.confirm(this.$t('notification:confirm-unsaved-changes')))
} else {
window.onbeforeunload = null
Expand Down Expand Up @@ -197,6 +197,7 @@ export default {
.then(() => {
// Disable unsaved changes prompt
this.workflow = {}
this.workflow.deletedAt = new Date()
this.$router.push({ name: 'workflow.list' })
this.toastSuccess(this.$t('notification:delete.success'))
})
Expand Down

0 comments on commit 84bfc13

Please sign in to comment.