Power-Components / livewire-powergrid

⚡ PowerGrid generates modern, powerful and easy-to-customize data tables using Laravel Livewire.
https://livewire-powergrid.com
MIT License
1.42k stars 209 forks source link

[FIX] Refactoring powergrid:create command #1404

Closed dansysanalyst closed 5 months ago

dansysanalyst commented 5 months ago

⚡ PowerGrid - Pull Request

Motivation

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

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):

https://github.com/Power-Components/livewire-powergrid/issues/1394

Documentation

This PR requires Documentation update?

dansysanalyst commented 5 months ago

@luanfreitasdev please review it thoroughly!

luanfreitasdev commented 5 months ago

Thank you @dansysanalyst. This looks amazing!