Skip to content

Commit 552623d

Browse files
committed
Merge branch 'staging'
2 parents e1d4b8d + ed0d97e commit 552623d

File tree

4 files changed

+46
-21
lines changed

4 files changed

+46
-21
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.2.0] - 2025-06-20
8+
9+
_Stable release based on [1.2.0-rc.1]._
10+
11+
## [1.2.0-rc.1] - 2025-06-20
12+
713
## [1.1.2] - 2025-06-11
814

915
### Fixed
@@ -357,6 +363,8 @@ _Stable release based on [0.1.0-rc.1]._
357363

358364
- New changelog file.
359365

366+
[1.2.0]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.1.2...v1.2.0
367+
[1.2.0-rc.1]: https://github.com/internetguru/laravel-model-browser/releases/tag/v1.1.2
360368
[1.1.2]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.1.1...v1.1.2
361369
[1.1.1]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.1.0...v1.1.1
362370
[1.1.0]: https://https://github.com/internetguru/laravel-model-browser/compare/v1.0.3...v1.1.0

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.2
1+
1.2.0

resources/views/livewire/table.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ class="table-wrapper"
2626
>
2727

2828
<div class="d-flex justify-content-end alig-items-center gap-3 m-3">
29-
<x-model-browser::filter :$filter :$viewAttributes />
29+
@if (!empty ($this->filterAttributes))
30+
<x-model-browser::filter :$filter :$viewAttributes />
31+
@endif
3032
<div class="mt-3">
3133
<x-model-browser::fullscreen-button />
3234
</div>

src/Components/BaseModelBrowser.php

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class BaseModelBrowser extends Component
2121

2222
public const PER_PAGE_MIN = 3;
2323
public const PER_PAGE_MAX = 150;
24-
public const PER_PAGE_DEFAULT = 50;
24+
public const PER_PAGE_DEFAULT = 20;
2525

2626
#[Locked]
2727
public string $model;
@@ -177,33 +177,37 @@ protected function getData(bool $paginate = true, bool $highlightMatches = true,
177177
}
178178
}
179179

180-
if ($applyFormats) {
180+
$applyFormatsOnAll = ! empty($this->filterAttributes) || $this->enableSort;
181+
182+
if ($applyFormats && $applyFormatsOnAll) {
181183
$data = $this->format($data);
182184
}
183185

184-
if ($this->filter) {
186+
if (! empty($this->filterAttributes) && $this->filter) {
185187
$data = $this->applyFilter($data);
186188
}
187189

188-
// Multi-column sort
189-
$sort = $this->sort;
190-
foreach ($this->defaultSort as $attribute => $direction) {
191-
if (! isset($sort[$attribute])) {
192-
$sort[$attribute] = $direction;
190+
if ($this->enableSort) {
191+
// Multi-column sort
192+
$sort = $this->sort;
193+
foreach ($this->defaultSort as $attribute => $direction) {
194+
if (! isset($sort[$attribute])) {
195+
$sort[$attribute] = $direction;
196+
}
193197
}
194-
}
195-
if (! empty($sort)) {
196-
$sortByArg = [];
197-
foreach ($sort as $attribute => $direction) {
198-
if (is_callable($this->sortComparators[$attribute][$direction] ?? null)) {
199-
$sortByArg[] = Closure::fromCallable($this->sortComparators[$attribute][$direction]);
200-
} else {
201-
$sortByArg[] = fn ($a, $b) => $direction === 'desc'
202-
? str($this->itemValueStripped($b, $attribute))->ascii() <=> str($this->itemValueStripped($a, $attribute))->ascii()
203-
: str($this->itemValueStripped($a, $attribute))->ascii() <=> str($this->itemValueStripped($b, $attribute))->ascii();
198+
if (! empty($sort)) {
199+
$sortByArg = [];
200+
foreach ($sort as $attribute => $direction) {
201+
if (is_callable($this->sortComparators[$attribute][$direction] ?? null)) {
202+
$sortByArg[] = Closure::fromCallable($this->sortComparators[$attribute][$direction]);
203+
} else {
204+
$sortByArg[] = fn ($a, $b) => $direction === 'desc'
205+
? str($this->itemValueStripped($b, $attribute))->ascii() <=> str($this->itemValueStripped($a, $attribute))->ascii()
206+
: str($this->itemValueStripped($a, $attribute))->ascii() <=> str($this->itemValueStripped($b, $attribute))->ascii();
207+
}
204208
}
209+
$data = $data->sortBy($sortByArg);
205210
}
206-
$data = $data->sortBy($sortByArg);
207211
}
208212

209213
// Paginate manually if required
@@ -222,6 +226,17 @@ protected function getData(bool $paginate = true, bool $highlightMatches = true,
222226
}
223227
}
224228

229+
if ($applyFormats && ! $applyFormatsOnAll) {
230+
// Apply formats only to the current page if not applied on all
231+
if ($paginate) {
232+
$data->setCollection(
233+
$this->format($data->getCollection())
234+
);
235+
} else {
236+
$data = $this->format($data);
237+
}
238+
}
239+
225240
if ($highlightMatches) {
226241
$highlightedColumns = $this->filterColumn == 'all' ? $this->filterAttributes : [$this->filterColumn];
227242
if ($paginate) {

0 commit comments

Comments
 (0)