Skip to content

Commit e238c4f

Browse files
13twelveifox
authored andcommitted
refactor inline repeater options to use traits
* `disableSortable()` -> `disableReorder` (existing trait) * `disableActions()` uses new trait
1 parent ee218af commit e238c4f

File tree

6 files changed

+37
-46
lines changed

6 files changed

+37
-46
lines changed

frontend/js/components/Repeater.vue

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
ref="blockList"
88
:block="block"
99
:index="index"
10-
:withHandle="allowSortable && draggable"
11-
:withActions="allowActions"
10+
:withHandle="reorder && draggable"
11+
:withActions="displayActions"
1212
:size="blockSize"
1313
:opened="opened"
1414
>
@@ -111,19 +111,19 @@
111111
type: Boolean,
112112
default: true
113113
},
114-
allowSortable: {
115-
type: Boolean,
116-
default: true
117-
},
118-
allowActions: {
114+
displayActions: {
119115
type: Boolean,
120116
default: true
121117
},
122118
max: {
123119
type: [Number, null],
124120
required: false,
125121
default: null
126-
}
122+
},
123+
reorder: {
124+
type: Boolean,
125+
default: true
126+
},
127127
},
128128
data: function () {
129129
return {

src/Services/Forms/Fields/Repeater.php

+2-16
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
use A17\Twill\Services\Forms\Fields\Traits\CanReorder;
66
use A17\Twill\Services\Forms\Fields\Traits\HasMax;
7+
use A17\Twill\Services\Forms\Fields\Traits\DisableActions;
78

89
class Repeater extends BaseFormField
910
{
1011
use HasMax;
1112
use CanReorder;
13+
use DisableActions;
1214

1315
protected ?string $type = null;
1416
protected bool $buttonAsLink = false;
1517
protected bool $allowCreate = true;
16-
protected bool $allowSortable = true;
17-
protected bool $allowActions = true;
1818
protected ?string $relation = null;
1919
protected ?array $browserModule = null;
2020

@@ -65,20 +65,6 @@ public function allowCreate(bool $allowCreate = true): static
6565
return $this;
6666
}
6767

68-
public function allowSortable(bool $allowSortable = true): static
69-
{
70-
$this->allowSortable = $allowSortable;
71-
72-
return $this;
73-
}
74-
75-
public function allowActions(bool $allowActions = true): static
76-
{
77-
$this->allowActions = $allowActions;
78-
79-
return $this;
80-
}
81-
8268
public function browserModule(?array $browserModule = null): static
8369
{
8470
$this->browserModule = $browserModule;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace A17\Twill\Services\Forms\Fields\Traits;
4+
5+
trait DisableActions
6+
{
7+
protected bool $actions = true;
8+
9+
/**
10+
* Adds a border around the options.
11+
*/
12+
public function disableActions(bool $actions = true): static
13+
{
14+
$this->displayActions = !$actions;
15+
16+
return $this;
17+
}
18+
}

src/Services/Forms/InlineRepeater.php

+7-18
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use A17\Twill\Services\Forms\Fields\Repeater;
1010
use A17\Twill\Services\Forms\Traits\HasSubFields;
1111
use A17\Twill\Services\Forms\Traits\RenderForBlocks;
12+
use A17\Twill\Services\Forms\Fields\Traits\CanReorder;
13+
use A17\Twill\Services\Forms\Fields\Traits\DisableActions;
1214
use Illuminate\Contracts\View\View;
1315
use Illuminate\Support\Collection;
1416
use Illuminate\Support\Str;
@@ -17,6 +19,8 @@ class InlineRepeater implements CanHaveSubfields, CanRenderForBlocks
1719
{
1820
use RenderForBlocks;
1921
use HasSubFields;
22+
use CanReorder;
23+
use DisableActions;
2024

2125
protected function __construct(
2226
private ?string $name = null,
@@ -25,15 +29,14 @@ protected function __construct(
2529
private ?Collection $fields = null,
2630
private ?string $label = null,
2731
private bool $allowCreate = true,
28-
private bool $allowSortable = true,
29-
private bool $allowActions = true,
3032
private ?string $relation = null,
3133
private ?bool $allowBrowse = false,
3234
private ?array $browser = null,
3335
private ?int $max = null,
3436
private ?string $titleField = null,
3537
private ?bool $hideTitlePrefix = false,
3638
private ?bool $buttonAsLink = false,
39+
private ?bool $displayActions = true,
3740
protected ?array $connectedTo = null,
3841
) {
3942
}
@@ -97,20 +100,6 @@ public function disableCreate(bool $disableCreate = true): static
97100
return $this;
98101
}
99102

100-
public function disableSortable(bool $disableSortable = true): static
101-
{
102-
$this->allowSortable = ! $disableSortable;
103-
104-
return $this;
105-
}
106-
107-
public function disableActions(bool $disableActions = true): static
108-
{
109-
$this->allowActions = ! $disableActions;
110-
111-
return $this;
112-
}
113-
114103
/**
115104
* The name of the module to use for selecting existing records. Not for json repeaters.
116105
*/
@@ -223,8 +212,8 @@ public function render(): View
223212
->name($this->name)
224213
->type($this->getRenderName())
225214
->allowCreate($this->allowCreate)
226-
->allowSortable($this->allowSortable)
227-
->allowActions($this->allowActions)
215+
->disableReorder(!$this->reorder)
216+
->disableActions(!$this->displayActions)
228217
->relation($this->relation ?? null)
229218
->browserModule($this->allowBrowse ? $this->browser : null);
230219

src/View/Components/Fields/Repeater.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ public function __construct(
1111
public string $type,
1212
public bool $buttonAsLink = false,
1313
public bool $reorder = true,
14+
public bool $displayActions = true,
1415
public ?int $max = null,
1516
public bool $allowCreate = true,
16-
public bool $allowSortable = true,
17-
public bool $allowActions = true,
1817
public ?string $relation = null,
1918
public ?array $browserModule = null,
2019
// Generic

views/partials/form/_repeater.blade.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
@if ($buttonAsLink) :button-as-link="true" @endif
88
@if ($relation) relation="{{$relation}}" @endif
99
:allow-create="{{$allowCreate ? 'true' : 'false'}}"
10-
:allow-sortable="{{$allowSortable ? 'true' : 'false'}}"
11-
:allow-actions="{{$allowActions ? 'true' : 'false' }}"
10+
:display-actions="{{$displayActions ? 'true' : 'false'}}"
1211
></a17-repeater>
1312

1413
@unless($renderForBlocks)

0 commit comments

Comments
 (0)