Skip to content

Commit

Permalink
feat: Add table summaries for average, count, range, sum
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Apr 13, 2024
1 parent 3669aa3 commit 285b688
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/Handlers/StubHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public function getStubs(): Collection
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Columns\Select::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Columns\ExtraAttributes::make($resource)->get(),

\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries\Average::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries\Count::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries\Range::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries\Sum::make($resource)->get(),

\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Filters\Reset::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Filters\Add::make($resource)->get(),
\CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Filters\Remove::make($resource)->get(),
Expand Down
5 changes: 5 additions & 0 deletions src/Stubs/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,11 @@ public function getTableSelectColumnsWithOptions(Resource $resource): array
])->toArray();
}

public function getResourceTableColumnsWithSummarizers(Resource $resource): Collection
{
return $this->getTableColumns($resource)->filter(fn($column) => $column->getSummarizers());
}

public function hasSoftDeletes(Resource $resource): bool
{
return method_exists($resource->getModel(), 'bootSoftDeletes');
Expand Down
20 changes: 20 additions & 0 deletions src/Stubs/Page/Index/Table/Summaries/Average.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries;

use Closure;
use CodeWithDennis\FilamentTests\Stubs\Base;

class Average extends Base
{
public Closure|bool $isTodo = true;

public function getShouldGenerate(): bool
{
return $this->getResourceTableColumnsWithSummarizers($this->resource)
->filter(fn($column) => collect($column->getSummarizers())
->filter(fn($summarizer) => $summarizer::class === \Filament\Tables\Columns\Summarizers\Average::class)
->count())
->isNotEmpty();
}
}
20 changes: 20 additions & 0 deletions src/Stubs/Page/Index/Table/Summaries/Count.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries;

use Closure;
use CodeWithDennis\FilamentTests\Stubs\Base;

class Count extends Base
{
public Closure|bool $isTodo = true;

public function getShouldGenerate(): bool
{
return $this->getResourceTableColumnsWithSummarizers($this->resource)
->filter(fn($column) => collect($column->getSummarizers())
->filter(fn($summarizer) => $summarizer::class === \Filament\Tables\Columns\Summarizers\Count::class)
->count())
->isNotEmpty();
}
}
20 changes: 20 additions & 0 deletions src/Stubs/Page/Index/Table/Summaries/Range.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries;

use Closure;
use CodeWithDennis\FilamentTests\Stubs\Base;

class Range extends Base
{
public Closure|bool $isTodo = true;

public function getShouldGenerate(): bool
{
return $this->getResourceTableColumnsWithSummarizers($this->resource)
->filter(fn($column) => collect($column->getSummarizers())
->filter(fn($summarizer) => $summarizer::class === \Filament\Tables\Columns\Summarizers\Range::class)
->count())
->isNotEmpty();
}
}
17 changes: 17 additions & 0 deletions src/Stubs/Page/Index/Table/Summaries/Sum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace CodeWithDennis\FilamentTests\Stubs\Page\Index\Table\Summaries;

use Closure;
use CodeWithDennis\FilamentTests\Stubs\Base;

class Sum extends Base
{
public Closure|bool $isTodo = true;

public function getShouldGenerate(): bool
{
return true;
// return $this->getResourceTableColumnsWithSummarizers($this->resource)->isNotEmpty();
}
}
4 changes: 2 additions & 2 deletions stubs/Page/Index/Table/Filters/Add.stub
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
it('can add a table filter', function () {

})->group('filters', 'table')->todo();
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
4 changes: 2 additions & 2 deletions stubs/Page/Index/Table/Filters/Remove.stub
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
it('can remove a table filter', function () {

})->group('filters', 'table')->todo();
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
2 changes: 1 addition & 1 deletion stubs/Page/Index/Table/Filters/Reset.stub
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ it('can reset table filters', function () {
livewire(List{{ MODEL_PLURAL_NAME }}::class)
->resetTableFilters(){{ LOAD_TABLE_METHOD_IF_DEFERRED }}
->assertCanSeeTableRecords($records);
})->group('filters', 'table');
}){{ RESOLVED_GROUP_METHOD }};
3 changes: 3 additions & 0 deletions stubs/Page/Index/Table/Summaries/Average.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('can average values in a column', function () {
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
3 changes: 3 additions & 0 deletions stubs/Page/Index/Table/Summaries/Count.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('can count values in a column', function () {
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
3 changes: 3 additions & 0 deletions stubs/Page/Index/Table/Summaries/Range.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('can range values in a column', function () {
//
}){{ RESOLVED_GROUP_METHOD }}->todo();
3 changes: 3 additions & 0 deletions stubs/Page/Index/Table/Summaries/Sum.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
it('can sum values in a column', function () {
//
}){{ RESOLVED_GROUP_METHOD }}->todo();

0 comments on commit 285b688

Please sign in to comment.