-
Notifications
You must be signed in to change notification settings - Fork 42
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
base: develop
Are you sure you want to change the base?
Conversation
init_params/1
callback to item actionsinit_params/1
callback for item actions
|
||
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable!
|
||
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable!
No description provided.