From 733c56e7fcf26c7b60224684d14d361df1d03076 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Thu, 21 Sep 2023 14:48:37 +0200 Subject: [PATCH] Fix lib/js tests --- .../components/PageBlocks/RecordListBase.vue | 2 +- .../compose/src/views/Admin/Pages/Builder.vue | 20 +++++++++++++++++-- lib/js/src/compose/types/page-block/base.ts | 4 ++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/client/web/compose/src/components/PageBlocks/RecordListBase.vue b/client/web/compose/src/components/PageBlocks/RecordListBase.vue index 9da128c93..20032c240 100644 --- a/client/web/compose/src/components/PageBlocks/RecordListBase.vue +++ b/client/web/compose/src/components/PageBlocks/RecordListBase.vue @@ -1040,8 +1040,8 @@ export default { beforeDestroy () { this.abortRequests() - this.setDefaultValues() this.destroyEvents() + this.setDefaultValues() }, created () { diff --git a/client/web/compose/src/views/Admin/Pages/Builder.vue b/client/web/compose/src/views/Admin/Pages/Builder.vue index b08bc4f2e..266975406 100644 --- a/client/web/compose/src/views/Admin/Pages/Builder.vue +++ b/client/web/compose/src/views/Admin/Pages/Builder.vue @@ -834,8 +834,11 @@ export default { } this.page = new compose.Page(page) - await this.fetchPageLayouts() - this.setLayout(layout.pageLayoutID) + + if (layout.pageLayoutID !== this.layout.pageLayoutID) { + await this.fetchPageLayouts() + this.setLayout(layout.pageLayoutID) + } }).finally(() => { this.processing = false }).catch(this.toastErrorHandler(this.$t('notification:page.page-layout.save.failed'))) @@ -973,6 +976,18 @@ export default { }, async setLayout (layoutID) { + const oldLayoutID = this.$route.query.layoutID + + // Cancelable redirect + if (layoutID && oldLayoutID !== layoutID) { + try { + await this.$router.replace({ ...this.$route, query: { ...this.$route.query, layoutID } }) + } catch { + this.$refs.layoutSelect.localValue = oldLayoutID + return + } + } + this.processingLayout = true layoutID = layoutID || this.$route.query.layoutID @@ -987,6 +1002,7 @@ export default { return this.$router.push(this.pageEditor) } + // If no previous layout was set and it exists, replace the URL with the proper layoutID if (this.$route.query.layoutID !== this.layout.pageLayoutID) { this.$router.replace({ ...this.$route, query: { ...this.$route.query, layoutID: this.layout.pageLayoutID } }) } diff --git a/lib/js/src/compose/types/page-block/base.ts b/lib/js/src/compose/types/page-block/base.ts index 0ac584f34..a2928a53b 100644 --- a/lib/js/src/compose/types/page-block/base.ts +++ b/lib/js/src/compose/types/page-block/base.ts @@ -105,8 +105,8 @@ export class PageBlock { this.meta.tempID = this.meta.tempID || generateUID() } - clone (): PageBlockInput { - return PageBlockMaker({ ...JSON.parse(JSON.stringify(this)), blockID: NoID, meta: { tempID: generateUID() } }) + clone (): this { + return new (this.constructor as new (i?: PageBlockInput) => this)({ ...JSON.parse(JSON.stringify(this)), blockID: NoID, meta: { tempID: '' } }) } }