Skip to content

Commit

Permalink
Adjust referenced block indication implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fajfa committed Nov 1, 2023
1 parent b0b63b5 commit 1a1ede0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
46 changes: 30 additions & 16 deletions client/web/compose/src/views/Admin/Pages/Builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@
</b-modal>

<b-modal
:title="$t('block.general.title')"
:ok-title="$t('build.addBlock')"
ok-variant="primary"
cancel-variant="link"
Expand All @@ -194,6 +193,20 @@
@ok="updateBlocks()"
@hide="editor = undefined"
>
<template #modal-title>
<div class="d-flex gap-1 align-items-center">
<h5 class="mb-0">
{{ $t('block.general.title') }}
</h5>
<font-awesome-icon
v-if="isEditorBlockReferenced"
v-b-tooltip.hover.right="{ title: $t('referencedBlock') }"
:icon="['fas', 'exclamation-circle']"
class="text-warning"
/>
</div>
</template>

<configurator
v-if="showCreator"
:namespace="namespace"
Expand All @@ -210,6 +223,7 @@
:visible="showEditor"
body-class="p-0 border-top-0"
footer-class="d-flex justify-content-between"
header-class="p-3 pb-0 border-bottom-0"
@hide="editor = undefined"
>
<template #modal-title>
Expand All @@ -219,7 +233,7 @@
</h5>
<font-awesome-icon
v-if="isEditorBlockReferenced"
v-b-popover.hover.right="{ content: 'This block is used in other layouts' }"
v-b-tooltip.hover.right="{ title: $t('referencedBlock') }"
:icon="['fas', 'exclamation-circle']"
class="text-warning"
/>
Expand Down Expand Up @@ -490,25 +504,25 @@ export default {
]
},
otherLayoutBlocks () {
let set
if (!set) {
set = new Set()
}
// Set of blockIDs used on other layouts
otherLayoutBlockIDs () {
const set = new Set()
return set
return this.layouts.reduce((acc, { blocks, pageLayoutID }) => {
if (pageLayoutID === this.layout.pageLayoutID) return acc
blocks.forEach(({ blockID }) => acc.add(blockID))
return acc
}, set)
},
// Is block open in editor referenced on other layouts
isEditorBlockReferenced () {
if (!this.editor || this.editor.block.blockID === NoID) return
const { block } = this.editor || {}
if (!block || block.blockID === NoID) return
// All blockIDs in other layouts except this one
const otherLayoutBlockIDs = this.layouts.reduce((acc, { blocks, pageLayoutID }) => {
if (pageLayoutID === this.layout.pageLayoutID) return acc
blocks.forEach(({ blockID }) => acc.add(blockID))
return acc
}, this.otherLayoutBlocks)
return otherLayoutBlockIDs.has(this.editor.block.blockID)
return this.otherLayoutBlockIDs.has(this.editor.block.blockID)
},
},
Expand Down
1 change: 0 additions & 1 deletion locale/en/corteza-webapp-compose/block.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ file:
preview:
label: File block
general:
changeBlock: Change existing block
descriptionLabel: Description
descriptionPlaceholder: Block description
headerStyle: Block header style (color)
Expand Down
2 changes: 1 addition & 1 deletion locale/en/corteza-webapp-compose/page.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ page-layout:

block:
general:
changeBlock: Change existing block
label:
cancel: Cancel
noHandle: No handle
Expand All @@ -70,6 +69,7 @@ block:
title: Add new block
invalid-handle-characters: Should be at least 2 characters long. Can contain only letters, numbers, dashes, underscores and dots. Must end with letter or number
changeBlock: Change existing block
referencedBlock: This block is used in other layouts
copyOf: "Copy of {{title}}"
build:
addBlock: Add block
Expand Down

0 comments on commit 1a1ede0

Please sign in to comment.