blacklight icon indicating copy to clipboard operation
blacklight copied to clipboard

It's difficult to override a method in FacetItemComponent globally

Open sandbergja opened this issue 2 years ago • 0 comments

User story

As a developer, I would like to make a small customization to the "x" remove icon button in all facets.

Current options

When I tried to do this for my app, I considered a few options, none of which seem very satisfactory:

  1. I could create a custom component that inherits from FacetItemComponent. Then, every time I call config.add_facet_field in my catalog controller, I could add item_component: MyCustomItemComponent. The downside is that my app has 77 lines like this; it would be easy to miss one and end up with an inconsistent display.
  2. I could copy the entire contents of FacetItemComponent into place at my app's app/components/blacklight/facet_item_component.rb. But this seems excessive, since I only want to override a single method.

Proposal

For this particular use case, it would be convenient to have a configuration option, so I could set something like this in the catalog controller:

config.default_facet_item_component = MyCustomItemComponent

And still allow individual FacetFields to override the default.

But, I could also be missing something, or maybe we could come up with a better API that would enable this use case -- feedback very welcome.

sandbergja avatar Feb 24 '23 01:02 sandbergja