-
Notifications
You must be signed in to change notification settings - Fork 157
feat(CurrentRefinements): consolidate API #550
Conversation
query state should always go first, since that way other widgets are able to control the query
return { | ||
transformItems: items => | ||
items.map(item => { | ||
item.label = item.label.toLocaleUpperCase(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer create a new object rather than mutate the value.
* "type": which can be "facet", "exclude", "disjunctive", "hierarchical", "numeric" or "query" | ||
* "attribute": used as the key | ||
* "label": string form of the value | ||
* "value": necessary for the refinement to work correctly, no need to be changed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* "value": necessary for the refinement to work correctly, no need to be changed | |
* `value`: necessary for the refinement to work correctly, no need to be changed |
|
||
* "type": which can be "facet", "exclude", "disjunctive", "hierarchical", "numeric" or "query" | ||
* "attribute": used as the key | ||
* "label": string form of the value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* "label": string form of the value | |
* `label`: string form of the value |
an Item has the keys: | ||
|
||
* "type": which can be "facet", "exclude", "disjunctive", "hierarchical", "numeric" or "query" | ||
* "attribute": used as the key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* "attribute": used as the key | |
* `attribute`: used as the key |
|
||
an Item has the keys: | ||
|
||
* "type": which can be "facet", "exclude", "disjunctive", "hierarchical", "numeric" or "query" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* "type": which can be "facet", "exclude", "disjunctive", "hierarchical", "numeric" or "query" | |
* `type`: which can be "facet", "exclude", "disjunctive", "hierarchical", "numeric" or "query" |
`item` | `{ item: Item, refine: Item => void }` | Override how an item looks | ||
`clearAllLabel` | `{ items: Item[] }` | Override how the "clear all" button looks | ||
|
||
an Item has the keys: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an Item has the keys: | |
An item has the keys: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On purpose, the name of the type is Item
. Will put it in backticks
}); | ||
|
||
const transformItems = items => | ||
items.filter(({ attribute }) => attribute === 'query'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem to test if transformItems
is applied after excludedAttributes
.
A way to effectively test it would be to overwrite the whole content with transformItems
.
); | ||
}); | ||
|
||
it("TransformItems happens after excludedAttributes (so it doesn't include query by default", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it("TransformItems happens after excludedAttributes (so it doesn't include query by default", () => { | |
it("TransformItems happens after excludedAttributes (so it doesn't include query by default)", () => { |
clearsQuery: | ||
this.excludedAttributes.indexOf('query') === -1 && | ||
(this.includedAttributes | ||
? this.includedAttributes.indexOf('query') > -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than > -1
I would go for !== -1
for consistency.
expect(label.text()).toMatch(/Query/); | ||
}); | ||
|
||
it('includedAttributes overrides excludedAttributes 2', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use a more meaningful name for the title of the test.
) * feat(current-refinements): consolidate API * chore(storybook): suppress Vue warning * fix(SearchBox): don't display internal value query state should always go first, since that way other widgets are able to control the query * docs(storybook): fix errors * feat(ClearRefinements): consistent naming * chore(ClearRefinements): lint * Update docs/src/components/ClearRefinements.md * Update docs/src/components/CurrentRefinements.md * Update docs/src/components/CurrentRefinements.md * Update CurrentRefinements.md * test: more focused test on transformItems being last * docs: fix typos & clarify * Update docs/src/components/CurrentRefinements.md * test: change naming * Update CurrentRefinements.vue
API of ClearRefinements & CurrentRefinements is consolidated
includedAttributes
. This is waiting for v3 of InstantSearch.js and will be added without breaking changeincludedAttributes
transparently takes precedence overexcludedAttributes
.If you don't want to display specific attributes listed in
includedAttributes
, don't write them or usetransformItems
.This doesn't implement the "merged items" done in InstantSearch.js v3, which will be added later (we can do a major maybe)