algolia / instantsearch

⚡️ Libraries for building performant and instant search and recommend experiences with Algolia. Compatible with JavaScript, TypeScript, React and Vue.
https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/
MIT License
3.72k stars 522 forks source link

connectCurrentRefinements doesn't provide enough information on hierarchical menu #3085

Closed Haroenv closed 3 years ago

Haroenv commented 6 years ago
{
  "type": "hierarchical",
  "attributeName": "hierarchicalCategories.lvl0",
  "name": "Cell Phone Accessories",
  "count": 50,
  "computedLabel": "Cell Phone Accessories"
}

Here I can't make a breadcrumb (note that what I refined was at lvl1, not lvl0).

I can't simply use the breadcrumb component either, since I don't have the same levels available, and a menu also uses type: hierarchical

bobylito commented 6 years ago

Can you add more info @Haroenv? Have you checked the implementations in instantsearch.js and in angular?

Haroenv commented 6 years ago

In InstantSearch.js and Angular we don't follow InstantSearch.css, we only show the "computed label", which doesn't include the attribute name.

Compare React InstantSearch (correct): https://community.algolia.com/react-instantsearch/storybook/?selectedKind=CurrentRefinements&selectedStory=with%20HierarchicalMenu&full=0&addons=1&stories=1&panelRight=1&addonPanel=storybooks%2Fstorybook-addon-knobs

to InstantSearch.js (missing attribute): https://community.algolia.com/instantsearch.js/v2/dev-novel/?selectedStory=CurrentRefinedValues.with%20clearsQuery

the InstantSearch.js example doesn't have a HierarchicalMenu, but the problem is already clear without

Haroenv commented 6 years ago

Here's a better example of InstantSearch.js's behaviour with hierarchical menus: https://codesandbox.io/s/k3zovlx2v5

Note that with the data given in the connector (posted in OP), you can't make the same behaviour as React InstantSearch

bobylito commented 6 years ago

It's a limitation of the current design of InstantSearch.js. The values are that the currentRefinements get are from the search state (helper) which does not contain any information about the widget that defined it.

A better way to handle that is to be able to retrieve the UI state from all the widgets without any filters from the user. We could that by moving this method to the instantsearch instance and then make the RoutingManager use it as well as the currentRefinements widget.

With that you are able to implement a generic "template" that can work with all the default widgets.

Did I miss something? Would that be enough information?

francoischalifour commented 5 years ago

Is your issue solved with InstantSearch.js 3, @Haroenv?

Haroenv commented 5 years ago

The label is no longer computed, meaning you get a whole "breadcrumb", but I don't think this is fully solved, because it doesn't list the other levels so you can't unrefine to a particular level.

I think the issue is a lot smaller now than it used to be when I opened this issue.

see Vue Storybook: https://vue-instantsearch.netlify.com/stories/?selectedKind=ais-current-refinements&selectedStory=with%20multiple%20refinements%20to%20clear&full=0&addons=1&stories=1&panelRight=1&addonPanel=storybooks%2Fstorybook-addon-knobs

Haroenv commented 3 years ago

Changed my mind as nobody asked for a breadcrumb inside current refinements, that's solved with using a separate breadcrumb.

Current refinements indeed now includes the attribute in the rendering, which solves most of this initial issue