Skip to content

Commit 24d9ded

Browse files
author
Eunjae Lee
authoredMar 30, 2021
feat(relevantSort): implement canRefine (#4693)
* feat(relevantSort): implement canRefine * fix canRefine and the test cases
1 parent 0f5d688 commit 24d9ded

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎src/connectors/relevant-sort/__tests__/connectRelevantSort-test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ describe('connectRelevantSort', () => {
172172
expect(renderState1.relevantSort).toEqual({
173173
isRelevantSorted: false,
174174
isVirtualReplica: false,
175+
canRefine: false,
175176
refine: expect.any(Function),
176177
widgetParams: {},
177178
});
@@ -192,6 +193,7 @@ describe('connectRelevantSort', () => {
192193
expect(renderState2.relevantSort).toEqual({
193194
isRelevantSorted: true,
194195
isVirtualReplica: true,
196+
canRefine: true,
195197
refine: expect.any(Function),
196198
widgetParams: {},
197199
});
@@ -210,6 +212,7 @@ describe('connectRelevantSort', () => {
210212
expect(widgetRenderState1).toEqual({
211213
isRelevantSorted: false,
212214
isVirtualReplica: false,
215+
canRefine: false,
213216
refine: expect.any(Function),
214217
widgetParams: {},
215218
});
@@ -229,6 +232,7 @@ describe('connectRelevantSort', () => {
229232
expect(widgetRenderState2).toEqual({
230233
isRelevantSorted: true,
231234
isVirtualReplica: true,
235+
canRefine: true,
232236
refine: expect.any(Function),
233237
widgetParams: {},
234238
});

‎src/connectors/relevant-sort/connectRelevantSort.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,24 @@ export type RelevantSortConnectorParams = Record<string, unknown>;
66
type Refine = (relevancyStrictness: number) => void;
77

88
export type RelevantSortRendererOptions = {
9+
/**
10+
* Indicates if it has appliedRelevancyStrictness greater than zero
11+
*/
912
isRelevantSorted: boolean;
13+
14+
/**
15+
* Indicates if the results come from a virtual replica
16+
*/
1017
isVirtualReplica: boolean;
18+
19+
/**
20+
* Indicates if search state can be refined
21+
*/
22+
canRefine: boolean;
23+
24+
/**
25+
* Sets the value as relevancyStrictness and trigger a new search
26+
*/
1127
refine: Refine;
1228
};
1329

@@ -77,11 +93,14 @@ const connectRelevantSort: RelevantSortConnector = function connectRelevantSort(
7793

7894
const { appliedRelevancyStrictness } = results || {};
7995

96+
const isVirtualReplica = appliedRelevancyStrictness !== undefined;
97+
8098
return {
8199
isRelevantSorted:
82100
typeof appliedRelevancyStrictness !== 'undefined' &&
83101
appliedRelevancyStrictness > 0,
84-
isVirtualReplica: appliedRelevancyStrictness !== undefined,
102+
isVirtualReplica,
103+
canRefine: isVirtualReplica,
85104
refine: connectorState.refine,
86105
widgetParams,
87106
};

0 commit comments

Comments
 (0)
Please sign in to comment.