@fluid-topics/ft-search-result-metadata 1.1.15 → 1.1.17

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,13 +16,17 @@ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base
16
16
  */
17
17
  maxLength?: number;
18
18
  private editorMode;
19
+ private metadataDescriptors;
20
+ private request?;
19
21
  private resultMetadata?;
20
22
  private metadataLabel?;
21
- private computedClusters;
23
+ private clustersByValue;
24
+ private clusters;
22
25
  constructor();
23
26
  setResultStateManager(resultStateManager: FtSearchResultStateManager): void;
24
27
  protected render(): import("lit").TemplateResult<1>;
25
28
  private renderClusterList;
29
+ private hideIfEmpty;
26
30
  private onClusterSelected;
27
31
  private computeClusters;
28
32
  private renderClusterItem;
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
4
4
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
- import { html } from "lit";
7
+ import { html, nothing } from "lit";
8
8
  import { property, state } from "lit/decorators.js";
9
9
  import { redux } from "@fluid-topics/ft-wc-utils";
10
10
  import { styles } from "./ft-search-result-metadata.css";
@@ -25,7 +25,9 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
25
25
  this.useAsClusterSwitch = false;
26
26
  this.goToDocumentOnSwitch = false;
27
27
  this.editorMode = false;
28
- this.computedClusters = {};
28
+ this.metadataDescriptors = [];
29
+ this.clustersByValue = {};
30
+ this.clusters = [];
29
31
  this.addStore(ftAppInfoStore);
30
32
  this.addI18nContext(searchResultMetadataContext);
31
33
  }
@@ -36,7 +38,10 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
36
38
  }
37
39
  }
38
40
  render() {
39
- return this.displayCluster ? this.renderClusterList() : this.renderChip();
41
+ return html `
42
+ ${this.displayCluster ? this.renderClusterList() : this.renderChip()}
43
+ ${this.hideIfEmpty()}
44
+ `;
40
45
  }
41
46
  renderClusterList() {
42
47
  return html `
@@ -46,23 +51,36 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
46
51
  slot="button">
47
52
  ${this.renderChip("toggle")}
48
53
  <ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
49
- ${repeat(Object.entries(this.computedClusters), ([value, _]) => value, ([value, item]) => this.renderClusterItem(item.result, item.metadata))}
54
+ ${repeat(this.clusters, cluster => cluster.metadata.value, cluster => this.renderClusterItem(cluster.result, cluster.metadata))}
50
55
  </ft-floating-menu>
51
56
  </div>
52
57
  `;
53
58
  }
59
+ hideIfEmpty() {
60
+ if (this.valueText.length == 0 && this.clusters.length == 0 && !this.editorMode) {
61
+ return html `
62
+ <style>
63
+ :host {
64
+ display: none !important;
65
+ }
66
+ </style>
67
+ `;
68
+ }
69
+ return nothing;
70
+ }
54
71
  onClusterSelected(e) {
55
72
  var _a;
56
- (_a = this.resultStateManager) === null || _a === void 0 ? void 0 : _a.selectResult(this.computedClusters[e.detail].result);
73
+ (_a = this.resultStateManager) === null || _a === void 0 ? void 0 : _a.selectResult(this.clustersByValue[e.detail].result);
57
74
  }
58
75
  computeClusters() {
59
- const newClusters = {};
60
- const clusteringHelper = new ClusteringHelper(this.cluster, this.result, this.resultStateManager.registeredMetadata);
61
- clusteringHelper.computeClustersItemsForMetadata(this.key)
62
- .forEach(item => {
63
- newClusters[item.metadata.value] = item;
76
+ var _a;
77
+ const clustersByValue = {};
78
+ const clusteringHelper = new ClusteringHelper(this.cluster, this.result, this.resultStateManager.registeredMetadata, this.metadataDescriptors);
79
+ this.clusters = clusteringHelper.computeClustersItemsForMetadata(this.key, ((_a = this.request) === null || _a === void 0 ? void 0 : _a.contentLocale) || "en");
80
+ this.clusters.forEach(item => {
81
+ clustersByValue[item.metadata.value] = item;
64
82
  });
65
- this.computedClusters = newClusters;
83
+ this.clustersByValue = clustersByValue;
66
84
  }
67
85
  renderClusterItem(result, metadata) {
68
86
  if (this.goToDocumentOnSwitch) {
@@ -101,7 +119,7 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
101
119
  if (this.resultMetadata) {
102
120
  return html `${this.getEllipsis(this.valueText)}`;
103
121
  }
104
- if (this.useAsClusterSwitch && Object.keys(this.computedClusters).length > 0) {
122
+ if (this.useAsClusterSwitch && Object.keys(this.clustersByValue).length > 0) {
105
123
  return html `${searchResultMetadataContext.messages.noValueInCluster()}`;
106
124
  }
107
125
  if (this.editorMode) {
@@ -206,6 +224,12 @@ __decorate([
206
224
  __decorate([
207
225
  redux({ store: ftAppInfoStore.name })
208
226
  ], FtSearchResultMetadata.prototype, "editorMode", void 0);
227
+ __decorate([
228
+ redux({ store: ftAppInfoStore.name })
229
+ ], FtSearchResultMetadata.prototype, "metadataDescriptors", void 0);
230
+ __decorate([
231
+ redux({ store: "search" })
232
+ ], FtSearchResultMetadata.prototype, "request", void 0);
209
233
  __decorate([
210
234
  state()
211
235
  ], FtSearchResultMetadata.prototype, "resultMetadata", void 0);
@@ -214,5 +238,8 @@ __decorate([
214
238
  ], FtSearchResultMetadata.prototype, "metadataLabel", void 0);
215
239
  __decorate([
216
240
  state()
217
- ], FtSearchResultMetadata.prototype, "computedClusters", void 0);
241
+ ], FtSearchResultMetadata.prototype, "clustersByValue", void 0);
242
+ __decorate([
243
+ state()
244
+ ], FtSearchResultMetadata.prototype, "clusters", void 0);
218
245
  export { FtSearchResultMetadata };