Skip to content

Commit

Permalink
Merge pull request #1398 from moonshine-software/lazy-resource
Browse files Browse the repository at this point in the history
[3.x] Lazy resource
  • Loading branch information
lee-to authored Dec 26, 2024
2 parents 7fcdc95 + e727a7c commit b76ff52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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): TableBuilder => $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

0 comments on commit b76ff52

Please sign in to comment.