Skip to content

Commit

Permalink
feat(autocomplete): provide indexId (#4142)
Browse files Browse the repository at this point in the history
This PR adds the `indexId` attribute to the `indices` provided by `autocomplete`.

Only the `indexName` was provided but its value is not stable. The value changes when the index changes e.g. with `sortBy`. A possible use case for stable value is a list of labels. Users might want to have labels on their indices. Without stable values, you can't predict which label you'll have.  The `indexId` solve this problem.
  • Loading branch information
samouss committed Sep 25, 2019
1 parent ce2ef56 commit 443cb06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/connectors/autocomplete/__tests__/connectAutocomplete-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,20 @@ search.addWidgets([
const secondIndexHits = [{ name: 'Hit 1' }, { name: 'Hit 2' }];
const scopedResults = [
{
indexId: 'index0',
indexId: 'indexId0',
results: new SearchResults(helper.state, [
createSingleSearchResponse({
index: 'index0',
index: 'indexName0',
hits: firstIndexHits,
}),
]),
helper,
},
{
indexId: 'index1',
indexId: 'indexId1',
results: new SearchResults(helper.state, [
createSingleSearchResponse({
index: 'index1',
index: 'indexName1',
hits: secondIndexHits,
}),
]),
Expand All @@ -183,13 +183,15 @@ search.addWidgets([

expect(render).toHaveBeenCalledTimes(2);
expect(secondRenderOptions.indices).toHaveLength(2);
expect(secondRenderOptions.indices[0].indexName).toEqual('index0');
expect(secondRenderOptions.indices[0].indexId).toEqual('indexId0');
expect(secondRenderOptions.indices[0].indexName).toEqual('indexName0');
expect(secondRenderOptions.indices[0].hits).toEqual(firstIndexHits);
expect(secondRenderOptions.indices[0].results.index).toEqual('index0');
expect(secondRenderOptions.indices[0].results.index).toEqual('indexName0');
expect(secondRenderOptions.indices[0].results.hits).toEqual(firstIndexHits);
expect(secondRenderOptions.indices[1].indexName).toEqual('index1');
expect(secondRenderOptions.indices[1].indexId).toEqual('indexId1');
expect(secondRenderOptions.indices[1].indexName).toEqual('indexName1');
expect(secondRenderOptions.indices[1].hits).toEqual(secondIndexHits);
expect(secondRenderOptions.indices[1].results.index).toEqual('index1');
expect(secondRenderOptions.indices[1].results.index).toEqual('indexName1');
expect(secondRenderOptions.indices[1].results.hits).toEqual(
secondIndexHits
);
Expand Down
1 change: 1 addition & 0 deletions src/connectors/autocomplete/connectAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ search.addWidgets([
: scopedResult.results.hits;

return {
indexId: scopedResult.indexId,
indexName: scopedResult.results.index,
hits: scopedResult.results.hits,
results: scopedResult.results,
Expand Down

0 comments on commit 443cb06

Please sign in to comment.