eighty9nine / filament-approvals

MIT License
68 stars 21 forks source link

The plugin works a bit differently I need... #28

Open sergeynilov opened 3 months ago

sergeynilov commented 3 months ago

Thank you for your plugin!

I added "ringlesoft/laravel-process-approval": "^1.0" and "eightynine/filament-approvals": "^3.1" into Laravel 10.48.14/"filament/filament": "^3.2-stable" app, but it works a bit differently I need :

1) I added into Doc model

extends ApprovableModel so when new model is added it has 1 rows in process_approval_statuses table with

status = Created

2) in Docs Resources I added :


            ->actions([
                ...\EightyNine\Approvals\Tables\Actions\ApprovalActions::make(
                    Action::make("Approve 987"), // "987" - JUST TO SEE THAT IS MY OPTION
                    [
                        Tables\Actions\EditAction::make(), // I REALLY DO NOT UNDERSTAND
                        Tables\Actions\ViewAction::make()  //  WHAT FOR THESE 2 LINES
                    ]
                ),
            ])

```But in listing I see 2 buttons :

    https://img001.prntscr.com/file/img001/j4XEME18SkWa1Kle4-k38g.png

but I need only 1 action "Approve", not "Submit"

3) When I select "Submit" option in 1st "Approvals" button I see
that status in process_approval_statuses = "Submitted" - I need "Approved"

4) If to hide

`    ->actions([`

lines - I do not have 2 buttons I show in printscreen

5) I added line :

`    \EightyNine\Approvals\Tables\Columns\ApprovalStatusColumn::make("approvalStatus.status"),
`
in table method I have error :

`    Attempt to read property "name" on null`

Maybe because Doc model have no "name" field ? Is it configurable ?
billydekid commented 3 months ago

Hi, You can disabled "Submit" button/action as explains here (plugin: ringlesoft/laravel-process-approval): https://github.com/ringlesoft/laravel-process-approval?tab=readme-ov-file#model-submitting

Then the flow or process will be auto-submitted. "This provides the opportunity for editing and other actions on the model before the approval procedure commences."

sergeynilov commented 3 months ago

Thank you for your feedback!

I modify my model :

class Doc extends ApprovableModel
{
    protected $table = 'docs';
    protected $primaryKey = 'id';
    public $timestamps = true;
    public bool $autoSubmit = true;

I edited Doc model Approval Flow with 2 steps :

https://img001.prntscr.com/file/img001/fza2wEZGRLCaRCMAwWIQcQ.png

Next when I create a new doc I see next sql in logs :

   INSERT INTO `docs` (`branch_id`, `department_id`, `doc_code`, `employee_id`, `type`, `creator_id`, `notes`, `title`, `applied_from`, `status`, `doc_attributes`, `updated_at`, `created_at`)
    VALUES (1, 1, 001000100002, 10, MD, 1, Sunt vero rerum est magnam. Qui libero architecto eum occaecati dolore voluptates.<br/> >>>>>>  add some notes on 30 July, 2024 9:18 AM, Herman Schuster is moved to 30 July, 2024 9:18 AM in Web developers department, 2024-07-30 09:18:23, W, {"user_id":10}, 2024-07-30 09:18:23, 2024-07-30 09:18:23)

   ...

   SELECT `process_approval_flow_steps`.*
    FROM `process_approval_flow_steps`
    INNER JOIN `process_approval_flows` on `process_approval_flows`.`id` = `process_approval_flow_steps`.`process_approval_flow_id`
    WHERE `process_approval_flows`.`approvable_type` = App\Models\Doc
    ORDER BY `order` asc, `id` asc

    ...
    INSERT INTO `process_approval_statuses` (`steps`, `status`, `creator_id`, `approvable_id`, `approvable_type`, `updated_at`, `created_at`)
    VALUES ([{"id":2,"action":"CHECK","process_approval_id":null,"role_id":5,"role_name":"MAIN_ACCOUNTANT","process_approval_action":null,"active":null},{"id":1,"action":"APPROVE","process_approval_id":null,"role_id":4,"role_name":"CEO","process_approval_action":null,"active":null}], Submitted, 1, 28, App\Models\Doc, 2024-07-30 09:18:23, 2024-07-30 09:18:23)

a) The 2nd request is just get options for Doc model Approval Flow b) 3rd request added status for my Doc model.

That is clear. What is unclear how now Docs resource page looks for newly added row :

https://img001.prntscr.com/file/img001/OC1CfcvBSua3ZCwd7cawow.png

c) Why no actions for new row? d) I suppose I need to delete old docs with prior flow and $autoSubmit = false; ? e) Have I to edit my resource page somehow ?