@fluid-topics/ft-search-context 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,6 +19,7 @@ export declare class FtSearchStateManager {
19
19
  initService(): Promise<boolean>;
20
20
  setQuery(query: string): void;
21
21
  setContentLocale(contentLocale?: string): string | undefined;
22
+ forceContentLocale(contentLocale?: string): void;
22
23
  setPageSize(pageSize: number): void;
23
24
  setPageNumber(pageNumber: number): void;
24
25
  setSort(sort: FtSearchSortCriterion[]): void;
@@ -23,6 +23,11 @@ export class FtSearchStateManager {
23
23
  this.searchDebouncer = new Debouncer(100);
24
24
  this.suggestDebouncer = new Debouncer(300);
25
25
  this.service = service !== null && service !== void 0 ? service : new FtSearchService();
26
+ this.service.cache.addEventListener("clear-cache", (e) => {
27
+ if (e.detail.clearedKeys.includes("available-locales")) {
28
+ this.updateLocales();
29
+ }
30
+ });
26
31
  }
27
32
  async initService() {
28
33
  this.updateLocales();
@@ -30,15 +35,16 @@ export class FtSearchStateManager {
30
35
  }
31
36
  setQuery(query) {
32
37
  this.store.actions.setRequestQuery(query);
33
- this.store.actions.setLiveQuery(query);
38
+ this.store.actions.liveQuery(query);
34
39
  this.store.actions.setPageNumber(1);
35
40
  this.launchSearch();
36
41
  }
37
42
  setContentLocale(contentLocale) {
38
- let locales = this.store.getState().locales;
43
+ var _a;
44
+ let locales = (_a = this.store.getState().locales) !== null && _a !== void 0 ? _a : [];
39
45
  let previousContentLocale = this.store.getState().request.contentLocale;
40
46
  if (contentLocale != previousContentLocale) {
41
- if (locales) {
47
+ if (locales.length > 0) {
42
48
  const isKnown = (locale) => locales.some(l => l.lang == locale);
43
49
  if (!isKnown(contentLocale)) {
44
50
  contentLocale = isKnown(previousContentLocale) ? previousContentLocale : locales[0].lang;
@@ -51,6 +57,10 @@ export class FtSearchStateManager {
51
57
  }
52
58
  return contentLocale;
53
59
  }
60
+ forceContentLocale(contentLocale) {
61
+ this.store.actions.setRequestContentLocale(contentLocale);
62
+ this.launchSearch();
63
+ }
54
64
  setPageSize(pageSize) {
55
65
  this.store.actions.setPageSize(pageSize);
56
66
  this.launchSearch();
@@ -68,11 +78,6 @@ export class FtSearchStateManager {
68
78
  const cleanFilters = filters.filter(f => !f.valueFilter || f.valueFilter.values.length > 0);
69
79
  this.store.actions.setRequestFilters(cleanFilters);
70
80
  this.store.actions.setPageNumber(1);
71
- cleanFilters.forEach(f => {
72
- if (!this.facetIds.includes(f.key)) {
73
- this.facetIds = [...this.facetIds, f.key];
74
- }
75
- });
76
81
  this.launchSearch();
77
82
  }
78
83
  setClusterSortCriterion(criterions) {
@@ -100,7 +105,7 @@ export class FtSearchStateManager {
100
105
  // Used in GWT
101
106
  clearAllFilters() {
102
107
  this.setFilters([]);
103
- this.store.eventBus.dispatchEvent(new ClearAllFiltersEvent());
108
+ this.store.dispatchEvent(new ClearAllFiltersEvent());
104
109
  }
105
110
  addFacet(id) {
106
111
  this.facetIds = [...this.facetIds, id];
@@ -115,7 +120,14 @@ export class FtSearchStateManager {
115
120
  this.launchSearch();
116
121
  }
117
122
  get facetIds() {
118
- return this.store.getState().request.facets.map(f => f.id);
123
+ var _a;
124
+ const request = this.store.getState().request;
125
+ return [
126
+ ...new Set([
127
+ ...request.facets.map(f => f.id),
128
+ ...((_a = request.metadataFilters) !== null && _a !== void 0 ? _a : []).map(f => f.key),
129
+ ])
130
+ ];
119
131
  }
120
132
  set facetIds(ids) {
121
133
  let uniqIds = [...new Set(ids)];
@@ -190,7 +202,7 @@ export class FtSearchStateManager {
190
202
  this.setFilters(filters);
191
203
  }
192
204
  setLiveQuery(query) {
193
- this.store.actions.setLiveQuery(query);
205
+ this.store.actions.liveQuery(query);
194
206
  this.launchSuggest();
195
207
  }
196
208
  setRequest(request) {
@@ -198,7 +210,7 @@ export class FtSearchStateManager {
198
210
  ...request,
199
211
  facets: this.store.getState().request.facets
200
212
  });
201
- this.store.actions.setLiveQuery(request.query);
213
+ this.store.actions.liveQuery(request.query);
202
214
  this.store.actions.setPageNumber(1);
203
215
  this.launchSearch();
204
216
  }
@@ -217,7 +229,7 @@ export class FtSearchStateManager {
217
229
  this.openExternalDocumentInNewTab = openExternalDocumentInNewTab;
218
230
  }
219
231
  updateLocales() {
220
- return this.localesDebouncer.run(async () => this.store.actions.setLocales((await this.service.getAvailableSearchLocales()).contentLocales));
232
+ return this.localesDebouncer.run(async () => this.store.actions.locales((await this.service.getAvailableSearchLocales()).contentLocales));
221
233
  }
222
234
  launchSearch() {
223
235
  return this.searchDebouncer.run(() => this.fetchSearchData());
@@ -229,26 +241,29 @@ export class FtSearchStateManager {
229
241
  var _a, _b;
230
242
  try {
231
243
  (_a = this.cancelableSearch) === null || _a === void 0 ? void 0 : _a.cancel();
232
- let request = this.store.getState().request;
233
- this.store.actions.setPaging(undefined);
244
+ let request = {
245
+ ...this.store.getState().request,
246
+ facets: this.facetIds.map(id => ({ id })),
247
+ };
248
+ this.store.actions.paging(undefined);
234
249
  if (this.ignoreEmptyQuery && request.query.length == 0) {
235
- this.store.actions.setResults(undefined);
236
- this.store.actions.setFacets(undefined);
237
- this.store.actions.setSpellcheck(undefined);
250
+ this.store.actions.results(undefined);
251
+ this.store.actions.facets(undefined);
252
+ this.store.actions.spellcheck(undefined);
238
253
  }
239
254
  else {
240
255
  this.cancelableSearch = cancelable(this.service.launchSearch(request));
241
256
  const results = await this.cancelableSearch;
242
257
  if (results.paging.currentPage <= 1) {
243
- this.store.actions.setResults(results.results);
244
- this.store.actions.setFacets(results.facets);
245
- this.store.actions.setSpellcheck(results.spellcheck);
258
+ this.store.actions.results(results.results);
259
+ this.store.actions.facets(results.facets);
260
+ this.store.actions.spellcheck(results.spellcheck);
246
261
  }
247
262
  else {
248
263
  let newResults = ((_b = this.store.getState().results) !== null && _b !== void 0 ? _b : []).concat(results.results);
249
- this.store.actions.setResults(newResults);
264
+ this.store.actions.results(newResults);
250
265
  }
251
- this.store.actions.setPaging(results.paging);
266
+ this.store.actions.paging(results.paging);
252
267
  }
253
268
  }
254
269
  catch (e) {
@@ -272,7 +287,7 @@ export class FtSearchStateManager {
272
287
  (_a = this.cancelableSuggest) === null || _a === void 0 ? void 0 : _a.cancel();
273
288
  this.cancelableSuggest = cancelable(this.service.launchSuggest(request));
274
289
  let results = await this.cancelableSuggest;
275
- this.store.actions.setSuggestResults(results.suggestions);
290
+ this.store.actions.suggestResults(results.suggestions);
276
291
  }
277
292
  catch (e) {
278
293
  if (!(e instanceof CanceledPromiseError) && this.errorHandler) {
@@ -1,14 +1,14 @@
1
1
  import { FtSearchFacet, FtSearchLocale, FtSearchResultCluster, FtSearchResultsPageInfo, FtSpellcheck, FtSuggestResult } from "@fluid-topics/public-api";
2
2
  import { EnrichedFtSearchRequest } from "@fluid-topics/ft-wc-utils";
3
3
  export interface FtSearchPageState {
4
- locales?: Array<FtSearchLocale>;
4
+ locales: Array<FtSearchLocale> | undefined;
5
5
  request: EnrichedFtSearchRequest;
6
- results?: Array<FtSearchResultCluster>;
7
- facets?: Array<FtSearchFacet>;
8
- paging?: FtSearchResultsPageInfo;
9
- spellcheck?: FtSpellcheck;
6
+ results: Array<FtSearchResultCluster> | undefined;
7
+ facets: Array<FtSearchFacet> | undefined;
8
+ paging: FtSearchResultsPageInfo | undefined;
9
+ spellcheck: FtSpellcheck | undefined;
10
10
  liveQuery: string;
11
- suggestResults?: Array<FtSuggestResult>;
11
+ suggestResults: Array<FtSuggestResult> | undefined;
12
12
  }
13
13
  export interface FtSearchResultsChangeEventDetail {
14
14
  request: EnrichedFtSearchRequest;
@@ -14,13 +14,6 @@ declare const searchPageStateReducers: {
14
14
  setRequestScope: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["request"]["scope"]>) => void;
15
15
  setOtherQueryParams: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["request"]["otherQueryParams"]>) => void;
16
16
  setRequestClusterSortCriterion: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["request"]["clusterSortCriterions"]>) => void;
17
- setResults: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["results"]>) => void;
18
- setFacets: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["facets"]>) => void;
19
- setSpellcheck: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["spellcheck"]>) => void;
20
- setLocales: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["locales"]>) => void;
21
- setPaging: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["paging"]>) => void;
22
- setLiveQuery: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["liveQuery"]>) => void;
23
- setSuggestResults: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["suggestResults"]>) => void;
24
17
  };
25
18
  export type FtSearchPageStateReducers = typeof searchPageStateReducers;
26
19
  export declare const createSearchPageStore: (id: string) => FtReduxStore<FtSearchPageState, {
@@ -36,12 +29,5 @@ export declare const createSearchPageStore: (id: string) => FtReduxStore<FtSearc
36
29
  setRequestScope: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["request"]["scope"]>) => void;
37
30
  setOtherQueryParams: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["request"]["otherQueryParams"]>) => void;
38
31
  setRequestClusterSortCriterion: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["request"]["clusterSortCriterions"]>) => void;
39
- setResults: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["results"]>) => void;
40
- setFacets: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["facets"]>) => void;
41
- setSpellcheck: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["spellcheck"]>) => void;
42
- setLocales: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["locales"]>) => void;
43
- setPaging: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["paging"]>) => void;
44
- setLiveQuery: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["liveQuery"]>) => void;
45
- setSuggestResults: (state: FtSearchPageState, action: PayloadAction<FtSearchPageState["suggestResults"]>) => void;
46
32
  }, import("redux").AnyAction>;
47
33
  export {};
@@ -1,4 +1,4 @@
1
- import { FtReduxStore } from "@fluid-topics/ft-wc-utils";
1
+ import { FtReduxStore, minmax } from "@fluid-topics/ft-wc-utils";
2
2
  const searchPageStateReducers = {
3
3
  setRequest: (state, action) => {
4
4
  state.request = action.payload;
@@ -10,10 +10,12 @@ const searchPageStateReducers = {
10
10
  state.request.contentLocale = action.payload;
11
11
  },
12
12
  setPageSize: (state, action) => {
13
- state.request.paging.perPage = action.payload;
13
+ var _a;
14
+ const perPage = +((_a = action.payload) !== null && _a !== void 0 ? _a : 20);
15
+ state.request.paging.perPage = isNaN(perPage) ? 20 : minmax(1, perPage, 40);
14
16
  },
15
17
  setPageNumber: (state, action) => {
16
- state.request.paging.page = action.payload;
18
+ state.request.paging.page = isNaN(action.payload) ? 1 : Math.max(1, action.payload);
17
19
  },
18
20
  setRequestSort: (state, action) => {
19
21
  state.request.sort = action.payload;
@@ -37,27 +39,6 @@ const searchPageStateReducers = {
37
39
  var _a;
38
40
  state.request.clusterSortCriterions = (_a = action.payload) !== null && _a !== void 0 ? _a : [];
39
41
  },
40
- setResults: (state, action) => {
41
- state.results = action.payload;
42
- },
43
- setFacets: (state, action) => {
44
- state.facets = action.payload;
45
- },
46
- setSpellcheck: (state, action) => {
47
- state.spellcheck = action.payload;
48
- },
49
- setLocales: (state, action) => {
50
- state.locales = action.payload;
51
- },
52
- setPaging: (state, action) => {
53
- state.paging = action.payload;
54
- },
55
- setLiveQuery: (state, action) => {
56
- state.liveQuery = action.payload;
57
- },
58
- setSuggestResults: (state, action) => {
59
- state.suggestResults = action.payload;
60
- },
61
42
  };
62
43
  export const createSearchPageStore = (id) => FtReduxStore.get({
63
44
  name: "ft-search-" + id,
@@ -74,6 +55,12 @@ export const createSearchPageStore = (id) => FtReduxStore.get({
74
55
  },
75
56
  },
76
57
  liveQuery: "",
58
+ paging: undefined,
59
+ facets: undefined,
60
+ spellcheck: undefined,
61
+ locales: [],
62
+ results: undefined,
63
+ suggestResults: undefined
77
64
  },
78
65
  reducers: searchPageStateReducers
79
66
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-search-context",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Context block for integrated search components",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,12 +19,12 @@
19
19
  "url": "ssh://git@scm.mrs.antidot.net:2222/fluidtopics/ft-web-components.git"
20
20
  },
21
21
  "dependencies": {
22
- "@fluid-topics/ft-app-context": "1.2.2",
23
- "@fluid-topics/ft-wc-utils": "1.2.2",
22
+ "@fluid-topics/ft-app-context": "1.2.3",
23
+ "@fluid-topics/ft-wc-utils": "1.2.3",
24
24
  "lit": "3.1.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@fluid-topics/public-api": "1.0.77"
27
+ "@fluid-topics/public-api": "1.0.78"
28
28
  },
29
- "gitHead": "b12fa278dd5bc8a5b9d027ed52dae60b4c821ec4"
29
+ "gitHead": "31c1696257f82afca00cddf81033e8984f665c43"
30
30
  }