Skip to content

Commit b4dcf3f

Browse files
refactor: revert to PowerGridFields in Commands and Concerns
1 parent 82af798 commit b4dcf3f

12 files changed

Lines changed: 37 additions & 37 deletions

‎resources/stubs/table.model.fillable.stub‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ final class {{ componentName }} extends PowerGridComponent
4141

4242
public function fields(): PowerGridFields
4343
{
44-
return PowerGrid::fields(){{ Fields }};
44+
return PowerGrid::fields(){{ PowerGridFields }};
4545
}
4646

4747
public function columns(): array

‎resources/stubs/table.query-builder.fillable.stub‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class {{ componentName }} extends PowerGridComponent
3737

3838
public function fields(): PowerGridFields
3939
{
40-
return PowerGrid::fields(){{ Fields }};
40+
return PowerGrid::fields(){{ PowerGridFields }};
4141
}
4242

4343
public function columns(): array

‎src/Commands/Actions/BuildStubVars.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final class BuildStubVars
1919
* @param list<string> $fields Column names, in the order they should be generated.
2020
* @param Collection<string, string> $types Column name => normalized type bucket.
2121
* @param string $model Model class used to type-hint generated closures; empty leaves them untyped.
22-
* @return array{'Fields': string, 'filters': string, 'columns': string}
22+
* @return array{'PowerGridFields': string, 'filters': string, 'columns': string}
2323
*/
2424
public static function handle(array $fields, Collection $types, string $model = ''): array
2525
{
@@ -46,7 +46,7 @@ public static function describe(string $type): string
4646
/**
4747
* @param list<string> $fields
4848
* @param Collection<string, string> $types
49-
* @return array{'Fields': string, 'filters': string, 'columns': string}
49+
* @return array{'PowerGridFields': string, 'filters': string, 'columns': string}
5050
*/
5151
private function build(array $fields, Collection $types, string $model): array
5252
{
@@ -74,7 +74,7 @@ private function build(array $fields, Collection $types, string $model): array
7474
$this->columns .= ' Column::action(\'Action\')'."\n";
7575

7676
return [
77-
'Fields' => $this->fields,
77+
'PowerGridFields' => $this->fields,
7878
'filters' => $this->filters.' ];',
7979
'columns' => $this->columns.' ];',
8080
];

‎src/Commands/Actions/GetStubVarsFromDbTable.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class GetStubVarsFromDbTable
99
{
1010
/**
11-
* @return array{'Fields': string, 'filters': string, 'columns': string}
11+
* @return array{'PowerGridFields': string, 'filters': string, 'columns': string}
1212
*/
1313
public static function handle(PowerGridComponentMaker $component): array
1414
{

‎src/Commands/Actions/GetStubVarsFromFromModel.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class GetStubVarsFromFromModel
99
{
1010
/**
11-
* @return array{'Fields': string, 'filters': string, 'columns': string}
11+
* @return array{'PowerGridFields': string, 'filters': string, 'columns': string}
1212
*/
1313
public static function handle(PowerGridComponentMaker $component): array
1414
{

‎src/Commands/Support/PowerGridComponentMaker.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ private function process(): self
213213

214214
if ($this->autoCreateColumns() === true) {
215215
if ($this->datasource === Datasource::ELOQUENT_BUILDER) {
216-
['Fields' => $Fields, 'filters' => $filters, 'columns' => $columns] = GetStubVarsFromFromModel::handle($this);
216+
['PowerGridFields' => $PowerGridFields, 'filters' => $filters, 'columns' => $columns] = GetStubVarsFromFromModel::handle($this);
217217
}
218218

219219
if ($this->datasource === Datasource::QUERY_BUILDER) {
220-
['Fields' => $Fields, 'filters' => $filters, 'columns' => $columns] = GetStubVarsFromDbTable::handle($this);
220+
['PowerGridFields' => $PowerGridFields, 'filters' => $filters, 'columns' => $columns] = GetStubVarsFromDbTable::handle($this);
221221
}
222222
}
223223

224-
$this->stub->setVar('Fields', $Fields ?? '');
224+
$this->stub->setVar('PowerGridFields', $PowerGridFields ?? '');
225225

226226
$this->stub->setVar('filters', $filters ?? '');
227227

‎src/Commands/Support/PowerGridStub.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private function ensureContentCompatibility(): void
3535
->replace('\{{ modelName }}', '{{ model }}')
3636
->replace('{{ modelName }}', '{{ modelFqn }}')
3737
->replace('{{ modelLastName }}', '{{ model }}')
38-
->replace('{{ datasource }}', '{{ Fields }}')
38+
->replace('{{ datasource }}', '{{ PowerGridFields }}')
3939
->replace('{{ dataBaseTableName }}', '{{ databaseTableName }}')
4040
->toString();
4141
}

‎src/Concerns/Base.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Livewire\Attributes\Computed;
66
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
7+
use PowerComponents\LivewirePowerGrid\PowerGridFields;
78
use PowerComponents\Turbine\Components\Filters\FilterBase;
8-
use PowerComponents\Turbine\Fields;
99

1010
trait Base
1111
{
@@ -50,7 +50,7 @@ trait Base
5050

5151
public bool $pruneHiddenColumns = true;
5252

53-
public function fields(): Fields
53+
public function fields(): PowerGridFields
5454
{
5555
return PowerGrid::fields();
5656
}

‎tests/Feature/Actions/BuildStubVarsTest.php‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,70 +6,70 @@
66
$vars = BuildStubVars::handle(['name'], collect(['name' => 'string']));
77

88
expect($vars['columns'])->toContain("Column::make('Name', 'name')\n ->sortable()\n ->searchable(),")
9-
->and($vars['Fields'])->toContain("->add('name')")
9+
->and($vars['PowerGridFields'])->toContain("->add('name')")
1010
->and($vars['filters'])->toContain("Filter::inputText('name')->operators(['contains']),");
1111
});
1212

1313
it('generates a plain column without a filter for an integer', function () {
1414
$vars = BuildStubVars::handle(['votes'], collect(['votes' => 'integer']));
1515

1616
expect($vars['columns'])->toContain("Column::make('Votes', 'votes'),")
17-
->and($vars['Fields'])->toContain("->add('votes')")
17+
->and($vars['PowerGridFields'])->toContain("->add('votes')")
1818
->and($vars['filters'])->not->toContain('votes');
1919
});
2020

2121
it('generates a toggleable column with a boolean filter for a boolean', function () {
2222
$vars = BuildStubVars::handle(['in_stock'], collect(['in_stock' => 'boolean']));
2323

2424
expect($vars['columns'])->toContain("Column::make('In stock', 'in_stock')\n ->toggleable(),")
25-
->and($vars['Fields'])->toContain("->add('in_stock')")
25+
->and($vars['PowerGridFields'])->toContain("->add('in_stock')")
2626
->and($vars['filters'])->toContain("Filter::boolean('in_stock'),");
2727
});
2828

2929
it('generates a formatted column with a date filter for a date', function () {
3030
$vars = BuildStubVars::handle(['published_on'], collect(['published_on' => 'date']));
3131

3232
expect($vars['columns'])->toContain("Column::make('Published on', 'published_on_formatted', 'published_on')")
33-
->and($vars['Fields'])->toContain("->add('published_on_formatted', fn (\$model) => Carbon::parse(\$model->published_on)->format('d/m/Y'))")
33+
->and($vars['PowerGridFields'])->toContain("->add('published_on_formatted', fn (\$model) => Carbon::parse(\$model->published_on)->format('d/m/Y'))")
3434
->and($vars['filters'])->toContain("Filter::datepicker('published_on'),");
3535
});
3636

3737
it('generates a formatted column with a datetime filter for a datetime', function () {
3838
$vars = BuildStubVars::handle(['created_at'], collect(['created_at' => 'datetime']));
3939

4040
expect($vars['columns'])->toContain("Column::make('Created at', 'created_at_formatted', 'created_at')")
41-
->and($vars['Fields'])->toContain("->add('created_at_formatted', fn (\$model) => Carbon::parse(\$model->created_at)->format('d/m/Y H:i:s'))")
41+
->and($vars['PowerGridFields'])->toContain("->add('created_at_formatted', fn (\$model) => Carbon::parse(\$model->created_at)->format('d/m/Y H:i:s'))")
4242
->and($vars['filters'])->toContain("Filter::datetimepicker('created_at'),");
4343
});
4444

4545
it('falls back to a searchable column without a filter for an unknown type', function () {
4646
$vars = BuildStubVars::handle(['payload'], collect(['payload' => 'other']));
4747

4848
expect($vars['columns'])->toContain("Column::make('Payload', 'payload')\n ->sortable()\n ->searchable(),")
49-
->and($vars['Fields'])->toContain("->add('payload')")
49+
->and($vars['PowerGridFields'])->toContain("->add('payload')")
5050
->and($vars['filters'])->toBe("[\n ];");
5151
});
5252

5353
it('adds the closure example to the first string field only', function () {
5454
$vars = BuildStubVars::handle(['name', 'email'], collect(['name' => 'string', 'email' => 'string']));
5555

56-
expect(substr_count($vars['Fields'], 'Example of custom column using a closure'))->toBe(1)
57-
->and($vars['Fields'])->toContain("->add('name_lower', fn (\$model) => strtolower(e(\$model->name)))")
58-
->and($vars['Fields'])->not->toContain('email_lower');
56+
expect(substr_count($vars['PowerGridFields'], 'Example of custom column using a closure'))->toBe(1)
57+
->and($vars['PowerGridFields'])->toContain("->add('name_lower', fn (\$model) => strtolower(e(\$model->name)))")
58+
->and($vars['PowerGridFields'])->not->toContain('email_lower');
5959
});
6060

6161
it('type-hints the model in generated closures', function () {
6262
$vars = BuildStubVars::handle(['name', 'created_at'], collect(['name' => 'string', 'created_at' => 'datetime']), 'Dish');
6363

64-
expect($vars['Fields'])
64+
expect($vars['PowerGridFields'])
6565
->toContain('fn (Dish $model) => strtolower(e($model->name))')
6666
->toContain('fn (Dish $model) => Carbon::parse($model->created_at)');
6767
});
6868

6969
it('skips fields that have no known column type', function () {
7070
$vars = BuildStubVars::handle(['name', 'ghost'], collect(['name' => 'string']));
7171

72-
expect($vars['Fields'])->not->toContain('ghost')
72+
expect($vars['PowerGridFields'])->not->toContain('ghost')
7373
->and($vars['columns'])->not->toContain('ghost');
7474
});
7575

@@ -84,5 +84,5 @@
8484

8585
expect($vars['columns'])->toBe("[\n Column::action('Action')\n ];")
8686
->and($vars['filters'])->toBe("[\n ];")
87-
->and($vars['Fields'])->toBe('');
87+
->and($vars['PowerGridFields'])->toBe('');
8888
});

‎tests/Feature/Actions/GetStubVarsFromDbTableTest.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function waiterQueryBuilderComponent(): PowerGridComponentMaker
2020
it('reads every column of the given table', function () {
2121
$vars = GetStubVarsFromDbTable::handle(waiterQueryBuilderComponent());
2222

23-
expect($vars['Fields'])
23+
expect($vars['PowerGridFields'])
2424
->toContain("->add('id')")
2525
->toContain("->add('name')")
2626
->toContain("->add('email')")
@@ -39,13 +39,13 @@ function waiterQueryBuilderComponent(): PowerGridComponentMaker
3939
it('has no model to hide columns with, unlike the Eloquent source', function () {
4040
$vars = GetStubVarsFromDbTable::handle(waiterQueryBuilderComponent());
4141

42-
expect($vars['Fields'])->toContain("->add('internal_note')");
42+
expect($vars['PowerGridFields'])->toContain("->add('internal_note')");
4343
});
4444

4545
it('leaves the generated closures untyped', function () {
4646
$vars = GetStubVarsFromDbTable::handle(waiterQueryBuilderComponent());
4747

48-
expect($vars['Fields'])->toContain('fn ($model)');
48+
expect($vars['PowerGridFields'])->toContain('fn ($model)');
4949
});
5050

5151
it('generates nothing when the table does not exist', function () {
@@ -54,7 +54,7 @@ function waiterQueryBuilderComponent(): PowerGridComponentMaker
5454
->setDatabaseTable('table_that_does_not_exist')
5555
->setAutoCreateColumns();
5656

57-
expect(GetStubVarsFromDbTable::handle($component)['Fields'])->toBe('');
57+
expect(GetStubVarsFromDbTable::handle($component)['PowerGridFields'])->toBe('');
5858
});
5959

6060
it('renders the generated columns into the query builder stub', function () {

0 commit comments

Comments
 (0)