@fluid-topics/ft-search-saved-searches 1.0.23
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.
- package/README.md +26 -0
- package/build/ft-search-saved-search.d.ts +27 -0
- package/build/ft-search-saved-search.js +169 -0
- package/build/ft-search-saved-searches.css.d.ts +15 -0
- package/build/ft-search-saved-searches.css.js +27 -0
- package/build/ft-search-saved-searches.d.ts +30 -0
- package/build/ft-search-saved-searches.js +151 -0
- package/build/ft-search-saved-searches.light.js +899 -0
- package/build/ft-search-saved-searches.min.js +1026 -0
- package/build/ft-search-saved-searches.properties.d.ts +6 -0
- package/build/ft-search-saved-searches.properties.js +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.js +6 -0
- package/build/utils/SavedSearchesComponentMessages.d.ts +6 -0
- package/build/utils/SavedSearchesComponentMessages.js +17 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Displays the saved searches
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```shell
|
|
6
|
+
npm install @fluid-topics/ft-search-saved-searches
|
|
7
|
+
yarn add @fluid-topics/ft-search-saved-searches
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { html } from "lit"
|
|
14
|
+
import "@fluid-topics/ft-search-saved-searches"
|
|
15
|
+
|
|
16
|
+
function render() {
|
|
17
|
+
return html`<ft-search-context>
|
|
18
|
+
<ft-search-saved-searches
|
|
19
|
+
showDescription
|
|
20
|
+
showSearchFilters
|
|
21
|
+
showSearchButton
|
|
22
|
+
showAlertStatus
|
|
23
|
+
></ft-search-saved-searches>
|
|
24
|
+
</ft-search-context>`
|
|
25
|
+
}
|
|
26
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
2
|
+
import { FtMySearch } from "@fluid-topics/public-api";
|
|
3
|
+
import "@fluid-topics/ft-card";
|
|
4
|
+
import "@fluid-topics/ft-icon";
|
|
5
|
+
import "@fluid-topics/ft-button";
|
|
6
|
+
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
7
|
+
declare const FtSearchSavedSearch_base: typeof FtSearchComponent & (new (...args: any[]) => import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface);
|
|
8
|
+
export declare class FtSearchSavedSearch extends FtSearchSavedSearch_base {
|
|
9
|
+
search?: FtMySearch;
|
|
10
|
+
showDescription: boolean;
|
|
11
|
+
showSearchFilters: boolean;
|
|
12
|
+
showSearchButton: boolean;
|
|
13
|
+
showAlertStatus: boolean;
|
|
14
|
+
selected: boolean;
|
|
15
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
16
|
+
constructor();
|
|
17
|
+
static styles: import("lit").CSSResult;
|
|
18
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
19
|
+
private renderDescription;
|
|
20
|
+
private renderSearchButton;
|
|
21
|
+
private renderAlertStatus;
|
|
22
|
+
private renderSearchFilters;
|
|
23
|
+
private renderMetadata;
|
|
24
|
+
private mapSortKey;
|
|
25
|
+
private mapPeriodFilter;
|
|
26
|
+
}
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html, nothing, css } from "lit";
|
|
8
|
+
import { property } from "lit/decorators.js";
|
|
9
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
10
|
+
import "@fluid-topics/ft-card";
|
|
11
|
+
import "@fluid-topics/ft-icon";
|
|
12
|
+
import "@fluid-topics/ft-button";
|
|
13
|
+
import { FtIcon } from "@fluid-topics/ft-icon";
|
|
14
|
+
import { FtCard, FtCardCssVariables } from "@fluid-topics/ft-card";
|
|
15
|
+
import { FtButton, FtButtonCssVariables } from "@fluid-topics/ft-button";
|
|
16
|
+
import { setVariable } from "@fluid-topics/ft-wc-utils";
|
|
17
|
+
import { FtSearchSavedSearchesCssVariables } from "./ft-search-saved-searches.css";
|
|
18
|
+
import { FtRippleCssVariables } from "@fluid-topics/ft-ripple";
|
|
19
|
+
import { withI18n } from "@fluid-topics/ft-i18n";
|
|
20
|
+
import { defaultSavedSearchesMessages, savedSearches } from "./utils/SavedSearchesComponentMessages";
|
|
21
|
+
import { FtChip } from "@fluid-topics/ft-chip";
|
|
22
|
+
class FtSearchSavedSearch extends withI18n(FtSearchComponent) {
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.showDescription = false;
|
|
26
|
+
this.showSearchFilters = false;
|
|
27
|
+
this.showSearchButton = false;
|
|
28
|
+
this.showAlertStatus = false;
|
|
29
|
+
this.selected = false;
|
|
30
|
+
this.addI18nContext(savedSearches, defaultSavedSearchesMessages);
|
|
31
|
+
}
|
|
32
|
+
render() {
|
|
33
|
+
var _a;
|
|
34
|
+
return html `
|
|
35
|
+
<ft-card title="${(_a = this.search) === null || _a === void 0 ? void 0 : _a.title}" clickable ?selected="${this.selected}">
|
|
36
|
+
${this.renderAlertStatus()}
|
|
37
|
+
<div id="container">
|
|
38
|
+
${this.renderDescription()}
|
|
39
|
+
${this.renderSearchFilters()}
|
|
40
|
+
${this.renderSearchButton()}
|
|
41
|
+
</div>
|
|
42
|
+
</ft-card>
|
|
43
|
+
`;
|
|
44
|
+
}
|
|
45
|
+
renderDescription() {
|
|
46
|
+
var _a;
|
|
47
|
+
return this.showDescription ? html `<div id="description" class="content">${(_a = this.search) === null || _a === void 0 ? void 0 : _a.description}</div>` : nothing;
|
|
48
|
+
}
|
|
49
|
+
renderSearchButton() {
|
|
50
|
+
return this.showSearchButton ? html `<div id="searchButton" class="content"><ft-button id="search" icon="search">${savedSearches.messages.search()}</ft-button></div>` : nothing;
|
|
51
|
+
}
|
|
52
|
+
renderAlertStatus() {
|
|
53
|
+
var _a;
|
|
54
|
+
return this.showAlertStatus && ((_a = this.search) === null || _a === void 0 ? void 0 : _a.alert) ? html `<ft-icon id="alertStatus" slot="header">alert</ft-icon>` : nothing;
|
|
55
|
+
}
|
|
56
|
+
// See net.antidot.fluidtopics.client.application.mylibrary.shared.MyLibraryTagWidgetFactory.createMySearchTags
|
|
57
|
+
renderSearchFilters() {
|
|
58
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
59
|
+
return this.showSearchFilters ? html `<div id="searchFilters" class="content">
|
|
60
|
+
${((_b = (_a = this.search) === null || _a === void 0 ? void 0 : _a.searchRequest.query.length) !== null && _b !== void 0 ? _b : 0 > 0) ? this.renderMetadata(savedSearches.messages.keywords(), (_c = this.search) === null || _c === void 0 ? void 0 : _c.searchRequest.query, true) : nothing}
|
|
61
|
+
${(_d = this.search) === null || _d === void 0 ? void 0 : _d.searchRequest.filters.map(f => this.renderMetadata(f.label, f.values))}
|
|
62
|
+
${((_g = (_f = (_e = this.search) === null || _e === void 0 ? void 0 : _e.searchRequest.contentLocale) === null || _f === void 0 ? void 0 : _f.length) !== null && _g !== void 0 ? _g : 0 > 0) ? this.renderMetadata(savedSearches.messages.language(), (_h = this.search) === null || _h === void 0 ? void 0 : _h.searchRequest.contentLocale, true) : nothing}
|
|
63
|
+
${((_l = (_k = (_j = this.search) === null || _j === void 0 ? void 0 : _j.searchRequest.sort[0]) === null || _k === void 0 ? void 0 : _k.key.length) !== null && _l !== void 0 ? _l : 0 > 0) ? this.renderMetadata(savedSearches.messages.sort(), this.mapSortKey((_m = this.search) === null || _m === void 0 ? void 0 : _m.searchRequest.sort[0].key), true) : nothing}
|
|
64
|
+
${((_o = this.search) === null || _o === void 0 ? void 0 : _o.searchRequest.periodFilter) ? this.renderMetadata(savedSearches.messages.period(), this.mapPeriodFilter((_p = this.search) === null || _p === void 0 ? void 0 : _p.searchRequest.periodFilter), true) : nothing}
|
|
65
|
+
</div>` : nothing;
|
|
66
|
+
}
|
|
67
|
+
renderMetadata(key, values, highlighted = false) {
|
|
68
|
+
return html `<ft-chip dense ?highlighted=${highlighted}><span class="metadata-label">${key}</span><span class="metadata-values">${Array.isArray(values) ? values.join(", ") : values}</span></ft-chip>`;
|
|
69
|
+
}
|
|
70
|
+
mapSortKey(key) {
|
|
71
|
+
switch (key) {
|
|
72
|
+
case "afs:relevance":
|
|
73
|
+
return savedSearches.messages.relevance();
|
|
74
|
+
case "ft:lastEdition":
|
|
75
|
+
return savedSearches.messages.lastUpdate();
|
|
76
|
+
default:
|
|
77
|
+
return key;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
mapPeriodFilter(periodFilter) {
|
|
81
|
+
switch (periodFilter.periodType) {
|
|
82
|
+
case "LAST_WEEK":
|
|
83
|
+
return savedSearches.messages.lastWeek();
|
|
84
|
+
case "LAST_MONTH":
|
|
85
|
+
return savedSearches.messages.lastMonth();
|
|
86
|
+
case "LAST_YEAR":
|
|
87
|
+
return savedSearches.messages.lastYear();
|
|
88
|
+
case "CUSTOM":
|
|
89
|
+
return savedSearches.messages.customPeriod();
|
|
90
|
+
default:
|
|
91
|
+
return "--";
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
FtSearchSavedSearch.elementDefinitions = {
|
|
96
|
+
"ft-icon": FtIcon,
|
|
97
|
+
"ft-card": FtCard,
|
|
98
|
+
"ft-chip": FtChip,
|
|
99
|
+
"ft-button": FtButton
|
|
100
|
+
};
|
|
101
|
+
FtSearchSavedSearch.styles = css `
|
|
102
|
+
ft-card {
|
|
103
|
+
${setVariable(FtCardCssVariables.outlineStyle, FtSearchSavedSearchesCssVariables.inactiveSearchBorderStyle)};
|
|
104
|
+
${setVariable(FtCardCssVariables.outlineWidth, FtSearchSavedSearchesCssVariables.inactiveSearchBorderWidth)};
|
|
105
|
+
${setVariable(FtCardCssVariables.outlineColor, FtSearchSavedSearchesCssVariables.inactiveSearchBorderColor)};
|
|
106
|
+
${setVariable(FtCardCssVariables.borderRadius, FtSearchSavedSearchesCssVariables.inactiveSearchBorderRadius)};
|
|
107
|
+
${setVariable(FtCardCssVariables.selectedOutlineStyle, FtSearchSavedSearchesCssVariables.activeSearchBorderStyle)};
|
|
108
|
+
${setVariable(FtCardCssVariables.selectedOutlineWidth, FtSearchSavedSearchesCssVariables.activeSearchBorderWidth)};
|
|
109
|
+
${setVariable(FtCardCssVariables.selectedOutlineColor, FtSearchSavedSearchesCssVariables.activeSearchBorderColor)};
|
|
110
|
+
${setVariable(FtCardCssVariables.selectedBorderRadius, FtSearchSavedSearchesCssVariables.activeSearchBorderRadius)};
|
|
111
|
+
${setVariable(FtRippleCssVariables.backgroundColor, FtSearchSavedSearchesCssVariables.inactiveSearchBackgroundColor)};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
ft-card[selected] {
|
|
115
|
+
${setVariable(FtRippleCssVariables.backgroundColor, FtSearchSavedSearchesCssVariables.activeSearchBackgroundColor)};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
#search {
|
|
119
|
+
${setVariable(FtButtonCssVariables.color, FtSearchSavedSearchesCssVariables.inactiveButtonTextColor)};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
ft-card[selected] #search {
|
|
123
|
+
${setVariable(FtButtonCssVariables.color, FtSearchSavedSearchesCssVariables.activeButtonTextColor)};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#searchFilters {
|
|
127
|
+
display: flex;
|
|
128
|
+
gap: 4px;
|
|
129
|
+
flex-wrap: wrap;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.content {
|
|
133
|
+
margin-bottom: 8px;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
.content:last-child {
|
|
137
|
+
margin-bottom: 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
ft-card::part(header) {
|
|
141
|
+
display: flex;
|
|
142
|
+
justify-content: space-between;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.metadata-label:after {
|
|
146
|
+
content: ":";
|
|
147
|
+
margin-right: 0.4em;
|
|
148
|
+
margin-left: 0.2em;
|
|
149
|
+
}
|
|
150
|
+
`;
|
|
151
|
+
__decorate([
|
|
152
|
+
property()
|
|
153
|
+
], FtSearchSavedSearch.prototype, "search", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
property({ type: Boolean })
|
|
156
|
+
], FtSearchSavedSearch.prototype, "showDescription", void 0);
|
|
157
|
+
__decorate([
|
|
158
|
+
property({ type: Boolean })
|
|
159
|
+
], FtSearchSavedSearch.prototype, "showSearchFilters", void 0);
|
|
160
|
+
__decorate([
|
|
161
|
+
property({ type: Boolean })
|
|
162
|
+
], FtSearchSavedSearch.prototype, "showSearchButton", void 0);
|
|
163
|
+
__decorate([
|
|
164
|
+
property({ type: Boolean })
|
|
165
|
+
], FtSearchSavedSearch.prototype, "showAlertStatus", void 0);
|
|
166
|
+
__decorate([
|
|
167
|
+
property({ type: Boolean })
|
|
168
|
+
], FtSearchSavedSearch.prototype, "selected", void 0);
|
|
169
|
+
export { FtSearchSavedSearch };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const FtSearchSavedSearchesCssVariables: {
|
|
2
|
+
activeButtonTextColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
3
|
+
activeSearchBackgroundColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
4
|
+
activeSearchBorderStyle: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
5
|
+
activeSearchBorderColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
6
|
+
activeSearchBorderWidth: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
7
|
+
activeSearchBorderRadius: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
8
|
+
inactiveButtonTextColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
9
|
+
inactiveSearchBackgroundColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
10
|
+
inactiveSearchBorderStyle: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
11
|
+
inactiveSearchBorderColor: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
12
|
+
inactiveSearchBorderWidth: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
13
|
+
inactiveSearchBorderRadius: import("@fluid-topics/ft-wc-utils").FtCssVariable;
|
|
14
|
+
};
|
|
15
|
+
export declare const styles: import("lit").CSSResult;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var _a, _b, _c, _d;
|
|
2
|
+
import { css } from "lit";
|
|
3
|
+
import { designSystemVariables, FtCssVariableFactory } from "@fluid-topics/ft-wc-utils";
|
|
4
|
+
import { FtCardCssVariables } from "@fluid-topics/ft-card";
|
|
5
|
+
export const FtSearchSavedSearchesCssVariables = {
|
|
6
|
+
activeButtonTextColor: FtCssVariableFactory.extend("--ft-search-saved-searches-active-button-text-color", designSystemVariables.colorPrimary),
|
|
7
|
+
activeSearchBackgroundColor: FtCssVariableFactory.extend("--ft-search-saved-searches-active-search-background-color", designSystemVariables.colorContent),
|
|
8
|
+
activeSearchBorderStyle: FtCssVariableFactory.create("--ft-search-saved-searches-active-search-border-style", "UNKNOWN", (_a = FtCardCssVariables.selectedOutlineStyle.lastResortDefaultValue()) !== null && _a !== void 0 ? _a : "solid"),
|
|
9
|
+
activeSearchBorderColor: FtCssVariableFactory.extend("--ft-search-saved-searches-active-search-border-color", designSystemVariables.colorPrimary),
|
|
10
|
+
activeSearchBorderWidth: FtCssVariableFactory.create("--ft-search-saved-searches-active-search-border-width", "SIZE", (_b = FtCardCssVariables.selectedOutlineWidth.lastResortDefaultValue()) !== null && _b !== void 0 ? _b : "2px"),
|
|
11
|
+
activeSearchBorderRadius: FtCssVariableFactory.extend("--ft-search-saved-searches-active-search-border-radius", designSystemVariables.borderRadiusM),
|
|
12
|
+
inactiveButtonTextColor: FtCssVariableFactory.extend("--ft-search-saved-searches-inactive-button-text-color", designSystemVariables.colorPrimary),
|
|
13
|
+
inactiveSearchBackgroundColor: FtCssVariableFactory.extend("--ft-search-saved-searches-inactive-search-background-color", designSystemVariables.colorContent),
|
|
14
|
+
inactiveSearchBorderStyle: FtCssVariableFactory.create("--ft-search-saved-searches-inactive-search-border-style", "UNKNOWN", (_c = FtCardCssVariables.outlineStyle.lastResortDefaultValue()) !== null && _c !== void 0 ? _c : "solid"),
|
|
15
|
+
inactiveSearchBorderColor: FtCssVariableFactory.extend("--ft-search-saved-searches-inactive-search-border-color", designSystemVariables.colorPrimary),
|
|
16
|
+
inactiveSearchBorderWidth: FtCssVariableFactory.create("--ft-search-saved-searches-inactive-search-border-width", "SIZE", (_d = FtCardCssVariables.outlineWidth.lastResortDefaultValue()) !== null && _d !== void 0 ? _d : "0"),
|
|
17
|
+
inactiveSearchBorderRadius: FtCssVariableFactory.extend("--ft-search-saved-searches-inactive-search-border-radius", designSystemVariables.borderRadiusM),
|
|
18
|
+
};
|
|
19
|
+
// language=CSS
|
|
20
|
+
export const styles = css `
|
|
21
|
+
#container {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
gap: 24px;
|
|
25
|
+
margin: 3px;
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { PropertyValues } from "lit";
|
|
2
|
+
import { ElementDefinitionsMap } from "@fluid-topics/ft-wc-utils";
|
|
3
|
+
import { FtSearchSavedSearchesProperties } from "./ft-search-saved-searches.properties";
|
|
4
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
5
|
+
declare const FtSearchSavedSearches_base: typeof FtSearchComponent & (new (...args: any[]) => import("@fluid-topics/ft-i18n").FtLitElementWithI18nInterface);
|
|
6
|
+
export declare class FtSearchSavedSearches extends FtSearchSavedSearches_base implements FtSearchSavedSearchesProperties {
|
|
7
|
+
static styles: import("lit").CSSResult;
|
|
8
|
+
showDescription: boolean;
|
|
9
|
+
showSearchFilters: boolean;
|
|
10
|
+
showSearchButton: boolean;
|
|
11
|
+
showAlertStatus: boolean;
|
|
12
|
+
private savedSearches?;
|
|
13
|
+
private user?;
|
|
14
|
+
private request?;
|
|
15
|
+
private editorMode;
|
|
16
|
+
private requiredRole;
|
|
17
|
+
static elementDefinitions: ElementDefinitionsMap;
|
|
18
|
+
constructor();
|
|
19
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
20
|
+
private get userHasRights();
|
|
21
|
+
private get isEmpty();
|
|
22
|
+
private isSelected;
|
|
23
|
+
private mapFtSearchSortCriterion;
|
|
24
|
+
private toFtSearchRequest;
|
|
25
|
+
private mapSearchFilter;
|
|
26
|
+
connectedCallback(): void;
|
|
27
|
+
private setSearch;
|
|
28
|
+
protected update(changedProperties: PropertyValues): void;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
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
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { html } from "lit";
|
|
8
|
+
import { property } from "lit/decorators.js";
|
|
9
|
+
import { deepEqual, redux } from "@fluid-topics/ft-wc-utils";
|
|
10
|
+
import { styles } from "./ft-search-saved-searches.css";
|
|
11
|
+
import { ftAppInfoStore } from "@fluid-topics/ft-app-context";
|
|
12
|
+
import { FtSearchSavedSearch } from "./ft-search-saved-search";
|
|
13
|
+
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
14
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
15
|
+
import { FtUserRole } from "@fluid-topics/public-api";
|
|
16
|
+
import { FtSearchComponent } from "@fluid-topics/ft-search-context/build/registration";
|
|
17
|
+
import { ftUserAssetsStore, userAssetsActions } from "@fluid-topics/ft-app-context/build/redux-stores/FtUserAssetsStore";
|
|
18
|
+
import { withI18n } from "@fluid-topics/ft-i18n";
|
|
19
|
+
import { defaultSavedSearchesMessages, savedSearches } from "./utils/SavedSearchesComponentMessages";
|
|
20
|
+
class FtSearchSavedSearches extends withI18n(FtSearchComponent) {
|
|
21
|
+
constructor() {
|
|
22
|
+
super();
|
|
23
|
+
this.showDescription = false;
|
|
24
|
+
this.showSearchFilters = false;
|
|
25
|
+
this.showSearchButton = false;
|
|
26
|
+
this.showAlertStatus = false;
|
|
27
|
+
this.editorMode = false;
|
|
28
|
+
this.requiredRole = FtUserRole.SAVED_SEARCH_USER;
|
|
29
|
+
this.addStore(ftAppInfoStore);
|
|
30
|
+
this.addStore(ftUserAssetsStore);
|
|
31
|
+
this.addI18nContext(savedSearches, defaultSavedSearchesMessages);
|
|
32
|
+
}
|
|
33
|
+
render() {
|
|
34
|
+
var _a;
|
|
35
|
+
if (this.editorMode && !this.userHasRights) {
|
|
36
|
+
return html `<ft-typography>${savedSearches.messages.missingRole(this.requiredRole)}</ft-typography>`;
|
|
37
|
+
}
|
|
38
|
+
else if (this.editorMode && this.isEmpty) {
|
|
39
|
+
return html `<ft-typography>${savedSearches.messages.displaySavedSearchesHere()}</ft-typography>`;
|
|
40
|
+
}
|
|
41
|
+
else if (this.userHasRights && !this.isEmpty) {
|
|
42
|
+
return html `
|
|
43
|
+
<div id="container">
|
|
44
|
+
${repeat((_a = this.savedSearches) !== null && _a !== void 0 ? _a : [], s => s.id, s => html `
|
|
45
|
+
<ft-search-saved-search
|
|
46
|
+
.search=${s}
|
|
47
|
+
?showDescription=${this.showDescription}
|
|
48
|
+
?showSearchFilters=${this.showSearchFilters}
|
|
49
|
+
?showSearchButton=${this.showSearchButton}
|
|
50
|
+
?showAlertStatus=${this.showAlertStatus}
|
|
51
|
+
?selected=${this.isSelected(s.searchRequest)}
|
|
52
|
+
@click=${(e) => this.setSearch(s.searchRequest)}
|
|
53
|
+
></ft-search-saved-search>`)}
|
|
54
|
+
</div>
|
|
55
|
+
`;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return html `
|
|
59
|
+
<style>
|
|
60
|
+
:host {
|
|
61
|
+
display: none !important;
|
|
62
|
+
}
|
|
63
|
+
</style>
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
get userHasRights() {
|
|
68
|
+
var _a;
|
|
69
|
+
return !!((_a = this.user) === null || _a === void 0 ? void 0 : _a.roles.includes(this.requiredRole));
|
|
70
|
+
}
|
|
71
|
+
get isEmpty() {
|
|
72
|
+
var _a;
|
|
73
|
+
return ((_a = this.savedSearches) !== null && _a !== void 0 ? _a : []).length == 0;
|
|
74
|
+
}
|
|
75
|
+
isSelected(mySearchRequest) {
|
|
76
|
+
var _a;
|
|
77
|
+
const request = (_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.store.getState().request;
|
|
78
|
+
return request != undefined
|
|
79
|
+
&& deepEqual(request.query, mySearchRequest.query)
|
|
80
|
+
&& deepEqual([...request.filters], [...mySearchRequest.filters])
|
|
81
|
+
&& deepEqual([...request.sort].map(this.mapFtSearchSortCriterion), [...mySearchRequest.sort].map(this.mapFtSearchSortCriterion))
|
|
82
|
+
&& deepEqual(request.contentLocale, mySearchRequest.contentLocale)
|
|
83
|
+
&& deepEqual(request.periodFilter, mySearchRequest.periodFilter);
|
|
84
|
+
}
|
|
85
|
+
mapFtSearchSortCriterion(s) {
|
|
86
|
+
return { ...s };
|
|
87
|
+
}
|
|
88
|
+
toFtSearchRequest(mySearchRequest) {
|
|
89
|
+
return this.stateManager == undefined ? undefined : {
|
|
90
|
+
...this.stateManager.store.getState().request,
|
|
91
|
+
periodFilter: mySearchRequest.periodFilter,
|
|
92
|
+
query: mySearchRequest.query,
|
|
93
|
+
filters: mySearchRequest.filters.map(this.mapSearchFilter),
|
|
94
|
+
sort: mySearchRequest.sort,
|
|
95
|
+
contentLocale: mySearchRequest.contentLocale,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
mapSearchFilter(f) {
|
|
99
|
+
return { key: f.key,
|
|
100
|
+
values: f.values,
|
|
101
|
+
negative: f.negative
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
connectedCallback() {
|
|
105
|
+
super.connectedCallback();
|
|
106
|
+
userAssetsActions.reloadMySearches();
|
|
107
|
+
}
|
|
108
|
+
setSearch(mySearchRequest) {
|
|
109
|
+
var _a;
|
|
110
|
+
const ftSearchRequest = this.toFtSearchRequest(mySearchRequest);
|
|
111
|
+
if (ftSearchRequest != undefined)
|
|
112
|
+
(_a = this.stateManager) === null || _a === void 0 ? void 0 : _a.setRequest(ftSearchRequest);
|
|
113
|
+
}
|
|
114
|
+
update(changedProperties) {
|
|
115
|
+
super.update(changedProperties);
|
|
116
|
+
if ((changedProperties.has("user") || changedProperties.has("savedSearches"))
|
|
117
|
+
&& this.savedSearches == undefined) {
|
|
118
|
+
userAssetsActions.reloadMySearches();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
FtSearchSavedSearches.styles = styles;
|
|
123
|
+
FtSearchSavedSearches.elementDefinitions = {
|
|
124
|
+
"ft-search-saved-search": FtSearchSavedSearch,
|
|
125
|
+
"ft-typography": FtTypography
|
|
126
|
+
};
|
|
127
|
+
__decorate([
|
|
128
|
+
property({ type: Boolean })
|
|
129
|
+
], FtSearchSavedSearches.prototype, "showDescription", void 0);
|
|
130
|
+
__decorate([
|
|
131
|
+
property({ type: Boolean })
|
|
132
|
+
], FtSearchSavedSearches.prototype, "showSearchFilters", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
property({ type: Boolean })
|
|
135
|
+
], FtSearchSavedSearches.prototype, "showSearchButton", void 0);
|
|
136
|
+
__decorate([
|
|
137
|
+
property({ type: Boolean })
|
|
138
|
+
], FtSearchSavedSearches.prototype, "showAlertStatus", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
redux({ store: ftUserAssetsStore.name })
|
|
141
|
+
], FtSearchSavedSearches.prototype, "savedSearches", void 0);
|
|
142
|
+
__decorate([
|
|
143
|
+
redux({ store: ftAppInfoStore.name, selector: (s) => { var _a; return (_a = s.session) === null || _a === void 0 ? void 0 : _a.profile; } })
|
|
144
|
+
], FtSearchSavedSearches.prototype, "user", void 0);
|
|
145
|
+
__decorate([
|
|
146
|
+
redux({ store: "search" })
|
|
147
|
+
], FtSearchSavedSearches.prototype, "request", void 0);
|
|
148
|
+
__decorate([
|
|
149
|
+
redux({ store: ftAppInfoStore.name })
|
|
150
|
+
], FtSearchSavedSearches.prototype, "editorMode", void 0);
|
|
151
|
+
export { FtSearchSavedSearches };
|