Skip to content
This repository was archived by the owner on Dec 30, 2022. It is now read-only.

feat(CurrentRefinements): consolidate API #550

Merged
merged 15 commits into from
Oct 18, 2018

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Oct 18, 2018

API of ClearRefinements & CurrentRefinements is consolidated

  1. ClearRefinements has no includedAttributes. This is waiting for v3 of InstantSearch.js and will be added without breaking change
  2. Searchbox: don't display internal value (otherwise you can clear the query but it stays visible)
  3. CurrentRefinements: includedAttributes transparently takes precedence over excludedAttributes.

If you don't want to display specific attributes listed in includedAttributes, don't write them or use transformItems.

This doesn't implement the "merged items" done in InstantSearch.js v3, which will be added later (we can do a major maybe)

@Haroenv Haroenv requested a review from a team October 18, 2018 12:34
return {
transformItems: items =>
items.map(item => {
item.label = item.label.toLocaleUpperCase();
Copy link
Contributor

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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* "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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* "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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* "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"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* "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:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
an Item has the keys:
An item has the keys:

Copy link
Contributor Author

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');
Copy link
Member

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", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Contributor

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', () => {
Copy link
Contributor

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.

@Haroenv Haroenv merged commit 2b08b76 into feat/connectors Oct 18, 2018
@Haroenv Haroenv deleted the feat/current-refinements-2 branch October 18, 2018 16:36
Haroenv added a commit to algolia/instantsearch that referenced this pull request Dec 28, 2022
)

* 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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants