@fluid-topics/ft-search-result-metadata 1.1.39 → 1.1.41

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.
@@ -21,12 +21,11 @@ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base
21
21
  private resultMetadata?;
22
22
  private metadataLabel?;
23
23
  private clustersByValue;
24
- private clusters;
24
+ private clusterItems?;
25
25
  constructor();
26
26
  setResultStateManager(resultStateManager: FtSearchResultStateManager): void;
27
27
  protected render(): import("lit").TemplateResult<1>;
28
28
  private renderClusterList;
29
- private hideIfEmpty;
30
29
  private onClusterSelected;
31
30
  private computeClusters;
32
31
  private renderClusterItem;
@@ -38,7 +37,7 @@ export declare class FtSearchResultMetadata extends FtSearchResultMetadata_base
38
37
  private get clusterHasMultipleValues();
39
38
  private getEllipsis;
40
39
  protected update(props: PropertyValues): void;
41
- private get resultData();
40
+ private resultData;
42
41
  private get valueText();
43
42
  private get tooltipText();
44
43
  private findClusterMetadataLabel;
@@ -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, nothing } from "lit";
7
+ import { html } from "lit";
8
8
  import { property, state } from "lit/decorators.js";
9
9
  import { ClusteringHelper, redux } from "@fluid-topics/ft-wc-utils";
10
10
  import { styles } from "./ft-search-result-metadata.css";
@@ -26,7 +26,6 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
26
26
  this.editorMode = false;
27
27
  this.metadataDescriptors = [];
28
28
  this.clustersByValue = {};
29
- this.clusters = [];
30
29
  this.addStore(ftAppInfoStore);
31
30
  this.addI18nContext(searchResultMetadataContext);
32
31
  }
@@ -37,12 +36,20 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
37
36
  }
38
37
  }
39
38
  render() {
40
- return html `
41
- ${this.displayCluster ? this.renderClusterList() : this.renderChip()}
42
- ${this.hideIfEmpty()}
43
- `;
39
+ var _a;
40
+ if (this.valueText.length == 0 && ((_a = this.clusterItems) === null || _a === void 0 ? void 0 : _a.length) == 0 && !this.editorMode) {
41
+ return html `
42
+ <style>
43
+ :host {
44
+ display: none !important;
45
+ }
46
+ </style>
47
+ `;
48
+ }
49
+ return this.displayCluster ? this.renderClusterList() : this.renderChip();
44
50
  }
45
51
  renderClusterList() {
52
+ var _a;
46
53
  return html `
47
54
  <div class="ft-search-result-metadata--container">
48
55
  <ft-floating-menu icon="THIN_ARROW"
@@ -50,23 +57,11 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
50
57
  slot="button">
51
58
  ${this.renderChip("toggle")}
52
59
  <ft-floating-menu-label>${this.metadataLabel}</ft-floating-menu-label>
53
- ${repeat(this.clusters, cluster => cluster.metadata.value, cluster => this.renderClusterItem(cluster.result, cluster.metadata))}
60
+ ${repeat((_a = this.clusterItems) !== null && _a !== void 0 ? _a : [], item => item.metadata.value, item => this.renderClusterItem(item.result, item.metadata))}
54
61
  </ft-floating-menu>
55
62
  </div>
56
63
  `;
57
64
  }
58
- hideIfEmpty() {
59
- if (this.valueText.length == 0 && this.clusters.length == 0 && !this.editorMode) {
60
- return html `
61
- <style>
62
- :host {
63
- display: none !important;
64
- }
65
- </style>
66
- `;
67
- }
68
- return nothing;
69
- }
70
65
  onClusterSelected(e) {
71
66
  var _a;
72
67
  (_a = this.resultStateManager) === null || _a === void 0 ? void 0 : _a.selectResult(this.clustersByValue[e.detail].result);
@@ -75,8 +70,8 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
75
70
  var _a, _b;
76
71
  const clustersByValue = {};
77
72
  const clusteringHelper = new ClusteringHelper((_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries, this.result, this.resultStateManager.registeredMetadata, this.metadataDescriptors);
78
- this.clusters = clusteringHelper.computeClustersItemsForMetadata(this.key, ((_b = this.request) === null || _b === void 0 ? void 0 : _b.contentLocale) || "en");
79
- this.clusters.forEach(item => {
73
+ this.clusterItems = clusteringHelper.computeClustersItemsForMetadata(this.key, ((_b = this.request) === null || _b === void 0 ? void 0 : _b.contentLocale) || "en");
74
+ this.clusterItems.forEach(item => {
80
75
  clustersByValue[item.metadata.value] = item;
81
76
  });
82
77
  this.clustersByValue = clustersByValue;
@@ -156,7 +151,7 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
156
151
  var _a, _b, _c, _d, _e;
157
152
  super.update(props);
158
153
  if ((props.has("result") || props.has("key")) && this.result) {
159
- this.resultMetadata = (_a = this.resultData) === null || _a === void 0 ? void 0 : _a.metadata.find(m => m.key == this.key);
154
+ this.resultMetadata = (_a = this.resultData()) === null || _a === void 0 ? void 0 : _a.metadata.find(m => m.key == this.key);
160
155
  this.metadataLabel = this.findClusterMetadataLabel();
161
156
  }
162
157
  if (props.has("key") && this.useAsClusterSwitch) {
@@ -180,9 +175,10 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
180
175
  this.computeClusters();
181
176
  }
182
177
  }
183
- get resultData() {
184
- var _a, _b, _c, _d, _e;
185
- return (_d = (_b = (_a = this.result) === null || _a === void 0 ? void 0 : _a.map) !== null && _b !== void 0 ? _b : (_c = this.result) === null || _c === void 0 ? void 0 : _c.topic) !== null && _d !== void 0 ? _d : (_e = this.result) === null || _e === void 0 ? void 0 : _e.document;
178
+ resultData(result) {
179
+ var _a, _b;
180
+ result = result !== null && result !== void 0 ? result : this.result;
181
+ return (_b = (_a = result === null || result === void 0 ? void 0 : result.map) !== null && _a !== void 0 ? _a : result === null || result === void 0 ? void 0 : result.topic) !== null && _b !== void 0 ? _b : result === null || result === void 0 ? void 0 : result.document;
186
182
  }
187
183
  get valueText() {
188
184
  var _a, _b;
@@ -199,7 +195,7 @@ class FtSearchResultMetadata extends withI18n(FtSearchResultComponent) {
199
195
  }
200
196
  findClusterMetadataLabel() {
201
197
  var _a;
202
- const metadata = (_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries.flatMap(result => { var _a, _b; return ((_b = (_a = result === null || result === void 0 ? void 0 : result.map) !== null && _a !== void 0 ? _a : result === null || result === void 0 ? void 0 : result.document) !== null && _b !== void 0 ? _b : result === null || result === void 0 ? void 0 : result.topic).metadata.filter(m => m.key == this.key); })[0];
198
+ const metadata = (_a = this.cluster) === null || _a === void 0 ? void 0 : _a.entries.flatMap(result => this.resultData(result).metadata.filter(m => m.key == this.key))[0];
203
199
  return metadata === null || metadata === void 0 ? void 0 : metadata.label;
204
200
  }
205
201
  }
@@ -246,5 +242,5 @@ __decorate([
246
242
  ], FtSearchResultMetadata.prototype, "clustersByValue", void 0);
247
243
  __decorate([
248
244
  state()
249
- ], FtSearchResultMetadata.prototype, "clusters", void 0);
245
+ ], FtSearchResultMetadata.prototype, "clusterItems", void 0);
250
246
  export { FtSearchResultMetadata };