DavidFeldhoff / al-codeactions

MIT License
17 stars 8 forks source link

[suggestion] Promote an action #151

Closed jwikman closed 1 year ago

jwikman commented 1 year ago

Promoting actions takes a bit more nowadays, compared to just adding the Promoted properties before.

Having a Code Action for this could speed things up a bit! :)

Running the code action (from anywhere within the action) on this code:

            action(ImportStuff)
            {
                Caption = 'Import';
                Image = Import;

                trigger OnAction()
                begin
                    ImportMyStuff()
                end;
            }

Should then create this:

        area(Promoted)
        {
            group(Category_Process)
            {
                Caption = 'Process';

                actionref(Import_Promoted; Import)
                {
                }
            }
        }

Promoting the next action only needs to insert the actionref, of course. :)

An extra feature would be that the user could choose which category to promote inside, but "Process" would be a good start. :)

What do you think about this?

DavidFeldhoff commented 1 year ago

That's a very good idea, thanks for that! I'm going to implement it in the next weeks :)

jwikman commented 1 year ago

Great David! 👍

I gave this some more thoughts, and I believe that you could leave out the group when promoting. As seen at https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-organizing-promoted-actions#how-should-promoted-actions-be-organized, having only one group is unnecessary - it'll be shown as if there was no group at all. So if the new code action just adds the actionref under the area, without group, I think it'll be quite easy for the developer to put it inside any group if they want.

So the result in my example would be like this instead

        area(Promoted)
        {
            actionref(Import_Promoted; Import)
            {
            }
        }

What do you think about that?

DavidFeldhoff commented 1 year ago

Didn't know that automatically unfolding. But that takes only place if there's only the home/processing group. What if my action has something to do with navigation? Would you like to create that group than manually or would you like to have a list of the common groups like Processing, Reports, Navigation, etc.? Like: "Pick one of the following or type in a new action group name"

Another thing that came to my mind: if there are already multiple promoted actions (on my current page or on the base page if I'm currently on a page extension), I probably want to add my new promoted action after another specific action and not want to promote it "somewhere". So I think there should be some kind of a selection where I could select one of the available actions to place mine after the current one, right?

DavidFeldhoff commented 1 year ago

Or an entire other approach: instead of adding a code action, you could simply copy your current action name and then use a snippet like tActionAreaWithPromotedAction Or just tPromotedAction These Snippets would then use the clipboard to create a new actionref at exactly the pace you want it to have 🤔 don't know what might be better. What do you think? Or simply adding both? 😅

jwikman commented 1 year ago

I was about to create that snippet to my extension when it struck me that you probably could create a much more elegeant solution! 😅

But it is challenging to create these kind of actions and cover all possible scenarios and developer wishes! One approach would be to divide the work into smaller pieces and first ship the smallest usable piece, and then see if that is "good enough" or if everyone want it to have more features. The smallest deliverable/usable feature would be what I suggest, without adding groups. Moving the actionref with an existing group with shift, altand up/down is quickly done if needed.

The next "nice to have" feature would be to have a selector on where to place the action, among other promoted actions. This selector would then also make it possible to select which group to place it in. If I have this promoted structure

        area(Promoted)
        {
            actionref(FirstAction_Promoted; FirstAction)
            {
            }
            group(Category_Process)
            {
                Caption = 'Process';
                actionref(SecondAction_Promoted; SecondAction)
                {
                }
            }
            group(Category_New)
            {
                Caption = 'New';
                actionref(ThirdAction_Promoted; ThirdAction)
                {
                }
            }
        }

Would present a selector that would contain something like

In that way, the user could place the new promoted action pretty much anywher, as long as the group exists. (I haven't given the texts too much thought, but I guess that you get the point 🙂)

The last "nice to have" feature would be to have the possibility to create new groups from the "common groups" list (there are some conditions that could be picked from https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-common-promoted-action-groups)

DavidFeldhoff commented 1 year ago

Hi Johannes, I gave it now a try and ended up with this.

promoteAction

What do you think? Best regards, David

DavidFeldhoff commented 1 year ago

Ah.. And the code action only shows up if there are no other actions that have a Promoted = true property set. Because then adding an actionref results in a non-compilable solution as you probably know. Then people simply should use Microsofts code actions to do the one-time-conversion first.

jwikman commented 1 year ago

What do you think? Best regards, David

I gave the new feature a test run - and it works great, good job! 🙂

I think you made the right decision to just place the promoted action last. Showing prompts where you 99 times out of 100 selects the same option is not appreciated.

Ah.. And the code action only shows up if there are no other actions that have a Promoted = true property set. Because then adding an actionref results in a non-compilable solution as you probably know. Then people simply should use Microsofts code actions to do the one-time-conversion first.

Yes, of course. Nice catch! 👍

DavidFeldhoff commented 1 year ago

Oh, thanks for your fast feedback. Much appreciated!

DavidFeldhoff commented 1 year ago

It's released in v1.0.25. Thanks for the suggestion once again, I think that really can come in handy !

jwikman commented 1 year ago

Perfect! I'm pretty sure that this will be used frequently! :)