@fluid-topics/ft-search-context 1.1.0 → 1.1.2

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,7 +1,7 @@
1
1
  import { FtSearchPageState } from "./model";
2
2
  import { FtReduxStore } from "@fluid-topics/ft-wc-utils";
3
3
  import { FtSearchPageStateReducers } from "./redux";
4
- import { FtSearchFilter, FtSearchRequest, FtSearchSortCriterion } from "@fluid-topics/public-api";
4
+ import { FtSearchFilter, FtSearchRequest, FtSearchScope, FtSearchSortCriterion } from "@fluid-topics/public-api";
5
5
  import { FtSearchService } from "./utils/FtSearchService";
6
6
  export declare const searchInDocumentTitlesOnlySelector: (s: FtSearchPageState) => boolean;
7
7
  export declare class ClearAllFiltersEvent extends Event {
@@ -14,6 +14,7 @@ export declare class FtSearchStateManager {
14
14
  static build(id: string): FtSearchStateManager;
15
15
  service?: FtSearchService;
16
16
  errorHandler?: (e: Error) => void;
17
+ ignoreEmptyQuery: boolean;
17
18
  constructor(store: FtReduxStore<FtSearchPageState, FtSearchPageStateReducers>, serviceProvider: () => Promise<FtSearchService>);
18
19
  initService(): Promise<boolean>;
19
20
  awaitService(): Promise<FtSearchService>;
@@ -33,6 +34,8 @@ export declare class FtSearchStateManager {
33
34
  setFilter(key: string, values: string[]): void;
34
35
  setLiveQuery(query: string): void;
35
36
  setRequest(request: FtSearchRequest): void;
37
+ setScope(scope: FtSearchScope): void;
38
+ setIgnoreEmptyQuery(ignoreEmptyQuery: boolean): void;
36
39
  private searchDebouncer;
37
40
  launchSearch(): Promise<boolean>;
38
41
  private suggestDebouncer;
@@ -41,4 +44,5 @@ export declare class FtSearchStateManager {
41
44
  private fetchSearchData;
42
45
  private cancelableSuggest;
43
46
  private fetchSuggestData;
47
+ clear(): void;
44
48
  }
@@ -18,6 +18,7 @@ export class FtSearchStateManager {
18
18
  constructor(store, serviceProvider) {
19
19
  this.store = store;
20
20
  this.serviceProvider = serviceProvider;
21
+ this.ignoreEmptyQuery = false;
21
22
  this.searchDebouncer = new Debouncer(100);
22
23
  this.suggestDebouncer = new Debouncer(300);
23
24
  }
@@ -134,6 +135,14 @@ export class FtSearchStateManager {
134
135
  this.store.actions.setPageNumber(1);
135
136
  this.launchSearch();
136
137
  }
138
+ setScope(scope) {
139
+ this.store.actions.setRequestScope(scope);
140
+ this.launchSearch();
141
+ }
142
+ setIgnoreEmptyQuery(ignoreEmptyQuery) {
143
+ this.ignoreEmptyQuery = ignoreEmptyQuery;
144
+ this.launchSearch();
145
+ }
137
146
  async launchSearch() {
138
147
  await this.awaitService();
139
148
  return this.searchDebouncer.run(() => this.fetchSearchData());
@@ -146,18 +155,27 @@ export class FtSearchStateManager {
146
155
  var _a, _b;
147
156
  try {
148
157
  (_a = this.cancelableSearch) === null || _a === void 0 ? void 0 : _a.cancel();
149
- this.cancelableSearch = cancelable(this.service.launchSearch(this.store.getState().request));
150
- const results = await this.cancelableSearch;
151
- if (results.paging.currentPage <= 1) {
152
- this.store.actions.setResults(results.results);
153
- this.store.actions.setFacets(results.facets);
154
- this.store.actions.setSpellcheck(results.spellcheck);
158
+ let request = this.store.getState().request;
159
+ this.store.actions.setPaging(undefined);
160
+ if (this.ignoreEmptyQuery && request.query.length == 0) {
161
+ this.store.actions.setResults(undefined);
162
+ this.store.actions.setFacets(undefined);
163
+ this.store.actions.setSpellcheck(undefined);
155
164
  }
156
165
  else {
157
- let newResults = ((_b = this.store.getState().results) !== null && _b !== void 0 ? _b : []).concat(results.results);
158
- this.store.actions.setResults(newResults);
166
+ this.cancelableSearch = cancelable(this.service.launchSearch(request));
167
+ const results = await this.cancelableSearch;
168
+ if (results.paging.currentPage <= 1) {
169
+ this.store.actions.setResults(results.results);
170
+ this.store.actions.setFacets(results.facets);
171
+ this.store.actions.setSpellcheck(results.spellcheck);
172
+ }
173
+ else {
174
+ let newResults = ((_b = this.store.getState().results) !== null && _b !== void 0 ? _b : []).concat(results.results);
175
+ this.store.actions.setResults(newResults);
176
+ }
177
+ this.store.actions.setPaging(results.paging);
159
178
  }
160
- this.store.actions.setPaging(results.paging);
161
179
  }
162
180
  catch (e) {
163
181
  if (!(e instanceof CanceledPromiseError) && this.errorHandler) {
@@ -188,4 +206,7 @@ export class FtSearchStateManager {
188
206
  }
189
207
  }
190
208
  }
209
+ clear() {
210
+ this.store.clear();
211
+ }
191
212
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluid-topics/ft-search-context",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
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.1.0",
23
- "@fluid-topics/ft-wc-utils": "1.1.0",
22
+ "@fluid-topics/ft-app-context": "1.1.2",
23
+ "@fluid-topics/ft-wc-utils": "1.1.2",
24
24
  "lit": "3.1.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@fluid-topics/public-api": "1.0.50"
27
+ "@fluid-topics/public-api": "1.0.51"
28
28
  },
29
- "gitHead": "3f2a051fc84a0e27b942f311efee39954f6d2883"
29
+ "gitHead": "53ce99f657872582bca43cbb7ad691b239b22823"
30
30
  }