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

Fix availableBlocks override eachother #2503

Open
wants to merge 4 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions frontend/js/components/blocks/Blocks.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<a17-blocks-list :editor-name="editorName" v-slot="{ savedBlocks, availableBlocks, moveBlock, moveBlockToEditor, cloneBlock }">
<a17-blocks-list :editor-name="editorName" :availability-id="availabilityId" v-slot="{ savedBlocks, availableBlocks, moveBlock, moveBlockToEditor, cloneBlock }">
<div class="blocks">
<draggable class="blocks__container"
:value="savedBlocks"
Expand Down Expand Up @@ -163,6 +163,9 @@
editorName: {
type: String,
required: true
},
availabilityId: {
type: String,
}
},
data () {
Expand All @@ -179,9 +182,8 @@
}),
...mapGetters([
'blocks',
'fieldsByBlockId',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not used in the component

'availableBlocks'
])
]),
},
methods: {
setOpened: function () {
Expand Down Expand Up @@ -265,7 +267,7 @@
}
},
checkIfBlockTypeIsAvailable (editorName, type) {
const availableBlocks = JSON.parse(JSON.stringify(this.availableBlocks(editorName)))
const availableBlocks = this.availableBlocks(editorName)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to deepclone this in this function, it's only being searched

const blockTypes = availableBlocks.map(block => block.component)

return blockTypes.indexOf(type) !== -1
Expand Down
7 changes: 4 additions & 3 deletions frontend/js/components/blocks/BlocksList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ export default {
editorName: {
type: String,
required: true
},
availabilityId: {
type: String,
}
},
computed: {
availableBlocks () {
const splitted = this.editorName.split('|')
const editorName = splitted[splitted.length - 1]
return this.getAvailableBlocks(editorName)
return this.getAvailableBlocks(this.availabilityId ? this.availabilityId : this.editorName.split('|').pop())
},
savedBlocks () {
return this.blocks(this.editorName)
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Forms/InlineRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public function render(): View
$repeater->buttonAsLink($this->buttonAsLink);
}

$repeater->renderForBlocks = $this->renderForBlocks ?? false;
$repeater->renderForBlocks($this->renderForBlocks ?? false);
return $repeater->render();
}

Expand Down
1 change: 1 addition & 0 deletions src/View/Components/Fields/BlockEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function render(): View
'value' => $this->name,
'nested' => $this->renderForBlocks,
],
'availabilityId' => uniqid($this->name . '-')
])
);
}
Expand Down
6 changes: 4 additions & 2 deletions views/partials/form/_block_editor.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
@endunless

<a17-blocks title="{{ $label }}"
availability-id="{{ $availabilityId }}"
@if ($renderForBlocks) :editor-name="nestedEditorName('{{ $name }}')" @else editor-name="{{ $name }}" @endif
trigger="{{ $trigger }}" :is-settings="{{ (bool) $isSettings ? 'true' : 'false' }}">

trigger="{{ $trigger }}" :is-settings="{{ $isSettings ? 'true' : 'false' }}">
</a17-blocks>

@push('vuexStore')
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $name }}'] =
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $availabilityId }}'] =
{!! json_encode(array_values($allowedBlocks)) !!}
window['{{ config('twill.js_namespace') }}'].STORE.form.editorNames.push({!! json_encode($editorName) !!})
@endpush
Expand Down