Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e9e5bce

Browse filesBrowse files
authored
fix(SF-979): Fix sort type, make withoutSorts check ByIdSorts, add originalRequest to response type (#85)
1 parent 77cfa37 commit e9e5bce
Copy full SHA for e9e5bce

4 files changed

+92-76Lines changed: 92 additions & 76 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/core/query.ts‎

Copy file name to clipboardExpand all lines: src/core/query.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as qs from 'qs';
55
import {
66
Biasing,
77
CustomUrlParam,
8+
FieldSort,
89
MatchStrategy,
910
Request,
1011
RestrictNavigation,
@@ -112,7 +113,11 @@ export class Query {
112113
}
113114

114115
withoutSorts(...sorts: Sort[]): Query {
115-
this.request.sort = this.request.sort.filter((oldSort) => !sorts.find((sort) => sort.field === oldSort.field));
116+
this.request.sort = this.request.sort.filter((oldSort) => !sorts.find((sort) =>
117+
sort.type === 'ByIds'
118+
? oldSort.type === 'ByIds' && sort.ids.toString() === oldSort.ids.toString()
119+
: sort.field === (<FieldSort>oldSort).field
120+
));
116121
return this;
117122
}
118123

Collapse file

‎src/models/request.ts‎

Copy file name to clipboardExpand all lines: src/models/request.ts
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,20 @@ export interface Request {
3434
wildcardSearchEnabled: boolean;
3535
}
3636

37-
export namespace Sort {
38-
export type Type = 'ByIds' | 'Field';
37+
export type Sort = FieldSort | ByIdSort;
38+
39+
export interface BaseSort {
40+
order?: SortOrder;
41+
}
42+
43+
export interface ByIdSort extends BaseSort {
44+
type: 'ByIds';
45+
ids: string[];
3946
}
4047

41-
export interface Sort {
42-
type: Sort.Type;
43-
ids?: string[];
44-
field?: string;
45-
order?: SortOrder;
48+
export interface FieldSort extends BaseSort {
49+
type?: 'Field';
50+
field: string;
4651
}
4752

4853
export interface CustomUrlParam {
Collapse file

‎src/models/response.ts‎

Copy file name to clipboardExpand all lines: src/models/response.ts
+63-62Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,115 +2,116 @@ export type SortType = 'Count_Ascending' | 'Count_Descending' | 'Value_Ascending
22

33
export interface Results {
44

5-
id: string;
5+
id: string;
66

7-
query: string;
8-
originalQuery: string;
9-
correctedQuery: string;
7+
query: string;
8+
originalQuery: string;
9+
correctedQuery: string;
1010

11-
area: string;
12-
biasingProfile: string;
13-
redirect: string;
11+
area: string;
12+
biasingProfile: string;
13+
redirect: string;
1414

15-
template: Template;
16-
pageInfo: PageInfo;
15+
template: Template;
16+
pageInfo: PageInfo;
1717

18-
totalRecordCount: number;
19-
records: Record[];
18+
totalRecordCount: number;
19+
records: Record[];
2020

21-
availableNavigation: Navigation[];
22-
selectedNavigation: Navigation[];
23-
didYouMean: string[];
24-
relatedQueries: string[];
25-
rewrites: string[];
21+
availableNavigation: Navigation[];
22+
selectedNavigation: Navigation[];
23+
didYouMean: string[];
24+
relatedQueries: string[];
25+
rewrites: string[];
2626

27-
errors: string;
28-
warnings: string[];
29-
debugInfo: DebugInfo;
27+
errors: string;
28+
warnings: string[];
29+
debugInfo: DebugInfo;
30+
originalRequest: Request;
3031
}
3132

3233
export interface Template {
33-
name: string;
34-
ruleName: string;
35-
zones: { [name: string]: Zone };
34+
name: string;
35+
ruleName: string;
36+
zones: { [name: string]: Zone };
3637
}
3738

3839
export interface PageInfo {
39-
recordStart: number;
40-
recordEnd: number;
40+
recordStart: number;
41+
recordEnd: number;
4142
}
4243

4344
export interface DebugInfo {
44-
rawRequest: any;
45-
rawResponse: any;
46-
rawAggregationsRequest: any;
47-
rawAggregationsResponse: any;
45+
rawRequest: any;
46+
rawResponse: any;
47+
rawAggregationsRequest: any;
48+
rawAggregationsResponse: any;
4849
}
4950

5051
export interface Record {
51-
id: string;
52-
url: string;
53-
title: string;
54-
allMeta: any;
55-
collection: string;
56-
snippet?: string;
52+
id: string;
53+
url: string;
54+
title: string;
55+
allMeta: any;
56+
collection: string;
57+
snippet?: string;
5758
}
5859

5960
export interface Navigation {
60-
name: string;
61-
displayName: string;
62-
type: 'Value' | 'Range';
63-
refinements: Refinement[];
64-
metadata: any[];
65-
range?: boolean;
66-
max?: number;
67-
min?: number;
68-
or?: boolean;
69-
moreRefinements?: boolean;
70-
ignored?: boolean;
71-
sort?: SortType;
61+
name: string;
62+
displayName: string;
63+
type: 'Value' | 'Range';
64+
refinements: Refinement[];
65+
metadata: any[];
66+
range?: boolean;
67+
max?: number;
68+
min?: number;
69+
or?: boolean;
70+
moreRefinements?: boolean;
71+
ignored?: boolean;
72+
sort?: SortType;
7273
}
7374

7475
export interface BaseRefinement {
75-
count: number;
76-
exclude?: boolean;
76+
count: number;
77+
exclude?: boolean;
7778
}
7879

7980
export interface ValueRefinement extends BaseRefinement {
80-
type: 'Value';
81-
value: string;
81+
type: 'Value';
82+
value: string;
8283
}
8384

8485
export interface RangeRefinement extends BaseRefinement {
85-
type: 'Range';
86-
low: number;
87-
high: number;
86+
type: 'Range';
87+
low: number;
88+
high: number;
8889
}
8990

9091
export type Refinement = ValueRefinement | RangeRefinement;
9192

9293
export interface RefinementResults {
93-
navigation: Navigation;
94+
navigation: Navigation;
9495
}
9596

9697
export type Zone = ContentZone | RichContentZone | RecordZone;
9798

9899
export interface BaseZone {
99-
name: string;
100+
name: string;
100101
}
101102

102103
export interface ContentZone extends BaseZone {
103-
type: 'Content';
104-
content: string;
104+
type: 'Content';
105+
content: string;
105106
}
106107

107108
export interface RichContentZone extends BaseZone {
108-
type: 'Rich_Content';
109-
richContent: string;
109+
type: 'Rich_Content';
110+
richContent: string;
110111
}
111112

112113
export interface RecordZone extends BaseZone {
113-
type: 'Record';
114-
query: string;
115-
records: Record[];
114+
type: 'Record';
115+
query: string;
116+
records: Record[];
116117
}
Collapse file

‎test/unit/core/query.ts‎

Copy file name to clipboardExpand all lines: test/unit/core/query.ts
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Query } from '../../../src/core/query';
2-
import { SelectedValueRefinement } from '../../../src/models/request';
2+
import { ByIdSort, FieldSort, SelectedValueRefinement } from '../../../src/models/request';
33
import suite from '../_suite';
44
import { COMBINED_REFINEMENTS, COMPLEX_REQUEST, CUSTOM_PARAMS_FROM_STRING } from '../fixtures';
55

@@ -223,12 +223,17 @@ suite('Query', ({ expect }) => {
223223
it('should allow sorts to be unselected', () => {
224224
query.withQuery('')
225225
.withSorts({ type: 'Field', field: 'this', order: 'Ascending' },
226-
{ type: 'Field', field: 'that', order: 'Descending' });
227-
expect(query.raw.sort.length).to.eq(2);
226+
{ type: 'Field', field: 'that', order: 'Descending' },
227+
{ type: 'ByIds', ids: ['1', '2', '3'] }
228+
);
229+
expect(query.raw.sort.length).to.eq(3);
228230
query.withoutSorts({ type: 'Field', field: 'that', order: 'Ascending' });
229-
expect(query.raw.sort.length).to.eq(1);
230-
expect(query.raw.sort[0].field).to.eq('this');
231+
expect(query.raw.sort.length).to.eq(2);
232+
expect((<FieldSort>query.raw.sort[0]).field).to.eq('this');
231233
query.withoutSorts({ type: 'Field', field: 'this', order: 'Ascending' });
234+
expect(query.raw.sort.length).to.eq(1);
235+
expect((<ByIdSort>query.raw.sort[0]).ids).to.eql(['1', '2', '3']);
236+
query.withoutSorts({ type: 'ByIds', ids: ['1', '2', '3'] });
232237
expect(query.raw.sort.length).to.eq(0);
233238
});
234239

@@ -239,7 +244,7 @@ suite('Query', ({ expect }) => {
239244
expect(query.raw.sort.length).to.eq(2);
240245
query.withoutSorts({ type: 'Field', field: 'that', order: 'Ascending' });
241246
expect(query.raw.sort.length).to.eq(1);
242-
expect(query.raw.sort[0].field).to.eq('this');
247+
expect((<FieldSort>query.raw.sort[0]).field).to.eq('this');
243248
query.withoutSorts({ type: 'Field', field: 'this', order: 'Ascending' });
244249
expect(query.raw.sort.length).to.eq(0);
245250
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.