From 4f7e7de89928eef3c3c1d3953d1b9313b5c65392 Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Sat, 15 Feb 2025 02:24:57 +0000 Subject: [PATCH 1/4] Migrate some default attributes into the default checkbox attributes method from blade, to simplify adjustments going forward with published views --- .../components/table/td/bulk-actions.blade.php | 10 +++------- .../components/table/th/bulk-actions.blade.php | 4 ++-- src/Traits/Styling/HasBulkActionsStyling.php | 2 +- .../Styling/Helpers/BulkActionStylingHelpers.php | 15 +++++++++++++-- .../BulkActionsStylingConfigurationTest.php | 16 ++++++++++++++-- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/resources/views/components/table/td/bulk-actions.blade.php b/resources/views/components/table/td/bulk-actions.blade.php index 80cb3e5ff..f788a180c 100644 --- a/resources/views/components/table/td/bulk-actions.blade.php +++ b/resources/views/components/table/td/bulk-actions.blade.php @@ -12,16 +12,12 @@ 'inline-flex rounded-md shadow-sm' => $isTailwind, 'form-check' => $isBootstrap5, ])> - merge($bulkActionsTdCheckboxAttributes)->class([ - 'rounded border-gray-300 text-indigo-600 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($isTailwind) && ($bulkActionsTdCheckboxAttributes['default'] ?? true), + 'border-gray-300 text-indigo-600 focus:border-indigo-300 focus:ring-indigo-200 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600' => ($isTailwind) && (($bulkActionsTdCheckboxAttributes['default'] ?? true) || ($bulkActionsTdCheckboxAttributes['default-colors'] ?? true)), + 'rounded shadow-sm transition duration-150 ease-in-out focus:ring focus:ring-opacity-50' => ($isTailwind) && (($bulkActionsTdCheckboxAttributes['default'] ?? true) || ($bulkActionsTdCheckboxAttributes['default-styling'] ?? true)), 'form-check-input' => ($isBootstrap5) && ($bulkActionsTdCheckboxAttributes['default'] ?? true), ])->except(['default','default-styling','default-colors']) }} diff --git a/resources/views/components/table/th/bulk-actions.blade.php b/resources/views/components/table/th/bulk-actions.blade.php index 90f9ba442..3edc95020 100644 --- a/resources/views/components/table/th/bulk-actions.blade.php +++ b/resources/views/components/table/th/bulk-actions.blade.php @@ -1,11 +1,11 @@ -@aware(['isTailwind', 'isBootstrap']) +@aware(['tableName','isTailwind', 'isBootstrap']) @php $customAttributes = $this->hasBulkActionsThAttributes ? $this->getBulkActionsThAttributes : $this->getAllThAttributes($this->getBulkActionsColumn())['customAttributes']; $bulkActionsThCheckboxAttributes = $this->getBulkActionsThCheckboxAttributes(); @endphp @if ($this->bulkActionsAreEnabled() && $this->hasBulkActions()) - +
true]; - protected array $bulkActionsTdCheckboxAttributes = ['default' => true]; + protected array $bulkActionsTdCheckboxAttributes = ['default' => true, 'default-colors' => false, 'default-styling' => false]; protected array $bulkActionsButtonAttributes = ['default-colors' => true, 'default-styling' => true]; diff --git a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php index adc3cea89..5f326e410 100644 --- a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php +++ b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php @@ -85,13 +85,24 @@ public function getBulkActionsTdAttributes(): array } /** - * Used to get attributes for the Bulk Actions TD + * Used to get attributes for the Bulk Actions TD Checkbox * * @return array */ public function getBulkActionsTdCheckboxAttributes(): array { - return $this->getCustomAttributes('bulkActionsTdCheckboxAttributes'); + $array = array_merge( + [ + 'x-cloak', + 'x-show' => "!currentlyReorderingStatus", + 'x-model' => "selectedItems", + 'wire:loading.attr.delay' => "disabled", + 'type' => "checkbox", + ], + $this->getCustomAttributes('bulkActionsTdCheckboxAttributes') + ); + ksort($array); + return $array; } diff --git a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php index 019c13d22..d226c7e68 100644 --- a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -31,7 +31,6 @@ public static function providesBulkActionMethodsToTest(): array 'BulkActionsThAttributes', 'BulkActionsThCheckboxAttributes', 'BulkActionsTdAttributes', - 'BulkActionsTdCheckboxAttributes', 'BulkActionsRowButtonAttributes', ]; } @@ -121,11 +120,24 @@ public function test_bulk_actions_td_attributes_returns_default_true_if_not_set( public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if_not_set(): void { - $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsTdCheckboxAttributes()); + $data = [ + 'x-cloak', + 'x-show' => '!currentlyReorderingStatus', + 'x-model' => 'selectedItems', + 'wire:loading.attr.delay' => 'disabled', + 'type' => 'checkbox', + 'default' => true, + 'default-colors' => false, + 'default-styling' => false + ]; + ksort($data); + + $this->assertSame($data, $this->basicTable->getBulkActionsTdCheckboxAttributes()); } public function test_bulk_actions_th_attributes_returns_default_true_if_not_set(): void { + $this->assertSame(['default' => true, 'default-colors' => false, 'default-styling' => false], $this->basicTable->getBulkActionsThAttributes()); } From d669758d8249f537ba714202781a2337c69c97f3 Mon Sep 17 00:00:00 2001 From: lrljoe <104938042+lrljoe@users.noreply.github.com> Date: Sat, 15 Feb 2025 02:25:26 +0000 Subject: [PATCH 2/4] Fix styling --- .../Styling/Helpers/BulkActionStylingHelpers.php | 11 ++++++----- .../BulkActionsStylingConfigurationTest.php | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php index 5f326e410..aad42b286 100644 --- a/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php +++ b/src/Traits/Styling/Helpers/BulkActionStylingHelpers.php @@ -94,14 +94,15 @@ public function getBulkActionsTdCheckboxAttributes(): array $array = array_merge( [ 'x-cloak', - 'x-show' => "!currentlyReorderingStatus", - 'x-model' => "selectedItems", - 'wire:loading.attr.delay' => "disabled", - 'type' => "checkbox", - ], + 'x-show' => '!currentlyReorderingStatus', + 'x-model' => 'selectedItems', + 'wire:loading.attr.delay' => 'disabled', + 'type' => 'checkbox', + ], $this->getCustomAttributes('bulkActionsTdCheckboxAttributes') ); ksort($array); + return $array; } diff --git a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php index d226c7e68..f0d66fc60 100644 --- a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -126,9 +126,9 @@ public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if 'x-model' => 'selectedItems', 'wire:loading.attr.delay' => 'disabled', 'type' => 'checkbox', - 'default' => true, - 'default-colors' => false, - 'default-styling' => false + 'default' => true, + 'default-colors' => false, + 'default-styling' => false, ]; ksort($data); From 5f6554ead32458d02e49eda2a64f7b318f1040e1 Mon Sep 17 00:00:00 2001 From: LRLJoe Date: Sat, 15 Feb 2025 05:51:17 +0000 Subject: [PATCH 3/4] Restore test --- .../BulkActionsStylingConfigurationTest.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php index f0d66fc60..066b71150 100644 --- a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -31,6 +31,7 @@ public static function providesBulkActionMethodsToTest(): array 'BulkActionsThAttributes', 'BulkActionsThCheckboxAttributes', 'BulkActionsTdAttributes', + 'BulkActionsTdCheckboxAttributes', 'BulkActionsRowButtonAttributes', ]; } @@ -77,7 +78,7 @@ public function test_can_set_bulk_actions_attributes_via_provider(string $setMet 'default' => $default, 'default-colors' => $defaultColors, 'default-styling' => $defaultStyling, - ], $this->basicTable->{$getMethod}()); + ], collect($this->basicTable->{$getMethod}())->only(['class','default','default-colors','default-styling'])->toArray()); $this->basicTable->{$setMethod}([ 'default' => $default, @@ -91,7 +92,7 @@ public function test_can_set_bulk_actions_attributes_via_provider(string $setMet 'default' => $default, 'default-colors' => ! $defaultColors, 'default-styling' => $defaultStyling, - ], $this->basicTable->{$getMethod}()); + ], collect($this->basicTable->{$getMethod}())->only(['class','default','default-colors','default-styling'])->toArray()); } #[DataProvider('bulkActionAttributesProvider')] @@ -106,7 +107,7 @@ public function test_can_get_bulk_actions_attributes_bag_via_provider(string $se $this->basicTable->{$setMethod}($data); - $this->assertSame($data, $this->basicTable->{$getMethod}()); + $this->assertSame($data, collect($this->basicTable->{$getMethod}())->only(['class','default','default-colors','default-styling'])->toArray()); $attributeBag = new ComponentAttributeBag($data); @@ -131,8 +132,10 @@ public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if 'default-styling' => false, ]; ksort($data); - - $this->assertSame($data, $this->basicTable->getBulkActionsTdCheckboxAttributes()); + $returnedData = $this->basicTable->getBulkActionsTdCheckboxAttributes(); + ksort($returnedData); + + $this->assertSame($data, $returnedData); } public function test_bulk_actions_th_attributes_returns_default_true_if_not_set(): void From 7cf58a32b62703b2323e434e395922de67b1ca3a Mon Sep 17 00:00:00 2001 From: lrljoe <104938042+lrljoe@users.noreply.github.com> Date: Sat, 15 Feb 2025 05:51:49 +0000 Subject: [PATCH 4/4] Fix styling --- .../Configuration/BulkActionsStylingConfigurationTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php index 066b71150..3eb389975 100644 --- a/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php +++ b/tests/Unit/Traits/Configuration/BulkActionsStylingConfigurationTest.php @@ -78,7 +78,7 @@ public function test_can_set_bulk_actions_attributes_via_provider(string $setMet 'default' => $default, 'default-colors' => $defaultColors, 'default-styling' => $defaultStyling, - ], collect($this->basicTable->{$getMethod}())->only(['class','default','default-colors','default-styling'])->toArray()); + ], collect($this->basicTable->{$getMethod}())->only(['class', 'default', 'default-colors', 'default-styling'])->toArray()); $this->basicTable->{$setMethod}([ 'default' => $default, @@ -92,7 +92,7 @@ public function test_can_set_bulk_actions_attributes_via_provider(string $setMet 'default' => $default, 'default-colors' => ! $defaultColors, 'default-styling' => $defaultStyling, - ], collect($this->basicTable->{$getMethod}())->only(['class','default','default-colors','default-styling'])->toArray()); + ], collect($this->basicTable->{$getMethod}())->only(['class', 'default', 'default-colors', 'default-styling'])->toArray()); } #[DataProvider('bulkActionAttributesProvider')] @@ -107,7 +107,7 @@ public function test_can_get_bulk_actions_attributes_bag_via_provider(string $se $this->basicTable->{$setMethod}($data); - $this->assertSame($data, collect($this->basicTable->{$getMethod}())->only(['class','default','default-colors','default-styling'])->toArray()); + $this->assertSame($data, collect($this->basicTable->{$getMethod}())->only(['class', 'default', 'default-colors', 'default-styling'])->toArray()); $attributeBag = new ComponentAttributeBag($data); @@ -134,7 +134,7 @@ public function test_bulk_actions_td_checkbox_attributes_returns_default_true_if ksort($data); $returnedData = $this->basicTable->getBulkActionsTdCheckboxAttributes(); ksort($returnedData); - + $this->assertSame($data, $returnedData); }