Skip to content

Commit 56ae025

Browse files
committed
fix: show all fields when sections disabled regardless of section
1 parent 297c174 commit 56ae025

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

src/Livewire/ManageFieldsWithoutSections.php

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,66 @@
1212
use Filament\Support\Enums\Size;
1313
use Filament\Support\Enums\Width;
1414
use Illuminate\Contracts\View\View;
15+
use Illuminate\Database\Eloquent\Collection;
16+
use Livewire\Attributes\Computed;
17+
use Livewire\Attributes\On;
1518
use Livewire\Component;
1619
use Relaticle\CustomFields\CustomFields;
1720
use Relaticle\CustomFields\Filament\Management\Schemas\FieldForm;
1821
use Relaticle\CustomFields\Livewire\Concerns\CreatesCustomFields;
19-
use Relaticle\CustomFields\Livewire\Concerns\ManagesFields;
2022
use Relaticle\CustomFields\Models\CustomFieldSection;
2123

2224
/**
2325
* Livewire component for managing custom fields when sections are disabled.
26+
*
27+
* Shows ALL fields for the entity type regardless of which section they belong to.
28+
* New fields are created in the default section.
2429
*/
2530
final class ManageFieldsWithoutSections extends Component implements HasActions, HasForms
2631
{
2732
use CreatesCustomFields;
2833
use InteractsWithActions;
2934
use InteractsWithForms;
30-
use ManagesFields;
3135

3236
public string $entityType;
3337

38+
/** The default section used for creating new fields */
3439
public CustomFieldSection $section;
3540

41+
/**
42+
* Get ALL fields for the entity type, regardless of section.
43+
*/
44+
#[Computed]
45+
public function fields(): Collection
46+
{
47+
return CustomFields::newCustomFieldModel()
48+
->newQuery()
49+
->withDeactivated()
50+
->where('entity_type', $this->entityType)
51+
->orderBy('sort_order')
52+
->get();
53+
}
54+
55+
#[On('field-width-updated')]
56+
public function fieldWidthUpdated(int|string $fieldId, int $width): void
57+
{
58+
$model = CustomFields::newCustomFieldModel();
59+
$model->where($model->getKeyName(), $fieldId)->update(['width' => $width]);
60+
unset($this->fields);
61+
}
62+
63+
#[On('field-deleted')]
64+
public function fieldDeleted(): void
65+
{
66+
unset($this->fields);
67+
}
68+
69+
#[On('fields-reordered')]
70+
public function fieldsReordered(): void
71+
{
72+
unset($this->fields);
73+
}
74+
3675
public function updateFieldsOrder(array $fields): void
3776
{
3877
$model = CustomFields::newCustomFieldModel();

0 commit comments

Comments
 (0)