Skip to content

Commit

Permalink
Pint
Browse files Browse the repository at this point in the history
  • Loading branch information
invaders-xx committed Apr 23, 2024
1 parent 62ade41 commit 5e01b0e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
17 changes: 10 additions & 7 deletions src/Commands/MakeNestedListPageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@
class MakeNestedListPageCommand extends Command
{
use CanManipulateFiles;

public $description = 'Creates a Filament nested list page class';
protected $signature = "make:filament-nested-list-page {name?} {--model=} {--R|resource=} {--F|force}";

protected $signature = 'make:filament-nested-list-page {name?} {--model=} {--R|resource=} {--F|force}';

protected ?string $resourceClass = null;

protected string $page;

protected string $pageClass;

public function handle(): int
{
$this->page = Str::of(strval($this->argument('name') ?? $this->askRequired('Name (e.g. `Users`)', 'name')))
$this->page = Str::of(strval($this->argument('name') ?? $this->askRequired('Name (e.g. `Users`)', 'name')))
->trim('/')
->trim('\\')
->trim(' ')
Expand Down Expand Up @@ -108,7 +112,6 @@ protected function createPage(): bool
->replace('//', '/')
->append('.php');


if (! $this->option('force') && $this->checkForCollision([$path])) {
return false;
}
Expand All @@ -130,16 +133,16 @@ protected function createPage(): bool

$this->copyStubToApp($stub, $path, [
'class' => $this->pageClass,
'namespace' => $namespace . ($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'namespace' => $namespace.($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'modelClass' => $modelClass == $this->pageClass ? 'NestedListPageModel' : $modelClass,
'model' => $model == $this->pageClass ? "{$model} as NestedListPageModel" : $model,
]);
} else {
$this->copyStubToApp($stub, $path, [
'namespace' => "{$resourceNamespace}\\{$resourceClass}\\Pages" . ($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'namespace' => "{$resourceNamespace}\\{$resourceClass}\\Pages".($pageNamespace !== '' ? "\\{$pageNamespace}" : ''),
'resource' => $this->resourceClass == $this->pageClass ? "{$resourceNamespace}\\{$resourceClass} as NestedListPageResource" : "{$resourceNamespace}\\{$resourceClass}",
'class' => $this->pageClass,
'resourceClass' => $resourceClass == $this->pageClass ? "NestedListPageResource" : $resourceClass,
'resourceClass' => $resourceClass == $this->pageClass ? 'NestedListPageResource' : $resourceClass,
]);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Commands/MakeNestedListWidgetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class MakeNestedListWidgetCommand extends Command
{
use CanManipulateFiles;

protected $description = 'Creates a Filament nested list widget class.';

protected $signature = 'make:filament-nested-list-widget {name?} {model?} {--R|resource=} {--F|force}';
Expand Down Expand Up @@ -44,7 +44,7 @@ public function handle(): int
->afterLast('\\');
}

$widget = Str::of(strval($this->argument('name') ?? $this->askRequired('Name (e.g. `ProductCategory`)', 'name')))
$widget = Str::of(strval($this->argument('name') ?? $this->askRequired('Name (e.g. `ProductCategory`)', 'name')))
->trim('/')
->trim('\\')
->trim(' ')
Expand Down Expand Up @@ -76,9 +76,9 @@ public function handle(): int

$this->copyStubToApp('NestedListWidget', $path, [
'class' => $widgetClass,
'namespace' => filled($resource) ? "{$resourceNamespace}\\{$resource}\\Widgets" . ($widgetNamespace !== '' ? "\\{$widgetNamespace}" : '') : $namespace . ($widgetNamespace !== '' ? "\\{$widgetNamespace}" : ''),
'namespace' => filled($resource) ? "{$resourceNamespace}\\{$resource}\\Widgets".($widgetNamespace !== '' ? "\\{$widgetNamespace}" : '') : $namespace.($widgetNamespace !== '' ? "\\{$widgetNamespace}" : ''),
'model' => $model == $widgetClass ? "{$model} as TreeWidgetModel" : $model,
'modelClass' => $modelClass == $widgetClass ? "TreeWidgetModel" : $modelClass,
'modelClass' => $modelClass == $widgetClass ? 'TreeWidgetModel' : $modelClass,
]);

$this->info("Successfully created {$widget} !");
Expand All @@ -89,7 +89,7 @@ public function handle(): int

return static::SUCCESS;
}

protected function askRequired(string $question, string $field, ?string $default = null): string
{
return $this->validateInput(fn () => $this->ask($question, $default), $field, ['required']);
Expand Down
4 changes: 2 additions & 2 deletions src/Concern/HasActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function getMountedNestedListAction(): ?Action
}

/**
* @param array<string>|string $name
* @param array<string>|string $name
*/
public function getCachedNestedListAction(string|array $name): ?Action
{
Expand Down Expand Up @@ -228,7 +228,7 @@ public function getMountedNestedListActionForm()
return $action->getForm(
$this->makeForm()
->model($this->getMountedNestedListActionRecord() ?? $this->getNestedListQuery()->getModel()::class)
->statePath('mountedNestedListActionData.' . array_key_last($this->mountedNestedListActionData))
->statePath('mountedNestedListActionData.'.array_key_last($this->mountedNestedListActionData))
->operation(implode('.', $this->mountedNestedListAction)),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Concern/HasRecords.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getNestedListRecord(?string $key): ?Model

protected function resolveNestedListRecord(?string $key): ?Model
{
if (null === $key) {
if ($key === null) {
return null;
}

Expand Down
1 change: 0 additions & 1 deletion src/Concern/InteractWithNestedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function getNestedListRecordTitle(?Model $record = null): string
return $record->{(method_exists($record, 'determineTitleColumnName') ? $record->determineTitleColumnName() : 'title')};
}


public function getRecordKey(?Model $record): ?string
{
return $this->getCachedNestedList()->getRecordKey($record);
Expand Down
4 changes: 2 additions & 2 deletions src/FilamentNestedListServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function boot()
public function packageBooted(): void
{
FilamentAsset::register([
Css::make('filament-nested-list-styles', __DIR__ . '/../resources/dist/filament-nested-list.css'),
Js::make('filament-nested-list-scripts', __DIR__ . '/../resources/dist/filament-nested-list.js'),
Css::make('filament-nested-list-styles', __DIR__.'/../resources/dist/filament-nested-list.css'),
Js::make('filament-nested-list-scripts', __DIR__.'/../resources/dist/filament-nested-list.js'),
], 'invaders-xx/filament-nested-list');
}

Expand Down
4 changes: 2 additions & 2 deletions src/Forms/Components/NestedList.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public function getCachedExistingRecords(): Collection

if ($relationship instanceof BelongsToMany) {
$relationshipQuery->select([
$relationship->getTable() . '.*',
$relationshipQuery->getModel()->getTable() . '.*',
$relationship->getTable().'.*',
$relationshipQuery->getModel()->getTable().'.*',
]);
}

Expand Down

0 comments on commit 5e01b0e

Please sign in to comment.