diff --git a/packages/panels/src/Commands/MakePageCommand.php b/packages/panels/src/Commands/MakePageCommand.php index a0be939134..7f9a6bc938 100644 --- a/packages/panels/src/Commands/MakePageCommand.php +++ b/packages/panels/src/Commands/MakePageCommand.php @@ -586,27 +586,29 @@ class MakePageCommand extends Command ); }; - if (! $this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_SCHEMAS)) { - $formSchemaFqn = $this->askForSchema( - intialQuestion: 'Should an existing form schema class be used?', - question: 'Which form schema class would you like to use?', - questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Schemas\\UserForm', - ); - } - - if (blank($formSchemaFqn)) { - $askForIsGeneratedIfNotAlready() - ? $askForRelatedModelFqnIfNotAlready() - : $askForRecordTitleAttributeIfNotAlready(); - } - if (confirm( 'Would you like to generate a read-only view modal for the table?', default: false, )) { $hasViewOperation = true; + } + $askForIsGeneratedIfNotAlready(); + + if ($isGenerated) { + $askForRelatedModelFqnIfNotAlready(); + } + + if (! $isGenerated) { if (! $this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_SCHEMAS)) { + $formSchemaFqn = $this->askForSchema( + intialQuestion: 'Should an existing form schema class be used?', + question: 'Which form schema class would you like to use?', + questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Schemas\\UserForm', + ); + } + + if ($hasViewOperation && (! $this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_SCHEMAS))) { $infolistSchemaFqn = $this->askForSchema( intialQuestion: 'Would you like to use an existing infolist schema class?', question: 'Which infolist schema class would you like to use?', @@ -614,30 +616,26 @@ class MakePageCommand extends Command ); } - if (blank($infolistSchemaFqn)) { - $askForRecordTitleAttributeIfNotAlready(); + if (! $this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_TABLES)) { + $tableFqn = $this->askForSchema( + intialQuestion: 'Would you like to use an existing table class?', + question: 'Which table class would you like to use?', + questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Tables\\UsersTable', + ); } } - if ($this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_TABLES)) { - $askForIsGeneratedIfNotAlready() - ? $askForRelatedModelFqnIfNotAlready() - : $askForRecordTitleAttributeIfNotAlready(); - } else { - $tableFqn = $this->askForSchema( - intialQuestion: 'Would you like to use an existing table class?', - question: 'Which table class would you like to use?', - questionPlaceholder: app()->getNamespace() . 'Filament\\Resources\\Users\\Tables\\UsersTable', - ); + if (blank($formSchemaFqn) && (! $isGenerated)) { + $askForRecordTitleAttributeIfNotAlready(); + } + + if ($hasViewOperation && blank($infolistSchemaFqn) && (! $isGenerated)) { + $askForRecordTitleAttributeIfNotAlready(); } if (blank($tableFqn)) { $askForRecordTitleAttributeIfNotAlready(); - $askForIsGeneratedIfNotAlready( - question: 'Should the table columns be generated from the current database columns?', - ) && $askForRelatedModelFqnIfNotAlready(); - $isSoftDeletable = (filled($relatedModelFqn) && static::$shouldCheckModelsForSoftDeletes && class_exists($relatedModelFqn)) ? in_array(SoftDeletes::class, class_uses_recursive($relatedModelFqn)) : confirm( diff --git a/packages/panels/src/Commands/MakeRelationManagerCommand.php b/packages/panels/src/Commands/MakeRelationManagerCommand.php index d2dd169ece..a85f906e28 100644 --- a/packages/panels/src/Commands/MakeRelationManagerCommand.php +++ b/packages/panels/src/Commands/MakeRelationManagerCommand.php @@ -247,47 +247,35 @@ class MakeRelationManagerCommand extends Command if (blank($this->relatedResourceFqn)) { $this->configureHasViewOperation(); - $this->configureFormSchemaFqn(); + $this->configureIsGeneratedIfNotAlready(); - if ($this->hasViewOperation) { - $this->configureInfolistSchemaFqn(); + if ($this->isGenerated) { + $this->configureRelatedModelFqnIfNotAlready(); } - if (! $this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_TABLES)) { - $this->configureTableFqn(); + if (! $this->isGenerated) { + $this->configureFormSchemaFqn(); + + if ($this->hasViewOperation) { + $this->configureInfolistSchemaFqn(); + } + + if (! $this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_TABLES)) { + $this->configureTableFqn(); + } } - if (blank($this->formSchemaFqn)) { - $this->configureIsGeneratedIfNotAlready(); - - $this->isGenerated - ? $this->configureRelatedModelFqnIfNotAlready() - : $this->configureRecordTitleAttributeIfNotAlready(); - } - - if ($this->hasViewOperation && blank($this->infolistSchemaFqn)) { + if (blank($this->formSchemaFqn) && (! $this->isGenerated)) { $this->configureRecordTitleAttributeIfNotAlready(); } - if ($this->hasFileGenerationFlag(FileGenerationFlag::EMBEDDED_PANEL_RESOURCE_TABLES)) { - $this->configureIsGeneratedIfNotAlready(); - - $this->isGenerated - ? $this->configureRelatedModelFqnIfNotAlready() - : $this->configureRecordTitleAttributeIfNotAlready(); + if ($this->hasViewOperation && blank($this->infolistSchemaFqn) && (! $this->isGenerated)) { + $this->configureRecordTitleAttributeIfNotAlready(); } if (blank($this->tableFqn)) { $this->configureRecordTitleAttributeIfNotAlready(); - $this->configureIsGeneratedIfNotAlready( - question: 'Should the table columns be generated from the current database columns?', - ); - - if ($this->isGenerated) { - $this->configureRelatedModelFqnIfNotAlready(); - } - $this->configureIsSoftDeletable(); $this->configureRelationshipType(); diff --git a/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php b/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php index 7c19f2f684..58904fbfd9 100644 --- a/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php +++ b/tests/src/Panels/Commands/Legacy/LegacyMakePageCommandTest.php @@ -366,9 +366,9 @@ it('can generate a manage related records page class in a resource', function () $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) + ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isGenerated'], false) ->expectsQuestion($questions['titleAttribute'], 'name') - ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -399,9 +399,9 @@ it('can generate a manage related records page class in a resource with a genera $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) + ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isGenerated'], true) ->expectsQuestion($questions['relatedModel'], 'Filament\\Tests\\Fixtures\\Models\\Team') - ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -417,9 +417,9 @@ it('can generate a manage related records page class in a resource with a view o $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) + ->expectsQuestion($questions['hasViewOperation'], true) ->expectsQuestion($questions['isGenerated'], false) ->expectsQuestion($questions['titleAttribute'], 'name') - ->expectsQuestion($questions['hasViewOperation'], true) ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -434,9 +434,9 @@ it('can generate a manage related records page class in a resource with soft-del $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) + ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isGenerated'], false) ->expectsQuestion($questions['titleAttribute'], 'name') - ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isSoftDeletable'], true) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -451,9 +451,9 @@ it('can generate a manage related records page class in a resource for a `HasMan $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) + ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isGenerated'], false) ->expectsQuestion($questions['titleAttribute'], 'name') - ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], HasMany::class); diff --git a/tests/src/Panels/Commands/MakePageCommandTest.php b/tests/src/Panels/Commands/MakePageCommandTest.php index a5c10cd182..1c5a803d71 100644 --- a/tests/src/Panels/Commands/MakePageCommandTest.php +++ b/tests/src/Panels/Commands/MakePageCommandTest.php @@ -347,7 +347,6 @@ $generateManageRelatedRecordsPageCommandQuestions = [ 'relatedModel' => 'What is the related model?', 'titleAttribute' => 'What is the title attribute for this model?', 'formSchemaClass' => 'Which form schema class would you like to use?', - 'isGeneratedTable' => 'Should the table columns be generated from the current database columns?', 'hasViewOperation' => 'Would you like to generate a read-only view modal for the table?', 'hasInfolistSchemaClass' => 'Would you like to use an existing infolist schema class?', 'infolistSchemaClass' => 'Which infolist schema class would you like to use?', @@ -363,11 +362,11 @@ it('can generate a manage related records page class in a resource', function () $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) - ->expectsQuestion($questions['isGenerated'], false) - ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['hasViewOperation'], false) + ->expectsQuestion($questions['isGenerated'], false) + ->expectsQuestion($questions['hasFormSchemaClass'], false) ->expectsQuestion($questions['hasTableClass'], false) + ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -398,12 +397,12 @@ it('can generate a manage related records page class in a resource with a form s $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) + ->expectsQuestion($questions['hasViewOperation'], false) + ->expectsQuestion($questions['isGenerated'], false) ->expectsQuestion($questions['hasFormSchemaClass'], true) ->expectsQuestion($questions['formSchemaClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Schemas\\TeamForm') - ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['hasTableClass'], false) ->expectsQuestion($questions['titleAttribute'], 'name') - ->expectsQuestion($questions['isGeneratedTable'], false) ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -418,11 +417,9 @@ it('can generate a manage related records page class in a resource with a genera $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) + ->expectsQuestion($questions['hasViewOperation'], false) ->expectsQuestion($questions['isGenerated'], true) ->expectsQuestion($questions['relatedModel'], 'Filament\\Tests\\Fixtures\\Models\\Team') - ->expectsQuestion($questions['hasViewOperation'], false) - ->expectsQuestion($questions['hasTableClass'], false) ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -438,12 +435,12 @@ it('can generate a manage related records page class in a resource with a view o $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) - ->expectsQuestion($questions['isGenerated'], false) - ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['hasViewOperation'], true) + ->expectsQuestion($questions['isGenerated'], false) + ->expectsQuestion($questions['hasFormSchemaClass'], false) ->expectsQuestion($questions['hasInfolistSchemaClass'], false) ->expectsQuestion($questions['hasTableClass'], false) + ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -458,13 +455,13 @@ it('can generate a manage related records page class in a resource with an infol $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) - ->expectsQuestion($questions['isGenerated'], false) - ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['hasViewOperation'], true) + ->expectsQuestion($questions['isGenerated'], false) + ->expectsQuestion($questions['hasFormSchemaClass'], false) ->expectsQuestion($questions['hasInfolistSchemaClass'], true) ->expectsQuestion($questions['infolistSchemaClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Schemas\\TeamInfolist') ->expectsQuestion($questions['hasTableClass'], false) + ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -479,12 +476,12 @@ it('can generate a manage related records page class in a resource with a table $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) - ->expectsQuestion($questions['isGenerated'], false) - ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['hasViewOperation'], false) + ->expectsQuestion($questions['isGenerated'], false) + ->expectsQuestion($questions['hasFormSchemaClass'], false) ->expectsQuestion($questions['hasTableClass'], true) - ->expectsQuestion($questions['tableClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Tables\\TeamsTable'); + ->expectsQuestion($questions['tableClass'], app()->getNamespace() . 'Filament\\Resources\\Teams\\Tables\\TeamsTable') + ->expectsQuestion($questions['titleAttribute'], 'name'); assertFileExists($path = app_path('Filament/Resources/Users/Pages/ManageUserTeams.php')); expect(file_get_contents($path)) @@ -497,11 +494,11 @@ it('can generate a manage related records page class in a resource with soft-del $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) - ->expectsQuestion($questions['isGenerated'], false) - ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['hasViewOperation'], false) + ->expectsQuestion($questions['isGenerated'], false) + ->expectsQuestion($questions['hasFormSchemaClass'], false) ->expectsQuestion($questions['hasTableClass'], false) + ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], true) ->expectsQuestion($questions['relationshipType'], BelongsToMany::class); @@ -516,11 +513,11 @@ it('can generate a manage related records page class in a resource for a `HasMan $runGenerateManageRelatedRecordsPageCommand($this) ->expectsQuestion($questions['relationship'], 'teams') ->expectsQuestion($questions['hasRelatedResource'], false) - ->expectsQuestion($questions['hasFormSchemaClass'], false) - ->expectsQuestion($questions['isGenerated'], false) - ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['hasViewOperation'], false) + ->expectsQuestion($questions['isGenerated'], false) + ->expectsQuestion($questions['hasFormSchemaClass'], false) ->expectsQuestion($questions['hasTableClass'], false) + ->expectsQuestion($questions['titleAttribute'], 'name') ->expectsQuestion($questions['isSoftDeletable'], false) ->expectsQuestion($questions['relationshipType'], HasMany::class);