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

[5.x] Run actions from publish forms #6375

Merged
merged 72 commits into from
May 17, 2024

Conversation

jacksleight
Copy link
Contributor

@jacksleight jacksleight commented Jul 25, 2022

This PR allows you to run all actions from the entry, term and user publish forms and the asset editor.

Some implementation details:

  • Because the word "actions" is already taken by the action URLs these actions are referred to as "item actions" in all publish forms, except for the asset editor which already has these actions under "actions".
  • There's a new view key in the action context which will either have a value of list or form. This allows actions to display or behave differently depending on where they’re being used.
  • The form values are synced after actions run using the same approach as Update entry publish form values after saving #6842, but at the moment I've had to duplicate the extractFromFields methods. Maybe they could be refactored so both controllers can use them?
    • I also implemented the value update feature from that PR for terms and users. It just made sense to add those since actions need the same thing.
    • I also noticed that the extractFromFields methods return meta values, but they’re not being passed back to the publish forms after save. I have copied that behaviour for actions, but I think they should be included so that all values display correctly?
  • The title, permalink and actions themselves are also synced after actions run.
  • Things that are already possible from the publish forms are filtered out from the actions menu eg. publish entry, assign user roles, most asset actions.
  • Currently the asset editor closes whenever an action completes, which may not be desirable for all actions, but I didn’t want to mess with that in this PR. This could be looked at in a future PR.
  • This PR does not add actions to form and submission show/edit pages, since they work a bit differently and don’t currently have their own publish form components. This could be looked at in a future PR.
  • I've updated the divider styles so they're hidden if they come first, last or directly after another. This is required to avoid unnecessary dividers in the menu when you don’t have permissions for all options.
  • Entries
  • Terms
  • Assets
  • Users

Closes statamic/ideas#712

@jacksleight jacksleight marked this pull request as draft July 25, 2022 14:20
@what-the-diff
Copy link

what-the-diff bot commented Nov 18, 2022

  • Added a new action to the entry publish form.
  • The list actions are now fetched from an endpoint, instead of being hardcoded in the view file.
  • When running an action on one or more entries, we return some data about those items (e.g., their values). This is used by PublishForm when it's rendered as part of another component (like EntriesIndex) so that it can update its own state with this information after successfully completing an action like "Duplicate".

@jacksleight jacksleight marked this pull request as ready for review November 18, 2022 17:10
@edalzell edalzell marked this pull request as draft January 30, 2023 17:52
@edalzell
Copy link
Contributor

Hey @jacksleight, there's a merge conflict now. If you're still interested in this, can you rebase off 3.4 and resolve?

I've mark this as draft in the meantime.

@jacksleight jacksleight changed the base branch from 3.3 to 3.4 February 1, 2023 11:37
@jacksleight jacksleight marked this pull request as ready for review February 1, 2023 11:44
@jacksleight jacksleight changed the base branch from 3.4 to 4.x May 10, 2023 12:46
@jacksleight jacksleight changed the title Run actions from the edit entry view [4.x] Run actions from the edit entry view May 10, 2023
@what-the-diff
Copy link

what-the-diff bot commented May 10, 2023

PR Summary

  • Added mixin to PublishForm for list actions
    A new mixin is now included in the PublishForm component to enable list actions.

  • Updated EditEntry view with initial data, URL and event listener
    The EditEntry view now has an initial data setup and URL for list actions. An event listener was added to update the state when needed.

  • Enhanced DeleteAction with a redirect method
    The DeleteAction now offers a redirect method to return to the collection listing page when required, improving user experience.

  • Improved DuplicateEntry action for handling multiple items and correct redirection
    DuplicateEntry action now handles multiple items selection better and ensures proper redirection to the correct site when necessary.

@jacksleight jacksleight marked this pull request as draft May 10, 2023 12:49
@jacksleight jacksleight marked this pull request as ready for review May 12, 2023 09:02
@laradevca
Copy link

laradevca commented May 13, 2023

I ended up on this PR while Googling. Just to make sure that I understand, the PR will allow us to run action within an entry? Will it allow us to restrict an action to be run only on 1 entry instead of the list view?

@jacksleight
Copy link
Contributor Author

jacksleight commented May 14, 2023

the PR will allow us to run action within an entry?

Yep.

Will it allow us to restrict an action to be run only on 1 entry instead of the list view?

Yes, within the action's visibleTo() method you could check for the publish_form key in the action context and filter based on that.

@duncanmcclean
Copy link
Member

Would love this one to be merged - just wanted the same thing but for users!

@jacksleight
Copy link
Contributor Author

jacksleight commented Aug 26, 2023

Yeah I think it'd be a nice feature to have. At the moment this PR only covers entries, the intention is to add the other types as well but there are a few implementation details I'm not too sure about right now.

@jasonvarga jasonvarga marked this pull request as draft September 5, 2023 20:32
@jasonvarga
Copy link
Member

Isn't naming tough?

The entry edit view is using the same InlineActions component as the listing page uses, but its own HasListActions mixin.

I'd just call it HasActions too. The existing one is in the data-list directory and the new one is in the publish directory.

Because the word “actions” is already taken by the publish actions I’ve used “list actions” for these new properties (because they’re copied from the listing page). There’s probably a better name.

Naming it just actions makes the most sense, but I don't want you to have to mess with the existing stuff all over the place. Let's call them item actions instead of list actions. Yes they're copied from the listings but on the publish form that doesn't really makes sense IMO.

I’ve included a new publish_form key in the action context which allows actions to behave differently if they’re being run from the form. This is used by the delete and duplicate actions to redirect elsewhere after the action runs.

Can we have a view key with a form value instead?

This could happen if the state of the entry causes different actions to be available.
For example when its published, the unpublished action is visible but not the publish action, and visa versa.
…o be consistent with saving. Maybe third party actions will.
When the form is dirty, a warning will be shown.

The message will be generic, unless overridden on the action, like the Duplicate action is doing.

Actions can opt out of the dirty state navigate-away dialog, like the Delete action is doing. In those cases, the warning won't be shown either.
@jasonvarga jasonvarga merged commit d7809ab into statamic:5.x May 17, 2024
16 checks passed
duncanmcclean added a commit to statamic-rad-pack/runway that referenced this pull request May 20, 2024
Because that's the release statamic/cms#6375 is included in.
duncanmcclean added a commit to statamic-rad-pack/runway that referenced this pull request May 20, 2024
* Refactor extracting values & field meta into trait

* Add actions dropdown to publish form

* Update delete & duplicate actions to support publish form actions

* Fix test

The `values` key now returns an array, instead of a collection.

* Fix styling

* Title on publish form should be the resource's title field

* we don't have revisions, so we don't need this

* Require Statamic 5.3.0

Because that's the release statamic/cms#6375 is included in.

---------

Co-authored-by: duncanmcclean <duncanmcclean@users.noreply.github.com>
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.

Show actions in the single entry view.
6 participants