From a03025fb5ff805e828a02d5c2a149514ee717320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C5=BEe=20Fortun?= Date: Wed, 29 Mar 2023 19:28:45 +0200 Subject: [PATCH] Update multi page layout interaction with tabs block --- .../Admin/Page/Builder/Selector.vue | 1 + .../PageBlocks/ChartConfigurator.vue | 2 +- .../PageBlocks/RecordListConfigurator.vue | 4 +- .../src/components/PageBlocks/TabsBase.vue | 6 +- .../PageBlocks/TabsConfigurator.vue | 12 +- .../src/components/PageBlocks/base.vue | 5 + .../src/components/Public/Page/Grid.vue | 7 +- client/web/compose/src/store/page-layout.js | 11 +- .../compose/src/views/Admin/Pages/Builder.vue | 179 +++++++++++------- .../compose/src/views/Admin/Pages/Edit.vue | 20 +- .../compose/src/views/Admin/Pages/List.vue | 2 +- lib/js/src/compose/types/page-layout.ts | 2 +- .../corteza-webapp-compose/notification.yaml | 7 + 13 files changed, 155 insertions(+), 103 deletions(-) diff --git a/client/web/compose/src/components/Admin/Page/Builder/Selector.vue b/client/web/compose/src/components/Admin/Page/Builder/Selector.vue index 04b487d08..c4cb11cd6 100644 --- a/client/web/compose/src/components/Admin/Page/Builder/Selector.vue +++ b/client/web/compose/src/components/Admin/Page/Builder/Selector.vue @@ -46,6 +46,7 @@ kind === 'RecordList' && blockID !== NoID && options.moduleID === this.selectedChartModuleID) + return this.blocks.filter(({ blockID, kind, options = {} }) => kind === 'RecordList' && blockID !== NoID && options.moduleID === this.selectedChartModuleID) }, }, diff --git a/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue b/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue index 93fa465bf..dff83afe0 100644 --- a/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/RecordListConfigurator.vue @@ -836,8 +836,8 @@ export default { disableInlineEditor () { const thisModuleID = this.options.moduleID - // Finds another inline editor block with the same recordListModulea as this one - const otherInlineWithSameModule = !!this.page.blocks.find(({ kind, options }, index) => { + // Finds another inline editor block with the same recordListModule as this one + const otherInlineWithSameModule = this.blocks.some(({ kind, options }, index) => { if (this.blockIndex !== index) { return kind === 'RecordList' && options.editable && options.moduleID === thisModuleID } diff --git a/client/web/compose/src/components/PageBlocks/TabsBase.vue b/client/web/compose/src/components/PageBlocks/TabsBase.vue index 31868fd83..258980dc5 100644 --- a/client/web/compose/src/components/PageBlocks/TabsBase.vue +++ b/client/web/compose/src/components/PageBlocks/TabsBase.vue @@ -82,16 +82,16 @@ export default { computed: { tabbedBlocks () { return this.block.options.tabs.map(({ blockID, title }) => { - let block = this.page.blocks.find(b => fetchID(b) === blockID) - block = block ? compose.PageBlockMaker(block) : undefined + let block = this.blocks.find(b => fetchID(b) === blockID) // Blocks should display as Plain, to avoid card shadow/border if (block) { block.style.wrap.kind = 'Plain' + block = compose.PageBlockMaker(block) } return { - block: block ? compose.PageBlockMaker(block) : undefined, + block, title, } }) diff --git a/client/web/compose/src/components/PageBlocks/TabsConfigurator.vue b/client/web/compose/src/components/PageBlocks/TabsConfigurator.vue index 450ca4a95..a48e9d734 100644 --- a/client/web/compose/src/components/PageBlocks/TabsConfigurator.vue +++ b/client/web/compose/src/components/PageBlocks/TabsConfigurator.vue @@ -168,8 +168,7 @@ id="popover-edit" size="sm" variant="light" - :title="blockEditDisabled ? $t('tabs.tooltip.editDisabled') : $t('tabs.tooltip.edit')" - :disabled="blockEditDisabled" + :title="$t('tabs.tooltip.edit')" class="d-flex align-items-center justify-content-center" style="width: 40px;" @click="editBlock(tab.blockID)" @@ -300,11 +299,10 @@ export default { computed: { blockOptions () { - return this.page.blocks.filter(b => b.kind !== 'Tabs').map(b => ({ ...b, value: fetchID(b) })) - }, - - blockEditDisabled () { - return this.page.blocks.find(b => fetchID(b) === fetchID(this.block)) === undefined + return [ + ...this.page.blocks.filter(({ blockID, kind }) => kind !== 'Tabs' && !this.blocks.some(b => b.blockID === blockID)), + ...this.blocks.filter(b => b.kind !== 'Tabs'), + ].map(b => ({ ...b, value: fetchID(b) })) }, }, diff --git a/client/web/compose/src/components/PageBlocks/base.vue b/client/web/compose/src/components/PageBlocks/base.vue index 8a79106a4..660bac89f 100644 --- a/client/web/compose/src/components/PageBlocks/base.vue +++ b/client/web/compose/src/components/PageBlocks/base.vue @@ -33,6 +33,11 @@ export default { required: true, }, + blocks: { + type: Array, + default: () => [], + }, + block: { type: compose.PageBlock, required: true, diff --git a/client/web/compose/src/components/Public/Page/Grid.vue b/client/web/compose/src/components/Public/Page/Grid.vue index 47ec864ff..2f2e97df1 100644 --- a/client/web/compose/src/components/Public/Page/Grid.vue +++ b/client/web/compose/src/components/Public/Page/Grid.vue @@ -9,7 +9,12 @@ slot-scope="{ boundingRect, block, index }" > diff --git a/client/web/compose/src/store/page-layout.js b/client/web/compose/src/store/page-layout.js index e007882d9..f796dc1b5 100644 --- a/client/web/compose/src/store/page-layout.js +++ b/client/web/compose/src/store/page-layout.js @@ -67,17 +67,16 @@ export default function (ComposeAPI) { }) }, - async findByID ({ commit, getters }, { namespaceID, pageLayoutID, force = false } = {}) { + async findByID ({ commit, getters }, { namespaceID, pageID, pageLayoutID, force = false } = {}) { if (!force) { const oldItem = getters.getByID(pageLayoutID) - if (oldItem) { - return new Promise((resolve) => resolve(oldItem)) - } + return new Promise((resolve) => resolve(oldItem)) } commit(types.pending) - return ComposeAPI.pageLayoutRead({ namespaceID, pageLayoutID }).then(pl => { + return ComposeAPI.pageLayoutRead({ namespaceID, pageID, pageLayoutID }).then(pl => { const pageLayout = new compose.PageLayout(pl) + commit(types.updateSet, [pageLayout]) return pageLayout }).finally(() => { @@ -122,7 +121,7 @@ export default function (ComposeAPI) { }) }, - async delete ({ commit, dispatch }, item) { + async delete ({ commit }, item) { commit(types.pending) return ComposeAPI.pageLayoutDelete(item).then(() => { commit(types.removeFromSet, [item]) diff --git a/client/web/compose/src/views/Admin/Pages/Builder.vue b/client/web/compose/src/views/Admin/Pages/Builder.vue index 17b44882f..43c01057a 100644 --- a/client/web/compose/src/views/Admin/Pages/Builder.vue +++ b/client/web/compose/src/views/Admin/Pages/Builder.vue @@ -136,10 +136,11 @@ ...$props }" :page="page" - :module="module" - :record="record" + :blocks="usedBlocks" :block-index="index" :block="block" + :module="module" + :record="record" :bounding-rect="boundingRect" editable class="p-2" @@ -183,6 +184,7 @@ :namespace="namespace" :module="module" :page="page" + :blocks="usedBlocks" :block.sync="editor.block" :record="record" /> @@ -202,10 +204,12 @@ :namespace="namespace" :module="module" :page="page" + :blocks="usedBlocks" :block.sync="editor.block" :block-index="editor.index" :record="record" /> +