Skip to content

Commit ed2ffdb

Browse files
committed
Fixes for Sorting Pill Labels
1 parent 834f7ff commit ed2ffdb

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/Views/Traits/Columns/IsSortable.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,20 @@ public function hasCustomSortingPillDirections(): bool
8989
return $this->sortingPillDirectionAsc !== null && $this->sortingPillDirectionDesc !== null;
9090
}
9191

92-
public function getCustomSortingPillDirections(string $direction): string
92+
public function getCustomSortingPillDirections(string $direction, ?string $defaultLabelAsc = 'A-Z', ?string $defaultLabelDesc = 'Z-A'): string
9393
{
9494
if ($direction === 'asc') {
95-
return $this->sortingPillDirectionAsc;
95+
return $this->sortingPillDirectionAsc ?? $defaultLabelAsc;
9696
}
9797

9898
if ($direction === 'desc') {
99-
return $this->sortingPillDirectionDesc;
99+
return $this->sortingPillDirectionDesc ?? $defaultLabelDesc;
100100
}
101101

102102
return __('livewire-tables::not_applicable');
103103
}
104104

105-
public function getCustomSortingPillDirectionsLabel(string $direction, string $defaultLabelAsc, string $defaultLabelDesc): string
105+
public function getCustomSortingPillDirectionsLabel(string $direction, ?string $defaultLabelAsc = 'A-Z', ?string $defaultLabelDesc = 'Z-A'): string
106106
{
107107
if ($direction === 'asc') {
108108
return $this->sortingPillDirectionAsc ?? $defaultLabelAsc;
@@ -118,13 +118,13 @@ public function getCustomSortingPillDirectionsLabel(string $direction, string $d
118118
public function getSortingPillDirection(DataTableComponent $component, string $direction): string
119119
{
120120
if ($this->hasCustomSortingPillDirections()) {
121-
return $this->getCustomSortingPillDirections($direction);
121+
return $this->getCustomSortingPillDirections($direction, $component->getDefaultSortingLabelAsc(), $component->getDefaultSortingLabelDesc());
122122
}
123123

124124
return $direction === 'asc' ? $component->getDefaultSortingLabelAsc() : $component->getDefaultSortingLabelDesc();
125125
}
126126

127-
public function getSortingPillDirectionLabel(string $direction, string $defaultLabelAsc, string $defaultLabelDesc): string
127+
public function getSortingPillDirectionLabel(string $direction, ?string $defaultLabelAsc = 'A-Z', ?string $defaultLabelDesc = 'Z-A'): string
128128
{
129129
if ($this->hasCustomSortingPillDirections()) {
130130
return $this->getCustomSortingPillDirectionsLabel($direction, $defaultLabelAsc, $defaultLabelDesc);

tests/Views/Traits/Helpers/ColumnHelpersTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function test_can_get_standard_sorting_pill_directions(): void
114114

115115
$this->assertFalse($column->hasCustomSortingPillDirections());
116116

117-
$this->assertSame(__('livewire-tables::not_applicable'), $column->getCustomSortingPillDirections('asc'));
118-
$this->assertSame(__('livewire-tables::not_applicable'), $column->getCustomSortingPillDirections('desc'));
117+
$this->assertSame($this->basicTable->getDefaultSortingLabelAsc(), $column->getCustomSortingPillDirections('asc'));
118+
$this->assertSame($this->basicTable->getDefaultSortingLabelDesc(), $column->getCustomSortingPillDirections('desc'));
119119
}
120120

121121
public function test_can_set_custom_sorting_pill_directions(): void

0 commit comments

Comments
 (0)