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

Add init_params/1 callback for item actions #673

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Flo0807
Copy link
Collaborator

@Flo0807 Flo0807 commented Nov 26, 2024

No description provided.

@Flo0807 Flo0807 added the feature New feature label Nov 26, 2024
@Flo0807 Flo0807 self-assigned this Nov 26, 2024
@Flo0807 Flo0807 changed the title Add init_params/1 callback to item actions Add init_params/1 callback for item actions Nov 26, 2024
@Flo0807 Flo0807 marked this pull request as draft November 27, 2024 07:20

changeset_function = &action.module.changeset/3

metadata = Resource.build_changeset_metadata(socket.assigns)

changeset = changeset_function.(base_item, %{}, metadata)
changeset = changeset_function.(base_item, init_params, metadata)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pehbehbeh We should combine this with the default values users can define for fields. Currently, we do not use these values in Item Actions (we do in Resource Actions: see https://github.com/naymspace/backpex/blob/develop/lib/backpex/live_resource.ex#L794)

What are your thoughts on using the init_params if defined and otherwise the default values (same for resource actions)?

Something like this:

init_params = action.module.init_params(socket.assigns) || build_default_params

If both init_params and "default" field values are not present an empty map is being used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable!

Base automatically changed from feature/rename-item-action-init-change-callback to develop November 27, 2024 10:21

changeset_function = &action.module.changeset/3

metadata = Resource.build_changeset_metadata(socket.assigns)

changeset = changeset_function.(base_item, %{}, metadata)
changeset = changeset_function.(base_item, init_params, metadata)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants