Skip to content

Create select_taxons admin form component - #6653

Open
benjaminwil wants to merge 3 commits into
solidusio:mainfrom
benjaminwil:product-taxon-select-component
Open

benjaminwil wants to merge 3 commits into
solidusio:mainfrom
benjaminwil:product-taxon-select-component

Conversation

@benjaminwil

@benjaminwil benjaminwil commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request creates a bespoke component for selecting taxons from a list of all of a store's taxons. This resolves #6643.

It also starts using the new component in two existing templates.

A screenshot showing four variants of the taxon select component: single select, single select with pre-filled options, multi-select, and multi-select with pre-filled options

Checklist

Check out our PR guidelines for more details.

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

Footnotes

  1. There is a JavaScript console error hard-coded in English. The intended audience is developers, though, not customers. ↩

@codecov

codecov Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (6f5b2b9) to head (3b7d2fa).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6653   +/-   ##
=======================================
  Coverage   92.47%   92.48%           
=======================================
  Files        1065     1066    +1     
  Lines       21541    21555   +14     
=======================================
+ Hits        19921    19935   +14     
  Misses       1620     1620           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch 10 times, most recently from 2899eff to d23c1f4 Compare September 29, 2026 23:04
@benjaminwil
benjaminwil marked this pull request as ready for review September 30, 2026 01:49
@benjaminwil
benjaminwil requested a review from a team as a code owner September 30, 2026 01:49

@tvdeyen tvdeyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should use the configured routes by using the routes helpers we have available in components, via the helpers proxy.

@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch 2 times, most recently from d23c1f4 to c77f9c6 Compare September 30, 2026 15:25
@benjaminwil
benjaminwil requested a review from tvdeyen September 30, 2026 15:26
@benjaminwil

Copy link
Copy Markdown
Contributor Author

I still think this is worth reviewing right now, but I have to go back and re-evaluate the tests due to timing issues.

There are indications that the remote data is not being loaded fast enough for the feature tests to fail. We're not waiting in quite the right ways.

@tvdeyen tvdeyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good.

<%= render component("ui/forms/field").select_taxons f,
:parent_id,
include_blank: t(".none"),
multiple: false %>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be the default anyway, no?

Suggested change
multiple: false %>
%>

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.

From a data perspective, I thought that multiple: true makes sense as a default. Since you'd almost always want a collection of taxons to be associated with something.

But maybe from a developer experience perspective you're more correct.

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.

@tvdeyen @jarednorman I don't feel strongly about this, but I've left it with a multiple: true default for now. This felt like the natural thing to do, due to the method name (.select_taxons plural).

If you all feel strongly in the other direction, I can change this.

@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch from c77f9c6 to f808334 Compare October 1, 2026 18:55
@benjaminwil

Copy link
Copy Markdown
Contributor Author

There are indications that the remote data is not being loaded fast enough for the feature tests to fail. We're not waiting in quite the right ways.

I was wrong. The issue was that using URL helpers via SolidusAdmin::Engine needed to be explicitly configured for the test environment. I have added a commit that does this.

errors:,
label:,
multiple: true,
src: SolidusAdmin::Engine.routes.url_helpers.pretty_names_taxons_url,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my local testing this still caused issues outside of tests because the host wasn't set because this doesn't have a request context, but this complicates the JS.

What if we just add a taxon select component that renders our select component from the view layer and avoids all of this complexity.

@benjaminwil benjaminwil Oct 4, 2026 •

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.

I'm not opposed to doing it that way.

But maybe it's worth discussing more? I feel like all of this is pointing to the fact that it's not easy enough to create select components that use remote data sources. Do we want to (and do we want application developers to) have to write view partials every time we (they) want a mildly complex select component in the admin interface?

I think the complexity is reasonably reduced if we can pass paths (rather than URLs) to the solidus_select.js we've built on top of Tom Select.

cc @tvdeyen

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't have a strong preference either way. If accepting paths makes stuff easier and is reasonably easy to do, that approach has my blessing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes. What Jared says.

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.

@jarednorman @tvdeyen I added a new commit that tackles this issue by allowing the use of path helpers.

I chose this route because:

  1. Currently the component is just a class method on the Form::Field::Component, so there would be some indirection and a lot more code to make a new component and component template. (Said another way: less code this way.)
  2. I think I was able to offset the complexity of getting URLs in a reasonable way, after all. See the Apply host URL to solidus_select data-srcs commit.

Let me know what y'all think.

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.

Jared located the real issue with paths, which was actually a missing fallback URL in the Tom Select remote_with_pagination plugin code. So I think that makes a lot of the issues we were discussing go away. 👍

@benjaminwil
benjaminwil requested a review from tvdeyen October 7, 2026 15:45
@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch from f808334 to 98bfa7d Compare October 22, 2026 21:20
@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch from 98bfa7d to f880d3d Compare October 22, 2026 22:01
@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch 2 times, most recently from 4345aad to 5695a07 Compare October 22, 2026 22:08

@jarednorman jarednorman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's a race condition in admin/lib/solidus_admin/testing_support/feature_helpers.rb#51-58 that I think needs fixing as part of this.

@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch 2 times, most recently from d9e4f7b to e0f7d56 Compare October 23, 2026 17:20
@benjaminwil benjaminwil changed the title Create #select_taxons admin form component Create select_taxons admin form component Oct 23, 2026
@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch from e0f7d56 to 4927e78 Compare October 23, 2026 18:45
@benjaminwil

Copy link
Copy Markdown
Contributor Author

Just rebased against main to resolve conflicts after #6654 was merged.

Comment thread admin/config/routes.rb Resolved
@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch from 4927e78 to 98aa43a Compare October 27, 2026 23:38

@jarednorman jarednorman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like the choice to skip auth. We need a pattern to handle routes like this properly. Just because it's safe here and now doesn't mean someone isn't going to customize these endpoints expecting them to be limited to admins.

benjaminwil and others added 3 commits November 2, 2026 16:12
This better handles options that are loaded from a remote data source
URL.

A CI/CD timing-related failure indicated that this code was required.
We want to create a reusable taxon select component for a couple of
reasons:

1. It is too error-prone to create this by hand.
2. We want to be able to create consistent functionality where ever
   there is a taxon select required. This means always using the
   `#pretty_name` method  and having shared code to load and present a
   list of taxons.

As you can see from the diff, this commit allows us to delete some
duplicated and kinda weird code for creating bespoke taxon select
components.
The custom Solidus Select web component did not support relative URLs
as remote data sources passed to `data-src`. This is because the
underlying select library, Tom Select, only allows absolute, fully-
qualified URLs to be used as remote data sources.

Co-Authored-By: Jared Norman <jared@super.gd>
@benjaminwil
benjaminwil force-pushed the product-taxon-select-component branch from 26065d4 to 3b7d2fa Compare November 3, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Create TaxonSelect component for the new admin

3 participants