Skip to content

Commit

Permalink
Fix availableBlocks override eachother
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Feb 27, 2024
1 parent df08d1a commit d36a511
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
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',
'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)
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 @@ -203,7 +203,7 @@ public function render(): View
$repeater->max($this->max);
}

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

Check warning on line 206 in src/Services/Forms/InlineRepeater.php

View check run for this annotation

Codecov / codecov/patch

src/Services/Forms/InlineRepeater.php#L206

Added line #L206 was not covered by tests
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,

Check failure on line 55 in src/View/Components/Fields/BlockEditor.php

View workflow job for this annotation

GitHub Actions / lint

Access to an undefined property A17\Twill\View\Components\Fields\BlockEditor::$renderForBlocks.
],
'availabilityId' => uniqid($this->name . '-')
])
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/View/Components/Fields/TwillFormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
public ?string $note = '',
public bool $inModal = false,
public bool $readOnly = false,
public bool $renderForBlocks = false,
bool $renderForBlocks = false,
public bool $renderForModal = false,
public bool $disabled = false,
public bool $required = false,
Expand All @@ -40,6 +40,7 @@ public function __construct(
$this->form_fields = $form['form_fields'] ?? [];
$this->formModuleName = $form['moduleName'] ?? null;
$this->routePrefix = $form['routePrefix'] ?? null;
$this->renderForBlocks = $renderForBlocks;

Check failure on line 43 in src/View/Components/Fields/TwillFormComponent.php

View workflow job for this annotation

GitHub Actions / lint

Access to an undefined property A17\Twill\View\Components\Fields\TwillFormComponent::$renderForBlocks.

$shared = ViewFacade::shared('TwillUntilConsumed', []);
foreach ($shared as $key => $value) {
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

0 comments on commit d36a511

Please sign in to comment.