Skip to content

Commit

Permalink
feat: Resource lazy load
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Dec 19, 2024
1 parent e02be10 commit 4d0ac12
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/Laravel/src/Pages/Crud/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ protected function getItemsComponent(iterable $items, Fields $fields): Component
->when($this->getResource()->isStickyTable(), function (TableBuilderContract $table): void {
$table->sticky();
})
->when($this->getResource()->isLazy(), function (TableBuilderContract $table): void {
$table->lazy()->whenAsync(fn(TableBuilderContract $t) => $t->items($this->getResource()->getItems()));
})
->when($this->getResource()->isColumnSelection(), function (TableBuilderContract $table): void {
$table->columnSelection();
});
Expand All @@ -251,7 +254,7 @@ protected function getItemsComponents(): array
request()->only($this->getResource()->getQueryParamsKeys())
);

$items = $this->getResource()->getItems();
$items = $this->getResource()->isLazy() ? [] : $this->getResource()->getItems();
$fields = $this->getResource()->getIndexFields();

return [
Expand Down
7 changes: 7 additions & 0 deletions src/Laravel/src/Resources/CrudResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ abstract class CrudResource extends Resource implements CrudResourceContract

protected bool $isAsync = true;

protected bool $isLazy = false;

protected bool $isPrecognitive = false;

protected bool $deleteRelationships = false;
Expand Down Expand Up @@ -210,6 +212,11 @@ public function isAsync(): bool
return $this->isAsync;
}

public function isLazy(): bool
{
return $this->isLazy;
}

public function isPrecognitive(): bool
{
return $this->isPrecognitive;
Expand Down
2 changes: 1 addition & 1 deletion src/UI/dist/assets/app.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/UI/resources/js/Components/TableBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ export default (
})
},
initColumnSelection() {
if (!this.table) {
return
}

if (!this.block) {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/UI/src/Components/IterableComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function resolvePaginator(): void

public function getItems(): Collection
{
return collect($this->items)->filter();
return $this->items = collect($this->items)->filter();
}

public function paginator(PaginatorContract $paginator): static
Expand Down

0 comments on commit 4d0ac12

Please sign in to comment.