@fluid-topics/ft-search-results 1.1.12 → 1.1.14

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.
@@ -10,9 +10,15 @@ export declare class FtSearchResults extends FtSearchResults_base implements FtS
10
10
  static styles: import("lit").CSSResult;
11
11
  clusterPolicy: ClusterPolicy;
12
12
  displayNoResultsMessage: boolean;
13
- renderResult: (result: FtSearchResultClusterEntry, index: number) => TemplateResult | string;
13
+ renderResult: (resultOrCluster: FtSearchResultClusterEntry, index: number) => TemplateResult | string;
14
14
  private results?;
15
+ private selectedResultByCluster;
15
16
  constructor();
16
17
  protected render(): unknown;
18
+ private onClusterChange;
19
+ private buildClusters;
20
+ private buildFullClusters;
21
+ private buildAllResultsClusters;
22
+ private clusterId;
17
23
  }
18
24
  export {};
@@ -24,23 +24,54 @@ class FtSearchResults extends withI18n(FtSearchComponent) {
24
24
  <ft-search-result-title></ft-search-result-title>
25
25
  <ft-search-result-abstract></ft-search-result-abstract>
26
26
  `;
27
+ this.selectedResultByCluster = {};
27
28
  this.addI18nContext(resultsNumberContext);
28
29
  }
29
30
  render() {
30
- var _a;
31
31
  if (this.displayNoResultsMessage && this.results != null && this.results.length == 0) {
32
32
  return html `
33
33
  <ft-typography part="no-results-message" variant="body1">${resultsNumberContext.messages.results(0)}</ft-typography>
34
34
  `;
35
35
  }
36
- return repeat(((_a = this.results) !== null && _a !== void 0 ? _a : [])
37
- .flatMap(result => this.clusterPolicy == "display-first-result"
38
- ? [result.entries[0]]
39
- : result.entries), (result) => { var _a, _b, _c, _d, _e; return (_d = (_b = (_a = result.document) === null || _a === void 0 ? void 0 : _a.documentId) !== null && _b !== void 0 ? _b : (_c = result.map) === null || _c === void 0 ? void 0 : _c.mapId) !== null && _d !== void 0 ? _d : (_e = result.topic) === null || _e === void 0 ? void 0 : _e.tocId; }, (result, index) => html `
40
- <ft-search-result-context .result=${result} index="${index}">
41
- ${this.renderResult(result, index)}
36
+ const clusters = this.buildClusters();
37
+ return repeat(clusters, cluster => cluster.id, (cluster, index) => {
38
+ var _a;
39
+ return html `
40
+ <ft-search-result-context .cluster=${cluster} index="${index}"
41
+ @ft-search-result-cluster-change="${(e) => this.onClusterChange(cluster.id, e.detail)}">
42
+ ${this.renderResult((_a = this.selectedResultByCluster[cluster.id]) !== null && _a !== void 0 ? _a : cluster.entries[0], index)}
42
43
  </ft-search-result-context>
43
- `);
44
+ `;
45
+ });
46
+ }
47
+ onClusterChange(clusterId, result) {
48
+ this.selectedResultByCluster[clusterId] = result;
49
+ }
50
+ buildClusters() {
51
+ switch (this.clusterPolicy) {
52
+ case "display-first-result":
53
+ return this.buildFullClusters();
54
+ case "display-all-results":
55
+ return this.buildAllResultsClusters();
56
+ }
57
+ }
58
+ buildFullClusters() {
59
+ var _a, _b;
60
+ return (_b = (_a = this.results) === null || _a === void 0 ? void 0 : _a.map(cluster => ({
61
+ id: this.clusterId(cluster.entries[0]),
62
+ entries: cluster.entries
63
+ }))) !== null && _b !== void 0 ? _b : [];
64
+ }
65
+ buildAllResultsClusters() {
66
+ var _a, _b;
67
+ return (_b = (_a = this.results) === null || _a === void 0 ? void 0 : _a.flatMap(cluster => cluster.entries.map(entry => ({
68
+ id: this.clusterId(entry),
69
+ entries: [entry]
70
+ })))) !== null && _b !== void 0 ? _b : [];
71
+ }
72
+ clusterId(result) {
73
+ var _a, _b, _c, _d, _e;
74
+ return (_d = (_b = (_a = result.map) === null || _a === void 0 ? void 0 : _a.mapId) !== null && _b !== void 0 ? _b : (_c = result.topic) === null || _c === void 0 ? void 0 : _c.tocId) !== null && _d !== void 0 ? _d : (_e = result.document) === null || _e === void 0 ? void 0 : _e.documentId;
44
75
  }
45
76
  }
46
77
  FtSearchResults.styles = styles;