Don't allow a subcategory to be assigned to another subcategory to ensure 1 level of nesting max #1730
Reference in New Issue
Block a user
Delete Branch "fix/1677"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes issue #1677
Overall, agree with the strategy here!
@@ -59,6 +67,14 @@ class CategoriesController < ApplicationController@category = Current.family.categories.find(params[:id])enddef set_categoriesIIRC, we're submitting the category form to the
:_topturbo frame, so I believe this:unprocessable_entitywill cause the background of the modal to go blank on an error.I think we either need to keep the
update!or remove that:_toptarget that was set here so that both success/failure cases render correctly:8256d116ddI think here, we can just have a conditional:
That way, if the user is not allowed to assign a parent, we don't ever give them the option.
@@ -59,6 +67,14 @@ class CategoriesController < ApplicationController@category = Current.family.categories.find(params[:id])enddef set_categoriesThe problem with keeping the
update!is that the user never receives any feedback, which is why I changed it.In the create action, we’re facing the same issue, causing the background to go blank when there is a validation error. That’s why I chose to ignore this issue for now.
Nice, i agree.
@@ -59,6 +67,14 @@ class CategoriesController < ApplicationController@category = Current.family.categories.find(params[:id])enddef set_categoriesAhh you're right, looks like we had a regression in
8256d116ddYou think we could throw in the correct handling for this endpoint (and remove the
:_toptarget introduced in that commit)? Here's an example of how we're doing it for other endpoints:We're essentially using a custom Turbo action to allow us to handle error states directly with streams, but do a full page refresh on success. It helps avoid that "blank screen" issue:
247d91b99d/app/javascript/application.js (L5-L7)@@ -59,6 +67,14 @@ class CategoriesController < ApplicationController@category = Current.family.categories.find(params[:id])enddef set_categoriesI made some changes on 4087275 to handle the turbo_stream form requests. I removed the
:_topturbo target and added aturbo_frame_tagto be replaced by the form partial and render the errors.@@ -59,6 +67,14 @@ class CategoriesController < ApplicationController@category = Current.family.categories.find(params[:id])So we will need the "redirect back or to" logic here since categories can be edited in the modal in many places across the app:
https://github.com/user-attachments/assets/89ac7141-8113-4eb5-ab9e-21689b582a10
Additionally, we should include the
htmlresponse type here as a fallback and for when forms specifyturbo: falseFinally, the
elselogic here should not need to manually replace the form. Turbo automatically handles the 422 and will simply render the instance variables in the existing view. So we should be able to dorender :edit, status: :unprocessable_entityand still get those validations rendering in the modal without closing it.@@ -59,6 +67,14 @@ class CategoriesController < ApplicationController@category = Current.family.categories.find(params[:id])You're right, I made these changes in 2926b84.
I believe it's correct now.
Looks good now. Left one more comment to address, then I think we're good to merge!
@@ -1,7 +1,7 @@<%# locals: (category:, categories:) %>Do we need this? What was the purpose of adding?
@@ -1,7 +1,7 @@<%# locals: (category:, categories:) %>ohhh, i forgot to remove this... it's done in 2c07cd6. ;-)
Looking good! Nice work, thanks for the fix.