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

fix: destroy when using forms and display fields API #2415

Merged
merged 7 commits into from Jan 29, 2024

Conversation

Paul-Bob
Copy link
Contributor

@Paul-Bob Paul-Bob commented Jan 26, 2024

Description

Fixes #2403

The detach button request has been updated to no longer hydrate the resource using the destroy view, as it was identified as a problematic approach when using def display_fields or def form_fields API since those methods wouldn't get called.

To address this, we have modified the process to include passing the current view as parameters during the detach request. This ensures that the appropriate view is properly hydrated into the resource.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

Before

before.webm

After

after.webm

Manual review steps

  1. Set a resource with an association field using only def display_fields and def form_fields API
  2. Visit resource's show view
  3. Detach a record from the association field
  4. Before was raising error, notice that now it works.

@Paul-Bob Paul-Bob added the Fix label Jan 26, 2024
@Paul-Bob Paul-Bob self-assigned this Jan 26, 2024
Copy link

codeclimate bot commented Jan 26, 2024

Code Climate has analyzed commit 9590f39 and detected 0 issues on this pull request.

View more on Code Climate.

Comment on lines 124 to 130
# Get view from params unless actions is index or show or forms...
# Else, for example for detach action we want the view from params to can fetch the correct fields
view = if action_view.in?([:index, :show, :new, :edit, :create])
action_view
else
params[:view] || action_view
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic avoid the following scenario:

When a has many field is rendered the action is index and params[:view] is show or edit but we want to keep @view as index for the related_resource

Same do not happen with other actions except the list on L126

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this as a comment in the code so we know why it's there.

Comment on lines 124 to 130
# Get view from params unless actions is index or show or forms...
# Else, for example for detach action we want the view from params to can fetch the correct fields
view = if action_view.in?([:index, :show, :new, :edit, :create])
action_view
else
params[:view] || action_view
end
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please add this as a comment in the code so we know why it's there.

@Paul-Bob Paul-Bob merged commit ff357bc into main Jan 29, 2024
13 of 21 checks passed
@Paul-Bob Paul-Bob deleted the fix/destroy_when_using_forms_and_display_fields branch January 29, 2024 09:04
Copy link
Contributor

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

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

Successfully merging this pull request may close these issues.

def display_fields / form_fields do not cover detach
2 participants