Skip to content

[OP-20783] Deleting a variant always redirects to the index page - #27083

Open
mrmir wants to merge 10 commits into
release/18.0from
bug/op-20783-deleting-a-variant-always-redirects-to-the-index-page
Open

mrmir wants to merge 10 commits into
release/18.0from
bug/op-20783-deleting-a-variant-always-redirects-to-the-index-page

Conversation

@mrmir

@mrmir mrmir commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Ticket

https://community.openproject.org/wp/OP-20783

What are you trying to accomplish?

  • Ensure deletion of a variant doesn't change the view, keeping collapsed state of the containing section as well as filters if applicable
    • Global types page -> Delete variant -> Stay there
    • Project types page -> Delete variant -> Stay there
    • Variants tab of a type -> Delete variant -> Stay there

What approach did you choose and why?

  • Morph after deletion, making it easier to thread collapsed state and filters through and not change anything except removing the deleted row

AI involvement

Collaborative – AI generated a substantial part of the code; I reviewed and understand every line.

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

@mrmir
mrmir marked this pull request as ready for review November 20, 2026 14:38
@github-actions github-actions Bot added the ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line. label Nov 20, 2026

@dfriquet dfriquet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  • One nitpick about a magic string;
  • One question about URL massaging;
  • And one unexpected behaviour: on the index page, the grouped component is rerendered without taking the filters into account.

Filtered before the deletion

Screenshot of filtered index pre-deletion

Rerendered after the deletion

Does not match is here again.

Screenshot of filtered index post-deletion

{ page: page_param, per_page: per_page_param }
end

def admin_types_migration_filter? = params[:created_by_migration].presence == "t"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Magic "t" would benefit from:

Suggested change
def admin_types_migration_filter? = params[:created_by_migration].presence == "t"
def admin_types_migration_filter? = params[:created_by_migration].presence == WorkPackageTypes::MigrationFilterComponent::MIGRATED

Or maybe some other way to share this "intelligence".

Comment on lines +211 to +225
def deletion_from_variants_tab?
params[:back_url].to_s.start_with?(type_variants_path(type_id: @type.id))
end

# A deletion posts from a paginated/filtered list, but that state travels inside
# back_url. Restore so morphing keeps the same state
def restore_list_view_state
search = params[:back_url].to_s.split("?", 2).second
return if search.blank?

restored = Rack::Utils.parse_nested_query(search)
.slice(*LIST_VIEW_STATE_KEYS)
.select { |_, value| value.is_a?(String) }
params.merge!(restored)
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here is a lot of URL massaging, and I’m usually not a big fan of it. Building in the view, deconstructing in the controller, building something else… I wonder if passing around the whole state would not be better in the end, instead of serializing it in a URL 🤔

I was satisfied with the back_url until now. Tbh, I’m torn.

@mrmir

mrmir commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Rerendered after the deletion

Does not match is here again.

Are there more specific repro steps than just filtering and then deleting one? Because it works fine for me and doesn't show unfiltered options after deletion, but maybe I'm missing something

Make default/remove default still used it. This makes them also morph
based on the passed through params, keeping consistency with the delete
action
@mrmir
mrmir force-pushed the bug/op-20783-deleting-a-variant-always-redirects-to-the-index-page branch from 91c124e to ca03ceb Compare November 25, 2026 15:30
@mrmir

mrmir commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

@dfriquet I went ahead and switched to param passing + morphing for all the relevant variant actions that would have edited the page (deletion + marking/unmarking default) to get rid of the back_url gymnastics. What do you think about this approach?

@github-actions

Copy link
Copy Markdown

Warning

Flaky specs

  • rspec ./modules/backlogs/spec/features/buckets/create_spec.rb[1:1]
🤖 Ask Copilot to investigate

Copy the prompt below into a new comment on this PR to delegate the investigation to GitHub Copilot. It will look into the flakiness and open a separate pull request with you as reviewer.

@copilot The following spec(s) are flaky in CI (first seen on PR #27083, linked for reference only):

- `rspec ./modules/backlogs/spec/features/buckets/create_spec.rb[1:1]`

Treat this as a standalone task, unrelated to PR #27083. Create a new branch from origin/dev and open a new pull request targeting dev — do not stack it on PR #27083 or reuse that branch.

Follow the playbook in docs/development/testing/handling-flaky-tests/README.md to find the root cause and fix the underlying race — do not skip, delete, or weaken the spec to make it pass; disabling is a last resort per the playbook, and only with a bug ticket. Verify the fix by running the spec(s) repeatedly (e.g. `script/bulk_run_rspec --run-count 10`).

If you cannot reproduce the flake or are not confident in a fix after reasonable investigation, do not fabricate a change or skip the spec to force CI green. Instead, leave the pull request in draft and document what you tried, the suspected cause, and any leads in its description, then assign @mrmir to take over.

Once the fix is verified, title the PR after the spec(s) it fixes, and use the PR description to explain the root cause, how the change resolves it, and the before/after results. Label the PR `flaky-spec`, assign @mrmir, and request a review from @mrmir.
On every commit, set @mrmir as the sole co-author with a `Co-authored-by:` trailer (use their GitHub no-reply email so it links to their account), so it is traceable who dispatched the fix.

@dfriquet

Copy link
Copy Markdown
Contributor

Are there more specific repro steps than just filtering and then deleting one?

Yes. The filter only hides some of a type's variants when the query matches variant names but not the type's name. Less specific, the bug also appears with the Migrated filter.

Maybe GIFs can be helpful here, too:

Name filter

Screencast of name filter bug

Migrated filter

Screencast of Migrated filter bug

@dfriquet

Copy link
Copy Markdown
Contributor

I went ahead and switched to param passing + morphing for all the relevant variant actions that would have edited the page (deletion + marking/unmarking default) to get rid of the back_url gymnastics. What do you think about this approach?

Way more explicit, I like it better 👍

I can’t remember if it matches the current behaviour, but Activate comes with the same unexpected (for me) side-effect as the name and Migrated filter: keeping the filter values in the UI but not taking them into account when re-rendering.

Screencast of activation rendering all other types

@dfriquet dfriquet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Apart from the filtering bug I already submitted, this new version LGTM 👍

Let’s hope the fix won’t cause too much trouble.

Comment thread .node-version Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don’t know if it’s up to this PR to update Node 🤷

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Def not, that was a stray. Removed

@mrmir
mrmir force-pushed the bug/op-20783-deleting-a-variant-always-redirects-to-the-index-page branch from 736680e to 6fbd1ce Compare November 26, 2026 17:26
@mrmir
mrmir requested a review from dfriquet November 26, 2026 17:28
@mrmir

mrmir commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

One last time I hope @dfriquet. I wasn't passing those params through properly after the update, but that should hopefully be fixed by the last commit

dfriquet
dfriquet previously approved these changes Nov 27, 2026
Comment on lines +45 to +46
query: params[:query],
created_by_migration: params[:created_by_migration]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Works in my browser 👍

I think I would have added a spec to prevent regressions, but I won’t block a complete bugfix so close to release just for that reason.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai: Collaborative 💻 AI generated a substantial part of the code; A human reviewed and understands every line.

Development

Successfully merging this pull request may close these issues.

2 participants