Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add improvement to tabbed page block configuration #1416

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion client/web/compose/src/components/PageBlocks/TabsBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<wrap
v-bind="$props"
:scrollable-body="false"
card-class="tabs-base-block-container"
v-on="$listeners"
>
<div
Expand Down Expand Up @@ -35,13 +36,50 @@
<b-tab
v-for="(tab, index) in tabbedBlocks"
:key="`${getTabTitle(tab, index)}-${index}`"
:title="getTabTitle(tab, index)"
class="h-100"
:title-item-class="getTitleItemClass(index)"
:title-link-class="getTitleItemClass(index)"
no-body
:lazy="isTabLazy(tab)"
>
<template #title>
<span>
{{ getTabTitle(tab, index) }}
</span>

<div
v-if="editable"
class="d-inline ml-3"
>
<div
v-if="unsavedBlocks.has(tab.block.blockID !== '0' ? tab.block.blockID : tab.block.meta.tempID)"
:title="$t('tabs.unsavedChanges')"
class="btn border-0"
>
<font-awesome-icon
:icon="['fas', 'exclamation-triangle']"
class="text-warning"
/>
</div>

<b-button
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use input confirm like toolbox does

size="sm"
variant="outline-light"
class="text-primary border-0 edit-block-btn"
@click="editTabbedBlock(tab)"
>
<font-awesome-icon
:icon="['far', 'edit']"
/>
</b-button>

<c-input-confirm
class="ml-1"
@confirmed="deleteTab(index)"
/>
</div>
</template>

<page-block-tab
v-if="tab.block"
v-bind="{ ...$attrs, ...$props, page, block: tab.block, blockIndex: index }"
Expand Down Expand Up @@ -78,6 +116,7 @@ export default {
components: {
PageBlockTab: () => import('corteza-webapp-compose/src/components/PageBlocks'),
},

extends: base,

computed: {
Expand Down Expand Up @@ -129,6 +168,17 @@ export default {
},

methods: {
editTabbedBlock (tab) {
const blockIndex = this.blocks.findIndex(block => fetchID(block) === tab.block.blockID)
if (blockIndex > -1) {
this.$emit('edit-block', blockIndex)
}
},

deleteTab (tabIndex) {
this.$emit('delete-tab', { tabIndex, blockIndex: this.blockIndex })
},

getTitleItemClass (index) {
const { justify, alignment } = this.block.options.style
return `order-${index} text-truncate text-${alignment} ${justify !== 'none' ? 'flex-fill' : ''}`
Expand All @@ -146,3 +196,11 @@ export default {
},
}
</script>

<style lang="scss">
.tabs-base-block-container .nav-pills {
.active .edit-block-btn {
color: $white !important;
}
}
</style>
5 changes: 5 additions & 0 deletions client/web/compose/src/components/PageBlocks/base.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export default {
required: false,
default: false,
},

unsavedBlocks: {
type: Set,
default: () => new Set(),
},
},

data () {
Expand Down
37 changes: 15 additions & 22 deletions client/web/compose/src/views/Admin/Pages/Builder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@
:module="module"
:record="record"
:resizing="resizing"
:unsaved-blocks="unsavedBlocks"
editable
class="p-2"
@edit-block="editBlock"
@delete-tab="deleteTab"
/>
</div>
</template>
Expand Down Expand Up @@ -613,6 +616,17 @@ export default {
if (this.editor) this.editor = undefined
},

deleteTab ({ blockIndex, tabIndex }) {
const { blockID } = this.blocks[blockIndex] || {}

if (!blockID) return

this.unsavedBlocks.add(blockID)
this.blocks[blockIndex].options.tabs.splice(tabIndex, 1)

this.showUntabbedHiddenBlocks()
},

// Changes meta.hidden property to false, for all blocks that are hidden but not in a tab
showUntabbedHiddenBlocks () {
const tabbedBlocks = new Set()
Expand Down Expand Up @@ -678,35 +692,14 @@ export default {

tabbedBlock.meta.hidden = true
})
this.showUnusedHiddenBlocks()
this.showUntabbedHiddenBlocks()
}

if (this.editor.block.kind === block.kind) {
this.editor = undefined
}
},

showUnusedHiddenBlocks () {
const allTabBlocks = this.blocks.filter(({ kind }) => kind === 'Tabs')

this.blocks.forEach(block => {
if (!block.meta.hidden) return

const hiddenBlockID = fetchID(block)

// Go through all hidden blocks to see if they are tabbed anywhere
const tabbed = allTabBlocks.some(({ options }) => {
const { tabs = [] } = options
return tabs.some(({ blockID }) => blockID === hiddenBlockID)
})

if (!tabbed) {
this.calculateNewBlockPosition(block)
block.meta.hidden = false
}
})
},

cloneBlock (index) {
this.appendBlock(this.blocks[index].clone(), this.$t('notification:page.cloneSuccess'))
},
Expand Down
1 change: 1 addition & 0 deletions locale/en/corteza-webapp-compose/block.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ tabs:
displayTitle: Display Options
preview: Live example
newBlockModal: Add new block
unsavedChanges: Unsaved Changes
placeholder:
block: Select a block to tab
style:
Expand Down