@fluid-topics/ft-search-context 2.2.26 → 2.2.28

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.
@@ -16,6 +16,7 @@ export declare class FtSearchStateManager extends FtStateManager {
16
16
  applyStickyFilters: boolean;
17
17
  private readonly searchWatcher;
18
18
  private readonly suggestWatcher;
19
+ private readonly localesWatcher;
19
20
  private readonly stickyFiltersIdWatcher;
20
21
  private readonly history;
21
22
  constructor(store: FtReduxStore<FtSearchPageState, FtSearchPageStateReducers>, service?: FtSearchService);
@@ -28,6 +29,7 @@ export declare class FtSearchStateManager extends FtStateManager {
28
29
  private updateSearchRequest;
29
30
  setQuery(query: string): void;
30
31
  setContentLocale(contentLocale?: string): string | undefined;
32
+ private static findKnownContentLocale;
31
33
  forceContentLocale(contentLocale?: string): void;
32
34
  setPageSize(pageSize: number): void;
33
35
  setPageNumber(pageNumber: number): void;
@@ -65,8 +67,7 @@ export declare class FtSearchStateManager extends FtStateManager {
65
67
  private loadTaruqaTemplate;
66
68
  addRecentQuery(query: string): void;
67
69
  removeRecentQuery(query: string): void;
68
- private localesDebouncer;
69
- updateLocales(): Promise<boolean>;
70
+ private updateLocales;
70
71
  private searchDebouncer;
71
72
  launchSearch: (request?: FtSearchRequest) => Promise<boolean>;
72
73
  private buildSearchRequest;
@@ -40,7 +40,12 @@ export class FtSearchStateManager extends FtStateManager {
40
40
  }
41
41
  this.updateSearchRequest({ taruqaTemplateOverride, changedByConfiguration: true });
42
42
  };
43
- this.localesDebouncer = new Debouncer(10);
43
+ this.updateLocales = (locales = ftAppInfoStore.getState().availableContentLocales) => {
44
+ this.store.actions.locales(locales);
45
+ if (locales.length > 0) {
46
+ this.forceContentLocale(this.store.getState().request.contentLocale);
47
+ }
48
+ };
44
49
  this.searchDebouncer = new Debouncer(100);
45
50
  this.launchSearch = (request) => {
46
51
  return this.searchDebouncer.run(() => this.fetchSearchData(request !== null && request !== void 0 ? request : this.buildSearchRequest()));
@@ -72,13 +77,9 @@ export class FtSearchStateManager extends FtStateManager {
72
77
  };
73
78
  };
74
79
  this.service = service !== null && service !== void 0 ? service : new FtSearchService();
75
- this.service.cache.addEventListener("clear-cache", (e) => {
76
- if (e.detail.clearedKeys.includes("available-locales")) {
77
- this.updateLocales();
78
- }
79
- });
80
80
  this.searchWatcher = new ReduxWatcher(store, this.buildSearchRequest, this.launchSearch);
81
81
  this.suggestWatcher = new ReduxWatcher(store, this.buildSuggestRequest, this.launchSuggest);
82
+ this.localesWatcher = new ReduxWatcher(ftAppInfoStore, (store) => store.availableContentLocales, this.updateLocales);
82
83
  this.stickyFiltersIdWatcher = new ReduxWatcher(ftAppInfoStore, (store) => { var _a; return (_a = store.stickyFilters) === null || _a === void 0 ? void 0 : _a.id; }, () => {
83
84
  if (this.applyStickyFilters) {
84
85
  this.launchSearch();
@@ -100,6 +101,7 @@ export class FtSearchStateManager extends FtStateManager {
100
101
  ftAppInfoStore.addEventListener(AuthenticationChangeEvent.eventName, this.loadTaruqaTemplate);
101
102
  this.searchWatcher.watch();
102
103
  this.suggestWatcher.watch();
104
+ this.localesWatcher.watch();
103
105
  this.stickyFiltersIdWatcher.watch();
104
106
  this.history.enable(ftAppInfoStore.getState().tenantId + "-ft-recent-queries");
105
107
  }
@@ -108,6 +110,7 @@ export class FtSearchStateManager extends FtStateManager {
108
110
  ftAppInfoStore.removeEventListener(AuthenticationChangeEvent.eventName, this.loadTaruqaTemplate);
109
111
  this.searchWatcher.stop();
110
112
  this.suggestWatcher.stop();
113
+ this.localesWatcher.stop();
111
114
  this.stickyFiltersIdWatcher.stop();
112
115
  this.history.disable();
113
116
  }
@@ -132,25 +135,32 @@ export class FtSearchStateManager extends FtStateManager {
132
135
  }
133
136
  setContentLocale(contentLocale) {
134
137
  var _a;
135
- var _b;
136
- const locales = (_b = this.store.getState().locales) !== null && _b !== void 0 ? _b : [];
137
138
  const previousContentLocale = this.store.getState().request.contentLocale;
138
- if (contentLocale != previousContentLocale) {
139
- if (locales.length > 0) {
140
- const isKnown = (locale) => locales.some((l) => l.lang == locale);
141
- if (!isKnown(contentLocale)) {
142
- contentLocale = isKnown(previousContentLocale) ? previousContentLocale : locales[0].lang;
143
- }
144
- }
139
+ if (contentLocale !== previousContentLocale) {
140
+ contentLocale = FtSearchStateManager.findKnownContentLocale(contentLocale, previousContentLocale);
145
141
  this.updateSearchRequest({ contentLocale, metadataFilters: [] }, true);
146
- if (this.canUpdateUiLocale && ((_a = ftAppStateManager.store.getState().localesConfiguration) === null || _a === void 0 ? void 0 : _a.searchLanguageSetsUiLanguage) && contentLocale) {
142
+ if (this.canUpdateUiLocale && ((_a = ftAppInfoStore.getState().localesConfiguration) === null || _a === void 0 ? void 0 : _a.searchLanguageSetsUiLanguage) && contentLocale) {
147
143
  ftAppStateManager.requestUiLocaleUpdate(contentLocale, contentLocale);
148
144
  }
149
145
  }
150
146
  return contentLocale;
151
147
  }
148
+ static findKnownContentLocale(...candidates) {
149
+ const { availableContentLocales, localesConfiguration } = ftAppInfoStore.getState();
150
+ if (availableContentLocales.length === 0) {
151
+ return candidates[0];
152
+ }
153
+ const isKnown = (locale) => availableContentLocales.some((l) => l.lang == locale);
154
+ for (const candidate of candidates) {
155
+ if (isKnown(candidate)) {
156
+ return candidate;
157
+ }
158
+ }
159
+ const defaultLocale = localesConfiguration === null || localesConfiguration === void 0 ? void 0 : localesConfiguration.defaultLocales.defaultContentLocale;
160
+ return defaultLocale ? `${defaultLocale.lang}-${defaultLocale.region}` : availableContentLocales[0].lang;
161
+ }
152
162
  forceContentLocale(contentLocale) {
153
- this.updateSearchRequest({ contentLocale });
163
+ this.updateSearchRequest({ contentLocale: FtSearchStateManager.findKnownContentLocale(contentLocale) });
154
164
  }
155
165
  setPageSize(pageSize) {
156
166
  const request = this.store.getState().request;
@@ -354,9 +364,6 @@ export class FtSearchStateManager extends FtStateManager {
354
364
  removeRecentQuery(query) {
355
365
  this.history.removeRecentQuery(query);
356
366
  }
357
- updateLocales() {
358
- return this.localesDebouncer.run(async () => this.store.actions.locales((await this.service.getAvailableSearchLocales()).contentLocales));
359
- }
360
367
  async fetchSearchData(request) {
361
368
  var _a, _b, _c;
362
369
  var _d, _e;
@@ -2,6 +2,9 @@ import { FtSearchConfiguration, FtSearchFacet, FtSearchLocale, FtSearchResultAnn
2
2
  import { EnrichedFtSearchRequest } from "@fluid-topics/ft-wc-utils";
3
3
  export interface FtSearchPageState {
4
4
  configuration: FtSearchConfiguration | undefined;
5
+ /**
6
+ * @deprecated Use app-context's availableContentLocales
7
+ */
5
8
  locales: Array<FtSearchLocale> | undefined;
6
9
  request: EnrichedFtSearchRequest;
7
10
  results: Array<FtSearchResultCluster> | undefined;
@@ -33,4 +33,5 @@ export const createSearchPageStore = (id) => FtReduxStore.get({
33
33
  propagatedFacets: [],
34
34
  },
35
35
  reducers: searchPageStateReducers,
36
+ deprecatedKeys: ["locales"],
36
37
  });
@@ -1,10 +1,9 @@
1
- import { type FluidTopicsApi, FtSearchConfiguration, FtSearchLocales, FtSearchRequest, FtSearchResults, FtSuggestRequest, FtSuggestResults } from "@fluid-topics/public-api";
1
+ import { type FluidTopicsApi, FtSearchConfiguration, FtSearchRequest, FtSearchResults, FtSuggestRequest, FtSuggestResults } from "@fluid-topics/public-api";
2
2
  import { FtServiceWithCache } from "@fluid-topics/ft-app-context";
3
3
  export declare class FtSearchService extends FtServiceWithCache {
4
4
  constructor(overrideApi?: FluidTopicsApi);
5
5
  launchSearch(request: FtSearchRequest): Promise<FtSearchResults>;
6
6
  launchSuggest(request: FtSuggestRequest): Promise<FtSuggestResults>;
7
- getAvailableSearchLocales(): Promise<FtSearchLocales>;
8
7
  getConfiguration(): Promise<FtSearchConfiguration>;
9
8
  private sortFilters;
10
9
  }
@@ -19,9 +19,6 @@ export class FtSearchService extends FtServiceWithCache {
19
19
  };
20
20
  return this.cache.get("suggest-" + this.hash(sortedRequest), async () => (await this.awaitApi).getSuggestions(request), 2 * 60 * 1000);
21
21
  }
22
- async getAvailableSearchLocales() {
23
- return this.cache.get("available-locales", async () => (await this.awaitApi).getAvailableSearchLocales());
24
- }
25
22
  async getConfiguration() {
26
23
  return this.cache.get("search-configuration");
27
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-search-context",
3
- "version": "2.2.26",
3
+ "version": "2.2.28",
4
4
  "description": "Context block for integrated search components",
5
5
  "keywords": [
6
6
  "Lit"
@@ -19,13 +19,13 @@
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.26",
23
- "@fluid-topics/ft-wc-utils": "2.2.26",
22
+ "@fluid-topics/ft-app-context": "2.2.28",
23
+ "@fluid-topics/ft-wc-utils": "2.2.28",
24
24
  "@reduxjs/toolkit": "2.13.0",
25
25
  "lit": "3.3.3"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@fluid-topics/public-api": "1.0.144"
29
29
  },
30
- "gitHead": "8372f450183ce9d47e678a6a2cb60bdc619a49db"
30
+ "gitHead": "8ca1d190ac34fad2ecec7ad3b03890913f865eb7"
31
31
  }