Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Refactoring powergrid:create command #1404

Merged

Conversation

dansysanalyst
Copy link
Member

@dansysanalyst dansysanalyst commented Feb 9, 2024

⚡ PowerGrid - Pull Request

Motivation

  • Bug fix
  • Enhancement
  • New feature
  • Breaking change

Description

This Pull Request aims to organize the code structure in everything related to creating a new PowerGrid component, while also resolving the issue mentioned below.

Main Interface Changes

Laravel Prompt Windows Fallback

There is no support for Laravel Prompt in Windows (read more here). I have tried to adapt the prompts to be usable when it goes into "asking question" mode. We might have to put more work to ensure a good user experience in the future. I propose to monitor issues on this topic.

Check for Component Existence

Until now, this check was happening at the end of the wizard, after the user has answered all asked questions. With this PR, this check happens right after the user informed a component name, and it defaults to "no".

CleanShot 2024-02-09 at 22 40 54@2x

Dependencies Notification

I have moved the notification check into a separated command powergrid:check-dependencies.

I rewrote the notification messages to bring more clarity.

In addition, I have also added a "confirmation" step to make sure the user doesn't miss this message. While this might be inconvenient, specially in a prompt fallback situation, we can easily remove this step in src/Commands/CheckDependenciesCommand.php.

B

Installation Wizard

I have provided some new texts and removed tables such as passwords, tokens, migrations from the table listing.

In addition, I improved the parsing of different ways to receive component names for a nested folder structure, such like "tables.admins.users.ListTable" or "\Tables\Admins\Users\ListTable".

In this PR, I have also modified the order questions were asked. I think it makes sense to for the table name in the same step we ask for models (when it applies).

To follow the new nomenclature, the wizard asks to import "fields" and not columns anymore.

CleanShot 2024-02-10 at 00 24 16

To finalize, instead of throwing exceptions, some prompts run on a loop.

When asked for models, if the given model doesn't exist the setup will return to the same question, avoiding having the user starting the wizard all over again.

CleanShot 2024-02-10 at 01 13 42@2x

Same for tables:

CleanShot 2024-02-10 at 10 04 44@2x

Before suggesting importing database table columns as fields, the wizard is now checking if there is a database connection, if the database has tables. If both fail, the setup will assume the given table and continue creating the component. When there are tables, it will suggest tables and validate that the given table exists.

While I think this scenario is less common, this PR allows the users to create components before running migrations.

CleanShot 2024-02-10 at 09 49 41@2x


Main Structural changes

  • Improved variable names in stubs.
  • Legacy variable names are handled to avoid breaking changes.
  • Stubs now have the type (e.g., .fillable) at the end of the filename, so we can decide when to load each type.
  • Stubs are processed by the PowerGridStub class (src/Support/PowerGridStub.php).
  • Data source types are now controlled by an enum src/Enums/Datasource.php. It may be a bit inflated with methods, but I think it is just simple to go this way.
  • The component building process is centered on the PowerGridComponentMaker class (src/Support/PowerGridComponentMaker.php)
  • Questions asked during the wizard are now moved into Actions.

TO DO

The Laravel Prompt tests are failing, I assume, due to a fallback to Symphony Question Helper. I need to dig deeper into testing prompts.

As mentioned above, we have to keep a look at Windows user's experience when creating a component.

Related Issue(s):

#1394

Documentation

This PR requires Documentation update?

  • Yes
  • No
  • I have already submitted a Documentation pull request.

@dansysanalyst
Copy link
Member Author

@luanfreitasdev please review it thoroughly!

@luanfreitasdev
Copy link
Collaborator

Thank you @dansysanalyst. This looks amazing!

@luanfreitasdev luanfreitasdev merged commit 22b9e24 into Power-Components:5.x Feb 10, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants