Skip to content

Commit

Permalink
Merge pull request #153 from dansysanalyst/dev
Browse files Browse the repository at this point in the history
Stubs passing static analysis
  • Loading branch information
luanfreitasdev authored Nov 25, 2021
2 parents 6fca742 + 1c0ace4 commit 77c87f7
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 52 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"doctrine/dbal": "^3.1"
},
"scripts": {
"cs-fixer": "./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no --stop-on-violation",
"fix": "./vendor/bin/php-cs-fixer fix",
"test": "@test:sqlite",
"test:sqlite": "./vendor/bin/pest --configuration phpunit.sqlite.xml",
"test:mysql": "./vendor/bin/pest --configuration phpunit.mysql.xml",
"test:pgsql": "./vendor/bin/pest --configuration phpunit.pgsql.xml",
"test:types": "./vendor/bin/phpstan analyse --ansi --memory-limit=-1",
"cs-fixer": "./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no --stop-on-violation",
"fix": "./vendor/bin/php-cs-fixer fix",
"dbs": [
"test:dbs": [
"@test:sqlite",
"@test:mysql",
"@test:pgsql"
Expand Down
24 changes: 15 additions & 9 deletions resources/stubs/table.collection.stub
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use PowerComponents\LivewirePowerGrid\PowerGridEloquent;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Traits\ActionButton;

class {{ componentName }} extends PowerGridComponent
final class {{ componentName }} extends PowerGridComponent
{
use ActionButton;

Expand All @@ -21,7 +21,7 @@ class {{ componentName }} extends PowerGridComponent
| Provides data to your Table using a Model or Collection
|
*/
public function datasource(): Collection
public function datasource(): ?Collection
{
return collect([
['id' => 1, 'name' => 'Name 1', 'price' => 1.58, 'created_at' => now(),],
Expand All @@ -39,7 +39,7 @@ class {{ componentName }} extends PowerGridComponent
| Configure here relationships to be used by the Search and Table Filters.
|
*/
public function setUp()
public function setUp(): void
{
$this->showCheckBox()
->showPerPage()
Expand All @@ -55,7 +55,7 @@ class {{ componentName }} extends PowerGridComponent
| You can pass a closure to transform/modify the data.
|
*/
public function addColumns(): PowerGridEloquent
public function addColumns(): ?PowerGridEloquent
{
return PowerGrid::eloquent()
->addColumn('id')
Expand All @@ -73,32 +73,38 @@ class {{ componentName }} extends PowerGridComponent
| Include the columns added columns, making them visible on the Table.
| Each column can be configured with properties, filters, actions...
|

*/
/**
* PowerGrid Columns.
*
* @return array<int, \PowerComponents\LivewirePowerGrid\Column>
*/
public function columns(): array
{
return [
Column::add()
->title(__('ID'))
->title('ID')
->field('id')
->searchable()
->sortable(),

Column::add()
->title(__('Name'))
->title('Name')
->field('name')
->searchable()
->makeInputText('name')
->sortable(),

Column::add()
->title(__('price'))
->title('Price')
->field('price')
->sortable()
->makeInputRange('price', '.', ''),

Column::add()
->title(__('Created At'))
->field('created_at_formatted', 'created_at')
->title('Created At')
->field('created_at_formatted')
->makeInputDatePicker('created_at'),
];
}
Expand Down
60 changes: 44 additions & 16 deletions resources/stubs/table.fillable.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ use PowerComponents\LivewirePowerGrid\PowerGridEloquent;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\Traits\ActionButton;

class {{ componentName }} extends PowerGridComponent
final class {{ componentName }} extends PowerGridComponent
{
use ActionButton;


//Messages informing success/error data is updated.
public bool $showUpdateMessages = true;

/*
Expand All @@ -26,12 +27,12 @@ class {{ componentName }} extends PowerGridComponent
| Setup Table's general features
|
*/
public function setUp()
public function setUp(): void
{
$this->showCheckBox()
->showPerPage()
->showExportOption('download', ['excel', 'csv'])
->showSearchInput();
->showSearchInput()
->showExportOption('download', ['excel', 'csv']);
}

/*
Expand All @@ -53,6 +54,12 @@ class {{ componentName }} extends PowerGridComponent
| Configure here relationships to be used by the Search and Table Filters.
|
*/

/**
* Relationship search.
*
* @return array<string, array<int, string>>
*/
public function relationSearch(): array
{
return [];
Expand All @@ -79,6 +86,12 @@ class {{ componentName }} extends PowerGridComponent
| Each column can be configured with properties, filters, actions...
|
*/

/**
* PowerGrid Columns.
*
* @return array<int, \PowerComponents\LivewirePowerGrid\Column>
*/
public function columns(): array
{
return {{ columns }};
Expand All @@ -92,17 +105,23 @@ class {{ componentName }} extends PowerGridComponent
|
*/

/**
* PowerGrid {{ modelLastName }} action buttons.
*
* @return array<int, \PowerComponents\LivewirePowerGrid\Button>
*/

/*
public function actions(): array
{
return [
Button::add('edit')
->caption(__('Edit'))
->caption('Edit')
->class('bg-indigo-500 text-white')
->route('{{ modelKebabCase }}.edit', ['{{ modelKebabCase }}' => 'id']),

Button::add('destroy')
->caption(__('Delete'))
->caption('Delete')
->class('bg-red-500 text-white')
->route('{{ modelKebabCase }}.destroy', ['{{ modelKebabCase }}' => 'id'])
->method('delete')
Expand All @@ -114,38 +133,47 @@ class {{ componentName }} extends PowerGridComponent
|--------------------------------------------------------------------------
| Edit Method
|--------------------------------------------------------------------------
| Enable this section to use editOnClick() or toggleable() methods
| Enable this section to use editOnClick() or toggleable() methods.
| Data must be validated and treated (see "Update Data" in PowerGrid doc).
|
*/

/**
* PowerGrid {{ modelLastName }} Update.
*
* @param array<string,string> $data
*/

/*
public function update(array $data ): bool
{
try {
$updated = {{ modelLastName }}::query()->find($data['id'])->update([
$data['field'] => $data['value']
]);
$updated = {{ modelLastName }}::query()->findOrFail($data['id'])
->update([
$data['field'] => $data['value'],
]);
} catch (QueryException $exception) {
$updated = false;
}
return $updated;
}

public function updateMessages(string $status, string $field = '_default_message'): string
public function updateMessages(string $status = 'error', string $field = '_default_message'): string
{
$updateMessages = [
'success' => [
'_default_message' => __('Data has been updated successfully!'),
//'custom_field' => __('Custom Field updated successfully!'),
//'custom_field' => __('Custom Field updated successfully!'),
],
'error' => [
'_default_message' => __('Error updating the data.'),
//'custom_field' => __('Error updating custom field.'),
//'custom_field' => __('Error updating custom field.'),
]
];

return ($updateMessages[$status][$field] ?? $updateMessages[$status]['_default_message']);
$message = ($updateMessages[$status][$field] ?? $updateMessages[$status]['_default_message']);

return (is_string($message)) ? $message : 'Error!';
}
*/

}
Loading

0 comments on commit 77c87f7

Please sign in to comment.