@fluid-topics/ft-search-context 2.2.6 → 2.2.7

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.
@@ -1,5 +1,5 @@
1
1
  import { FtSearchPageState } from "./model";
2
- import { FtReduxStore, FtStateManager, ReduxWatcher } from "@fluid-topics/ft-wc-utils";
2
+ import { FtReduxStore, FtStateManager } from "@fluid-topics/ft-wc-utils";
3
3
  import { FtSearchPageStateReducers } from "./redux";
4
4
  import { FtDateFilterTypeKeys, FtMetadataFilter, FtPublicClusterSortCriterion, FtSearchKeywordMatch, FtSearchRequest, FtSearchScope, FtSearchSortCriterion, FtSuggestRequest, FtVirtualField } from "@fluid-topics/public-api";
5
5
  import { FtSearchService } from "./utils/FtSearchService";
@@ -13,14 +13,16 @@ export declare class FtSearchStateManager extends FtStateManager {
13
13
  ignoreEmptyQuery: boolean;
14
14
  canUpdateUiLocale: boolean;
15
15
  openExternalDocumentInNewTab: boolean;
16
- protected readonly searchWatcher: ReduxWatcher<FtSearchPageState, FtSearchRequest>;
17
- protected readonly suggestWatcher: ReduxWatcher<FtSearchPageState, FtSuggestRequest>;
16
+ applyStickyFilters: boolean;
17
+ private readonly searchWatcher;
18
+ private readonly suggestWatcher;
19
+ private readonly stickyFiltersIdWatcher;
20
+ private readonly history;
18
21
  constructor(store: FtReduxStore<FtSearchPageState, FtSearchPageStateReducers>, service?: FtSearchService);
19
22
  onNewNeededRequest: (neededRequest: string) => void;
20
23
  initService(): Promise<boolean>;
21
24
  addListeners(): void;
22
25
  removeListeners(): void;
23
- private get recentQueriesStorageKey();
24
26
  private get taruqaConfigStorageKey();
25
27
  private onStorageEvent;
26
28
  private updateSearchRequest;
@@ -58,11 +60,10 @@ export declare class FtSearchStateManager extends FtStateManager {
58
60
  setIgnoreEmptyQuery(ignoreEmptyQuery: boolean): void;
59
61
  setOpenExternalDocumentInNewTab(openExternalDocumentInNewTab: boolean): void;
60
62
  setCanUpdateUiLocale(canUpdateUiLocale: boolean): void;
63
+ setApplyStickyFilters(applyStickyFilters: boolean): void;
61
64
  private loadTaruqaTemplate;
62
- private loadRecentQueries;
63
65
  addRecentQuery(query: string): void;
64
66
  removeRecentQuery(query: string): void;
65
- private setRecentQueries;
66
67
  private localesDebouncer;
67
68
  updateLocales(): Promise<boolean>;
68
69
  private searchDebouncer;
@@ -1,5 +1,5 @@
1
1
  import { FtSearchStateResourceRequest, } from "./model";
2
- import { cancelable, CanceledPromiseError, Debouncer, deepCopy, FtStateManager, minmax, watch, } from "@fluid-topics/ft-wc-utils";
2
+ import { cancelable, CanceledPromiseError, Debouncer, deepCopy, FtStateManager, minmax, ReduxWatcher, QueryHistoryStorage, } from "@fluid-topics/ft-wc-utils";
3
3
  import { createSearchPageStore, } from "./redux";
4
4
  import { FtSearchKeywordMatch, FtSearchScope, FtUserRole, FtVirtualField, userHasRole, } from "@fluid-topics/public-api";
5
5
  import { FtSearchService } from "./utils/FtSearchService";
@@ -8,7 +8,6 @@ import { AuthenticationChangeEvent, ftAppInfoStore, ftAppStateManager, } from "@
8
8
  export const searchInDocumentTitlesOnlySelector = (s) => s.request.virtualField === FtVirtualField.TITLE_ONLY
9
9
  && s.request.scope === FtSearchScope.DOCUMENTS;
10
10
  export const keywordMatchSelector = (s) => s.request.keywordMatch == FtSearchKeywordMatch.MANDATORY;
11
- const maxRecentQueries = 20;
12
11
  export class FtSearchStateManager extends FtStateManager {
13
12
  static build(id, service) {
14
13
  return new FtSearchStateManager(createSearchPageStore(id.trim() || "context"), service);
@@ -19,17 +18,16 @@ export class FtSearchStateManager extends FtStateManager {
19
18
  this.ignoreEmptyQuery = false;
20
19
  this.canUpdateUiLocale = false;
21
20
  this.openExternalDocumentInNewTab = false;
21
+ this.applyStickyFilters = false;
22
+ this.history = new QueryHistoryStorage(this.store.actions.recentQueries);
22
23
  this.onNewNeededRequest = (neededRequest) => {
23
24
  if (neededRequest == FtSearchStateResourceRequest.CLUSTERED_SEARCH) {
24
- this.launchSearch(this.buildSearchRequest(this.store.getState()));
25
+ this.launchSearch();
25
26
  }
26
27
  };
27
28
  this.onStorageEvent = (e) => {
28
29
  // detect changes from any context
29
- if (e.key === this.recentQueriesStorageKey) {
30
- this.loadRecentQueries();
31
- }
32
- else if (e.key === this.taruqaConfigStorageKey) {
30
+ if (e.key === this.taruqaConfigStorageKey) {
33
31
  this.loadTaruqaTemplate();
34
32
  }
35
33
  };
@@ -45,28 +43,31 @@ export class FtSearchStateManager extends FtStateManager {
45
43
  this.localesDebouncer = new Debouncer(10);
46
44
  this.searchDebouncer = new Debouncer(100);
47
45
  this.launchSearch = (request) => {
48
- return this.searchDebouncer.run(() => this.fetchSearchData(request !== null && request !== void 0 ? request : this.buildSearchRequest(this.store.getState())));
46
+ return this.searchDebouncer.run(() => this.fetchSearchData(request !== null && request !== void 0 ? request : this.buildSearchRequest()));
49
47
  };
50
- this.buildSearchRequest = (state) => {
48
+ this.buildSearchRequest = (searchState = this.store.getState()) => {
49
+ var _a;
51
50
  return {
52
- ...state.request,
51
+ ...searchState.request,
53
52
  facets: this.facetIds.map((id) => ({ id })),
53
+ stickyFiltersId: this.applyStickyFilters ? (_a = ftAppInfoStore.getState().stickyFilters) === null || _a === void 0 ? void 0 : _a.id : undefined,
54
54
  };
55
55
  };
56
56
  this.suggestDebouncer = new Debouncer(1000);
57
57
  this.launchSuggest = (request) => {
58
- return this.suggestDebouncer.run(() => this.fetchSuggestData(request !== null && request !== void 0 ? request : this.buildSuggestRequest(this.store.getState())));
58
+ return this.suggestDebouncer.run(() => this.fetchSuggestData(request !== null && request !== void 0 ? request : this.buildSuggestRequest()));
59
59
  };
60
- this.buildSuggestRequest = (state) => {
61
- var _a;
60
+ this.buildSuggestRequest = (searchState = this.store.getState()) => {
61
+ var _a, _b;
62
62
  return {
63
- input: state.liveQuery,
64
- metadataFilters: state.request.metadataFilters,
65
- sort: (_a = state.request.sort) !== null && _a !== void 0 ? _a : [],
66
- sortId: state.request.sortId,
67
- contentLocale: state.request.contentLocale,
68
- scope: state.request.scope,
69
- keywordMatch: state.request.keywordMatch,
63
+ input: searchState.liveQuery,
64
+ metadataFilters: searchState.request.metadataFilters,
65
+ sort: (_a = searchState.request.sort) !== null && _a !== void 0 ? _a : [],
66
+ sortId: searchState.request.sortId,
67
+ contentLocale: searchState.request.contentLocale,
68
+ scope: searchState.request.scope,
69
+ keywordMatch: searchState.request.keywordMatch,
70
+ stickyFiltersId: this.applyStickyFilters ? (_b = ftAppInfoStore.getState().stickyFilters) === null || _b === void 0 ? void 0 : _b.id : undefined,
70
71
  };
71
72
  };
72
73
  this.service = service !== null && service !== void 0 ? service : new FtSearchService();
@@ -75,8 +76,14 @@ export class FtSearchStateManager extends FtStateManager {
75
76
  this.updateLocales();
76
77
  }
77
78
  });
78
- this.searchWatcher = watch(store, this.buildSearchRequest, this.launchSearch);
79
- this.suggestWatcher = watch(store, this.buildSuggestRequest, this.launchSuggest);
79
+ this.searchWatcher = new ReduxWatcher(store, this.buildSearchRequest, this.launchSearch);
80
+ this.suggestWatcher = new ReduxWatcher(store, this.buildSuggestRequest, this.launchSuggest);
81
+ this.stickyFiltersIdWatcher = new ReduxWatcher(ftAppInfoStore, (store) => { var _a; return (_a = store.stickyFilters) === null || _a === void 0 ? void 0 : _a.id; }, () => {
82
+ if (this.applyStickyFilters) {
83
+ this.launchSearch();
84
+ this.launchSuggest();
85
+ }
86
+ });
80
87
  }
81
88
  async initService() {
82
89
  this.updateLocales();
@@ -84,20 +91,24 @@ export class FtSearchStateManager extends FtStateManager {
84
91
  this.store.actions.configuration(conf);
85
92
  this.setSortId(this.store.getState().request.sortId);
86
93
  });
87
- this.loadRecentQueries();
88
94
  this.loadTaruqaTemplate();
89
95
  return this.launchSearch();
90
96
  }
91
97
  addListeners() {
92
98
  window.addEventListener("storage", this.onStorageEvent);
93
99
  ftAppInfoStore.addEventListener(AuthenticationChangeEvent.eventName, this.loadTaruqaTemplate);
100
+ this.searchWatcher.watch();
101
+ this.suggestWatcher.watch();
102
+ this.stickyFiltersIdWatcher.watch();
103
+ this.history.enable(ftAppInfoStore.getState().tenantId + "-ft-recent-queries");
94
104
  }
95
105
  removeListeners() {
96
106
  window.removeEventListener("storage", this.onStorageEvent);
97
107
  ftAppInfoStore.removeEventListener(AuthenticationChangeEvent.eventName, this.loadTaruqaTemplate);
98
- }
99
- get recentQueriesStorageKey() {
100
- return ftAppInfoStore.getState().tenantId + "-ft-recent-queries";
108
+ this.searchWatcher.stop();
109
+ this.suggestWatcher.stop();
110
+ this.stickyFiltersIdWatcher.stop();
111
+ this.history.disable();
101
112
  }
102
113
  get taruqaConfigStorageKey() {
103
114
  return ftAppInfoStore.getState().tenantId + "-taruqa-experiment-conf";
@@ -324,38 +335,16 @@ export class FtSearchStateManager extends FtStateManager {
324
335
  setCanUpdateUiLocale(canUpdateUiLocale) {
325
336
  this.canUpdateUiLocale = canUpdateUiLocale;
326
337
  }
327
- loadRecentQueries() {
328
- var _a;
329
- this.store.actions.recentQueries(JSON.parse((_a = window.localStorage.getItem(this.recentQueriesStorageKey)) !== null && _a !== void 0 ? _a : "[]"));
338
+ setApplyStickyFilters(applyStickyFilters) {
339
+ this.applyStickyFilters = applyStickyFilters;
340
+ this.launchSearch();
341
+ this.launchSuggest();
330
342
  }
331
343
  addRecentQuery(query) {
332
- query = query.trim();
333
- if (query.length === 0) {
334
- return;
335
- }
336
- const normalizedQuery = query.toLowerCase();
337
- const newValue = this.store.getState().recentQueries.filter((q) => q.toLowerCase() !== normalizedQuery).slice(0, maxRecentQueries - 1);
338
- newValue.unshift(query);
339
- this.setRecentQueries(newValue);
344
+ this.history.addRecentQuery(query);
340
345
  }
341
346
  removeRecentQuery(query) {
342
- const normalizedQuery = query.trim().toLowerCase();
343
- const original = this.store.getState().recentQueries;
344
- const otherQueries = original.filter((q) => q.toLowerCase() !== normalizedQuery);
345
- if (original.length !== otherQueries.length) {
346
- this.setRecentQueries(otherQueries);
347
- }
348
- }
349
- setRecentQueries(queries) {
350
- const newValue = JSON.stringify(queries);
351
- window.localStorage.setItem(this.recentQueriesStorageKey, newValue);
352
- // notify all contexts
353
- window.dispatchEvent(new StorageEvent("storage", {
354
- key: this.recentQueriesStorageKey,
355
- newValue,
356
- storageArea: window.localStorage,
357
- url: window.location.href,
358
- }));
347
+ this.history.removeRecentQuery(query);
359
348
  }
360
349
  updateLocales() {
361
350
  return this.localesDebouncer.run(async () => this.store.actions.locales((await this.service.getAvailableSearchLocales()).contentLocales));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-search-context",
3
- "version": "2.2.6",
3
+ "version": "2.2.7",
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": "2.2.6",
23
- "@fluid-topics/ft-wc-utils": "2.2.6",
22
+ "@fluid-topics/ft-app-context": "2.2.7",
23
+ "@fluid-topics/ft-wc-utils": "2.2.7",
24
24
  "lit": "3.3.3"
25
25
  },
26
26
  "devDependencies": {
27
- "@fluid-topics/public-api": "1.0.139"
27
+ "@fluid-topics/public-api": "1.0.140"
28
28
  },
29
- "gitHead": "f482cb39331ccd1668b13e3debc0b652310aadc2"
29
+ "gitHead": "dff67505fe1e41bc42e0bdfafc7060ca40f8dc9d"
30
30
  }