Skip to content

Commit bd8c37e

Browse files
committed
refactor: remove setWidth method and replace with AlpineJS event dispatch for width updates
Streamline the width update mechanism by delegating functionality to AlpineJS, removing redundant livewire logic and tests.
1 parent 025c3ec commit bd8c37e

File tree

3 files changed

+3
-16
lines changed

3 files changed

+3
-16
lines changed

resources/views/livewire/manage-custom-field-width.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div
22
x-data="{
3-
fieldId: @entangle('fieldId'),
4-
selectedWidth: @entangle('selectedWidth'),
3+
fieldId: @js($fieldId),
4+
selectedWidth: $wire.entangle('selectedWidth'),
55
widths: @js($widthOptions),
66
isSelected(width) {
77
return width <= this.selectedWidth;
@@ -13,7 +13,7 @@ class="relative"
1313
<div class="absolute w-20 flex opacity-70" style="z-index: 1">
1414
<template x-for="(width, index) in widths" :key="index">
1515
<div
16-
wire:click="$parent.setWidth(fieldId, width)"
16+
x-on:click="$dispatch('field-width-updated', { fieldId: fieldId, width: Number(width) })"
1717
class="h-6 flex-1 cursor-pointer bg-gray-200 hover:bg-gray-300 dark:bg-gray-700 dark:hover:bg-gray-600 transition-colors"
1818
:class="{
1919
'rounded-s-md': index === 0,

src/Livewire/ManageCustomField.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ public function deleteAction(): Action
9898
});
9999
}
100100

101-
public function setWidth(int|string $fieldId, int $width): void
102-
{
103-
$this->dispatch('field-width-updated', $fieldId, $width);
104-
}
105-
106101
public function render(): View
107102
{
108103
return view('custom-fields::livewire.manage-custom-field');

tests/Feature/Admin/Pages/CustomFieldsFieldManagementTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,6 @@
281281
'field' => $systemField,
282282
])->assertActionHidden('delete');
283283
});
284-
285-
it('dispatches width update event', function (): void {
286-
// Act & Assert
287-
livewire(ManageCustomField::class, [
288-
'field' => $this->field,
289-
])->call('setWidth', $this->field->getKey(), 75)
290-
->assertDispatched('field-width-updated', $this->field->getKey(), 75);
291-
});
292284
});
293285

294286
describe('Enhanced field management with datasets', function (): void {

0 commit comments

Comments
 (0)