@telia-ace/knowledge-widget-components-search 1.0.15 → 1.0.18
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/dist/index.js +140 -221
- package/dist/index.js.map +1 -1
- package/dist/search.ffb2e6c2.js +779 -0
- package/dist/search.ffb2e6c2.js.map +1 -0
- package/package.json +11 -7
- package/dist/search.js +0 -1063
- package/dist/search.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,234 +1,153 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
1
|
+
var R = Object.defineProperty, I = Object.defineProperties;
|
|
2
|
+
var D = Object.getOwnPropertyDescriptors;
|
|
3
|
+
var b = Object.getOwnPropertySymbols;
|
|
4
|
+
var O = Object.prototype.hasOwnProperty, j = Object.prototype.propertyIsEnumerable;
|
|
5
|
+
var T = (a, e, o) => e in a ? R(a, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : a[e] = o, u = (a, e) => {
|
|
6
|
+
for (var o in e || (e = {}))
|
|
7
|
+
O.call(e, o) && T(a, o, e[o]);
|
|
8
|
+
if (b)
|
|
9
|
+
for (var o of b(e))
|
|
10
|
+
j.call(e, o) && T(a, o, e[o]);
|
|
17
11
|
return a;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const trailIds = categoryTrail(categoryId, categories);
|
|
29
|
-
const categoryMap = getCategoryTrailAsObjects(trailIds, categories);
|
|
30
|
-
const trail = trailIds.map((id) => {
|
|
31
|
-
var _a;
|
|
32
|
-
return ((_a = categoryMap.get(id)) == null ? void 0 : _a.title) || "";
|
|
12
|
+
}, h = (a, e) => I(a, D(e));
|
|
13
|
+
import { createEventSubscriber as F } from "@telia-ace/knowledge-widget-core";
|
|
14
|
+
import { DataType as A } from "@telia-ace/knowledge-widget-types-grid";
|
|
15
|
+
import { createReactComponent as x } from "@telia-ace/knowledge-widget-ui";
|
|
16
|
+
import { createParams as E, findCategoryById as G, deepClone as p, categoryTrail as M, getCategoryTrailAsObjects as S } from "@telia-ace/widget-utilities";
|
|
17
|
+
const B = (a) => !!a.guideCategory || !!a.tag, H = (a, e) => {
|
|
18
|
+
const o = M(a, e), f = S(o, e);
|
|
19
|
+
return o.map((C) => {
|
|
20
|
+
var y;
|
|
21
|
+
return ((y = f.get(C)) == null ? void 0 : y.title) || "";
|
|
33
22
|
}).join(" / ");
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
return clone;
|
|
50
|
-
};
|
|
51
|
-
const SearchComponent = (container) => {
|
|
52
|
-
return createReactComponent(container, "search", import("./search.js"), (component) => {
|
|
53
|
-
const { events } = container.get("$widget");
|
|
54
|
-
const [subscribe, unsubscribe] = createEventSubscriber(events);
|
|
55
|
-
const load = (params) => {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
const { activeFilterBadges } = component.properties();
|
|
58
|
-
if (((_a = activeFilterBadges == null ? void 0 : activeFilterBadges.guideCategory) == null ? void 0 : _a.id) !== params.guideCategory || ((_b = activeFilterBadges == null ? void 0 : activeFilterBadges.tag) == null ? void 0 : _b.id) !== params.tag) {
|
|
59
|
-
component.actions.dispatch("quick-filter:add", {
|
|
60
|
-
tag: params.tag,
|
|
61
|
-
category: params.guideCategory,
|
|
62
|
-
initial: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
component.actions.create("search", (data) => {
|
|
67
|
-
const { value, filters, filtersChanged } = data;
|
|
68
|
-
const { route = "search", patchParams = false } = component.properties();
|
|
69
|
-
if (value.length > 0 || (hasActiveFilterBadge(filters) || filtersChanged) && !(filters == null ? void 0 : filters.initial)) {
|
|
70
|
-
container.getAsync("router").then((router) => {
|
|
71
|
-
var _a, _b;
|
|
72
|
-
const { params } = router.getRouteData();
|
|
73
|
-
let searchParams = {
|
|
74
|
-
guide: void 0,
|
|
75
|
-
id: void 0,
|
|
76
|
-
accordion: void 0,
|
|
77
|
-
contactMethod: void 0
|
|
78
|
-
};
|
|
79
|
-
searchParams.phrase = value.length > 0 ? encodeURIComponent(value) : "";
|
|
80
|
-
if (patchParams) {
|
|
81
|
-
searchParams = __spreadValues(__spreadValues({}, params), searchParams);
|
|
82
|
-
}
|
|
83
|
-
if ((filters == null ? void 0 : filters.guideCategory) || filtersChanged) {
|
|
84
|
-
searchParams.guideCategory = ((_a = filters.guideCategory) == null ? void 0 : _a.id) || void 0;
|
|
85
|
-
}
|
|
86
|
-
if ((filters == null ? void 0 : filters.tag) || filtersChanged) {
|
|
87
|
-
searchParams.tag = ((_b = filters.tag) == null ? void 0 : _b.id) || void 0;
|
|
88
|
-
}
|
|
89
|
-
router.navigate(route, createParams(searchParams));
|
|
90
|
-
});
|
|
91
|
-
}
|
|
23
|
+
}, v = (a) => {
|
|
24
|
+
const e = p(a);
|
|
25
|
+
return e.sort((o, f) => o.title > f.title ? 1 : -1), e.forEach((o) => {
|
|
26
|
+
o.items && (o.items = v(o.items));
|
|
27
|
+
}), e;
|
|
28
|
+
}, K = (a) => x(a, "search", import("./search.ffb2e6c2.js"), (e) => {
|
|
29
|
+
const { events: o } = a.get("$widget"), [f, P] = F(o), C = (i) => {
|
|
30
|
+
var r, n;
|
|
31
|
+
const { activeFilterBadges: t } = e.properties();
|
|
32
|
+
(((r = t == null ? void 0 : t.guideCategory) == null ? void 0 : r.id) !== i.guideCategory || ((n = t == null ? void 0 : t.tag) == null ? void 0 : n.id) !== i.tag) && e.actions.dispatch("quick-filter:add", {
|
|
33
|
+
tag: i.tag,
|
|
34
|
+
category: i.guideCategory,
|
|
35
|
+
initial: !0
|
|
92
36
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const { activeFilterBadges: previous } = component.properties();
|
|
105
|
-
const activeFilterBadges = previous || {
|
|
106
|
-
initial,
|
|
107
|
-
guideCategory: null,
|
|
108
|
-
tag: null,
|
|
109
|
-
tooltip: null
|
|
37
|
+
};
|
|
38
|
+
e.actions.create("search", (i) => {
|
|
39
|
+
const { value: t, filters: r, filtersChanged: n } = i, { route: c = "search", patchParams: g = !1 } = e.properties();
|
|
40
|
+
(t.length > 0 || (B(r) || n) && !(r != null && r.initial)) && a.getAsync("router").then((s) => {
|
|
41
|
+
var q, w;
|
|
42
|
+
const { params: d } = s.getRouteData();
|
|
43
|
+
let l = {
|
|
44
|
+
guide: void 0,
|
|
45
|
+
id: void 0,
|
|
46
|
+
accordion: void 0,
|
|
47
|
+
contactMethod: void 0
|
|
110
48
|
};
|
|
111
|
-
|
|
112
|
-
if (category) {
|
|
113
|
-
return fetchCategories({}).then((categories) => {
|
|
114
|
-
const categoryItem = findCategoryById(category, categories) || null;
|
|
115
|
-
return __spreadProps(__spreadValues({}, activeFilterBadges), {
|
|
116
|
-
guideCategory: categoryItem,
|
|
117
|
-
tooltip: getTooltip(category, categories) || null
|
|
118
|
-
});
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
return __spreadProps(__spreadValues({}, activeFilterBadges), {
|
|
122
|
-
guideCategory: null,
|
|
123
|
-
tooltip: null
|
|
124
|
-
});
|
|
125
|
-
}).then((next) => {
|
|
126
|
-
if (tag) {
|
|
127
|
-
return fetchTags({}).then((tags) => {
|
|
128
|
-
return __spreadProps(__spreadValues({}, next), {
|
|
129
|
-
tag: tags.find((t) => t.id === tag) || null
|
|
130
|
-
});
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return __spreadProps(__spreadValues({}, next), {
|
|
134
|
-
tag: null
|
|
135
|
-
});
|
|
136
|
-
}).then((next) => {
|
|
137
|
-
return component.writeProperties({
|
|
138
|
-
activeFilterBadges: __spreadProps(__spreadValues({}, next), { initial: !!initial })
|
|
139
|
-
});
|
|
140
|
-
});
|
|
49
|
+
l.phrase = t.length > 0 ? encodeURIComponent(t) : "", g && (l = u(u({}, d), l)), ((r == null ? void 0 : r.guideCategory) || n) && (l.guideCategory = ((q = r.guideCategory) == null ? void 0 : q.id) || void 0), ((r == null ? void 0 : r.tag) || n) && (l.tag = ((w = r.tag) == null ? void 0 : w.id) || void 0), s.navigate(c, E(l));
|
|
141
50
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
initial: false,
|
|
147
|
-
guideCategory: types.indexOf("guideCategory") > -1 ? null : activeFilterBadges == null ? void 0 : activeFilterBadges.guideCategory,
|
|
148
|
-
tag: types.indexOf("tag") > -1 ? null : activeFilterBadges == null ? void 0 : activeFilterBadges.tag
|
|
149
|
-
})
|
|
150
|
-
});
|
|
51
|
+
}), e.actions.create("clear", (i, t) => {
|
|
52
|
+
i.navigateToHome && a.getAsync("router").then((r) => {
|
|
53
|
+
const { name: n } = r.getInitialRoute();
|
|
54
|
+
r.navigate(n);
|
|
151
55
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
56
|
+
});
|
|
57
|
+
const y = () => a.getAsync("router").then((i) => i.getRouteData().params);
|
|
58
|
+
e.actions.create("quick-filter:add", (i) => {
|
|
59
|
+
const { category: t, tag: r, initial: n } = i, { activeFilterBadges: c } = e.properties(), g = c || {
|
|
60
|
+
initial: n,
|
|
61
|
+
guideCategory: null,
|
|
62
|
+
tag: null,
|
|
63
|
+
tooltip: null
|
|
64
|
+
};
|
|
65
|
+
return Promise.resolve().then(() => t ? m({}).then((s) => {
|
|
66
|
+
const d = G(t, s) || null;
|
|
67
|
+
return h(u({}, g), {
|
|
68
|
+
guideCategory: d,
|
|
69
|
+
tooltip: H(t, s) || null
|
|
159
70
|
});
|
|
71
|
+
}) : h(u({}, g), {
|
|
72
|
+
guideCategory: null,
|
|
73
|
+
tooltip: null
|
|
74
|
+
})).then((s) => r ? k({}).then((d) => h(u({}, s), {
|
|
75
|
+
tag: d.find((l) => l.id === r) || null
|
|
76
|
+
})) : h(u({}, s), {
|
|
77
|
+
tag: null
|
|
78
|
+
})).then((s) => e.writeProperties({
|
|
79
|
+
activeFilterBadges: h(u({}, s), { initial: !!n })
|
|
80
|
+
}));
|
|
81
|
+
}), e.actions.create("quick-filter:remove", ({ types: i }) => {
|
|
82
|
+
const { activeFilterBadges: t } = e.properties();
|
|
83
|
+
e.writeProperties({
|
|
84
|
+
activeFilterBadges: h(u({}, t), {
|
|
85
|
+
initial: !1,
|
|
86
|
+
guideCategory: i.indexOf("guideCategory") > -1 ? null : t == null ? void 0 : t.guideCategory,
|
|
87
|
+
tag: i.indexOf("tag") > -1 ? null : t == null ? void 0 : t.tag
|
|
88
|
+
})
|
|
160
89
|
});
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
categories: guideCategory,
|
|
189
|
-
searchPhrase: phrase
|
|
190
|
-
}).then((items) => {
|
|
191
|
-
const clone = deepClone(items);
|
|
192
|
-
component.writeProperties({
|
|
193
|
-
quickFilter: {
|
|
194
|
-
items: sortRecursive(clone),
|
|
195
|
-
loading: false
|
|
196
|
-
}
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
}
|
|
90
|
+
}), e.actions.create("quick-filter:close", () => e.writeProperties({
|
|
91
|
+
quickFilter: {
|
|
92
|
+
items: [],
|
|
93
|
+
loading: !1,
|
|
94
|
+
open: !1
|
|
95
|
+
}
|
|
96
|
+
})), e.actions.create("quick-filter:open", ({ symbol: i, type: t }) => (e.writeProperties({
|
|
97
|
+
quickFilter: {
|
|
98
|
+
type: t,
|
|
99
|
+
symbol: i,
|
|
100
|
+
items: [],
|
|
101
|
+
loading: !0,
|
|
102
|
+
open: !0
|
|
103
|
+
}
|
|
104
|
+
}), y().then(({ tag: r, guideCategory: n, phrase: c }) => {
|
|
105
|
+
if (t === "guideCategory")
|
|
106
|
+
return m({
|
|
107
|
+
tagId: r,
|
|
108
|
+
searchPhrase: c
|
|
109
|
+
}).then((g) => {
|
|
110
|
+
const s = p(g);
|
|
111
|
+
e.writeProperties({
|
|
112
|
+
quickFilter: {
|
|
113
|
+
items: v(s),
|
|
114
|
+
loading: !1
|
|
115
|
+
}
|
|
116
|
+
});
|
|
200
117
|
});
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const {
|
|
213
|
-
routeData: { params }
|
|
214
|
-
} = current;
|
|
215
|
-
load(params);
|
|
216
|
-
});
|
|
217
|
-
subscribe("data-client:fetched", (event, data) => {
|
|
218
|
-
const { filterBadges } = component.properties();
|
|
219
|
-
const showTag = typeof filterBadges === "object" ? !!filterBadges.tag : !!filterBadges;
|
|
220
|
-
if (data.type === "match" && showTag) {
|
|
221
|
-
getRouterParams().then(({ tag: tagId }) => {
|
|
222
|
-
const { tags = [] } = data.response;
|
|
223
|
-
const tag = tags.find((t) => t.id === tagId) || null;
|
|
224
|
-
component.writeProperties({ filters: { tag } });
|
|
118
|
+
if (t === "tag")
|
|
119
|
+
return k({
|
|
120
|
+
categories: n,
|
|
121
|
+
searchPhrase: c
|
|
122
|
+
}).then((g) => {
|
|
123
|
+
const s = p(g);
|
|
124
|
+
e.writeProperties({
|
|
125
|
+
quickFilter: {
|
|
126
|
+
items: v(s),
|
|
127
|
+
loading: !1
|
|
128
|
+
}
|
|
225
129
|
});
|
|
226
|
-
}
|
|
130
|
+
});
|
|
131
|
+
})));
|
|
132
|
+
const m = (i) => a.getAsync("dataClient").then((t) => t.fetch(A.GuideCategories, i)).then((t) => t.categories || []), k = (i) => a.getAsync("dataClient").then((t) => t.fetch(A.TagsOnGuides, i)).then((t = []) => t);
|
|
133
|
+
return y().then((i) => {
|
|
134
|
+
C(i);
|
|
135
|
+
}), f("router:changed", (i, { current: t }) => {
|
|
136
|
+
const {
|
|
137
|
+
routeData: { params: r }
|
|
138
|
+
} = t;
|
|
139
|
+
C(r);
|
|
140
|
+
}), f("data-client:fetched", (i, t) => {
|
|
141
|
+
const { filterBadges: r } = e.properties(), n = typeof r == "object" ? !!r.tag : !!r;
|
|
142
|
+
t.type === "match" && n && y().then(({ tag: c }) => {
|
|
143
|
+
const { tags: g = [] } = t.response, s = g.find((d) => d.id === c) || null;
|
|
144
|
+
e.writeProperties({ filters: { tag: s } });
|
|
227
145
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
146
|
+
}), () => {
|
|
147
|
+
P();
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
export {
|
|
151
|
+
K as default
|
|
232
152
|
};
|
|
233
|
-
export { SearchComponent as default };
|
|
234
153
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/search-component.ts"],"sourcesContent":["import { Category, createEventSubscriber, Tag } from '@telia-ace/knowledge-widget-core';\r\nimport {\r\n CategoriesResult,\r\n DataClient,\r\n DataType,\r\n MatchResult,\r\n QueryParameters,\r\n TagsResult,\r\n} from '@telia-ace/knowledge-widget-types-grid';\r\nimport { createReactComponent } from '@telia-ace/knowledge-widget-ui';\r\nimport { RoutingService } from '@telia-ace/widget-routing';\r\nimport {\r\n categoryTrail,\r\n createParams,\r\n deepClone,\r\n findCategoryById,\r\n getCategoryTrailAsObjects,\r\n Params,\r\n} from '@telia-ace/widget-utilities';\r\nimport { Container } from '@webprovisions/platform';\r\n\r\nexport type SearchComponentProps = {\r\n route?: string;\r\n role?: string;\r\n\r\n showSearchButton: boolean;\r\n showClearButton: boolean;\r\n showChildren: boolean;\r\n\r\n searchButtonLabel: string;\r\n clearButtonLabel: string;\r\n ariaLabel?: string;\r\n\r\n placeholder: string;\r\n autoFocus: boolean;\r\n incremental?: boolean | number;\r\n\r\n filterBadges?: FilterConfig | boolean;\r\n activeFilterBadges?: ActiveFilterBadges; // internal\r\n deleteFilterBadgeAriaLabel?: string;\r\n\r\n quickFilters?: FilterConfig | boolean;\r\n quickFilter?: Filter; // internal\r\n\r\n patchParams?: boolean;\r\n};\r\n\r\nexport type Filter = {\r\n items?: Category[] | Tag[];\r\n type?: 'guideCategory' | 'tag';\r\n symbol?: string;\r\n loading: boolean;\r\n open: boolean;\r\n};\r\n\r\nexport type ActiveFilterBadges = {\r\n guideCategory?: Category | null;\r\n tag?: Tag | null;\r\n tooltip?: string | null;\r\n initial?: boolean;\r\n};\r\n\r\nexport type FilterConfig = {\r\n autoSelect?: boolean;\r\n guideCategory?: boolean;\r\n tag?: boolean;\r\n position?: 'inside' | 'below';\r\n};\r\n\r\nconst hasActiveFilterBadge = (filters: ActiveFilterBadges) => {\r\n return !!filters.guideCategory || !!filters.tag;\r\n};\r\n\r\nconst getTooltip = (categoryId: string, categories: Category[]) => {\r\n const trailIds: string[] = categoryTrail(categoryId, categories);\r\n const categoryMap = getCategoryTrailAsObjects(trailIds, categories);\r\n const trail = trailIds.map((id) => categoryMap.get(id)?.title || '').join(' / ');\r\n return trail;\r\n};\r\n\r\nconst sortRecursive = (items: any[]) => {\r\n const clone = deepClone(items);\r\n\r\n clone.sort((a: any, b: any) => {\r\n if (a.title > b.title) {\r\n return 1;\r\n }\r\n return -1;\r\n });\r\n\r\n clone.forEach((item: any) => {\r\n if (item.items) {\r\n item.items = sortRecursive(item.items);\r\n }\r\n });\r\n\r\n return clone;\r\n};\r\n\r\nconst SearchComponent = (container: Container) => {\r\n return createReactComponent(container, 'search', import('./search'), (component) => {\r\n const { events } = container.get('$widget');\r\n const [subscribe, unsubscribe] = createEventSubscriber(events);\r\n\r\n const load = (params: Params) => {\r\n const { activeFilterBadges } = component.properties<SearchComponentProps>();\r\n\r\n if (\r\n activeFilterBadges?.guideCategory?.id !== params.guideCategory ||\r\n activeFilterBadges?.tag?.id !== params.tag\r\n ) {\r\n component.actions.dispatch('quick-filter:add', {\r\n tag: params.tag,\r\n category: params.guideCategory,\r\n initial: true,\r\n });\r\n }\r\n };\r\n\r\n component.actions.create('search', (data) => {\r\n const { value, filters, filtersChanged } = data;\r\n const { route = 'search', patchParams = false } =\r\n component.properties<SearchComponentProps>();\r\n\r\n if (\r\n value.length > 0 ||\r\n ((hasActiveFilterBadge(filters) || filtersChanged) && !filters?.initial)\r\n ) {\r\n container.getAsync('router').then((router: RoutingService) => {\r\n const { params } = router.getRouteData();\r\n\r\n let searchParams: { [key: string]: string | undefined } = {\r\n guide: undefined,\r\n id: undefined,\r\n accordion: undefined,\r\n contactMethod: undefined,\r\n };\r\n\r\n searchParams.phrase = value.length > 0 ? encodeURIComponent(value) : '';\r\n\r\n if (patchParams) {\r\n searchParams = {\r\n ...params,\r\n ...searchParams,\r\n };\r\n }\r\n\r\n if (filters?.guideCategory || filtersChanged) {\r\n searchParams.guideCategory = filters.guideCategory?.id || undefined;\r\n }\r\n\r\n if (filters?.tag || filtersChanged) {\r\n searchParams.tag = filters.tag?.id || undefined;\r\n }\r\n\r\n router.navigate(route, createParams(searchParams));\r\n });\r\n }\r\n });\r\n\r\n component.actions.create('clear', (data, options) => {\r\n if (data.navigateToHome) {\r\n container.getAsync('router').then((router: RoutingService) => {\r\n const { name }: any = router.getInitialRoute();\r\n router.navigate(name);\r\n });\r\n }\r\n });\r\n\r\n const getRouterParams: () => Promise<Params> = () =>\r\n container\r\n .getAsync('router')\r\n .then((router: RoutingService) => router.getRouteData().params);\r\n\r\n component.actions.create(\r\n 'quick-filter:add',\r\n (data: { category?: string; tag?: string; initial?: boolean }) => {\r\n const { category, tag, initial } = data;\r\n const { activeFilterBadges: previous } =\r\n component.properties<SearchComponentProps>();\r\n\r\n const activeFilterBadges: ActiveFilterBadges = previous || {\r\n initial,\r\n guideCategory: null,\r\n tag: null,\r\n tooltip: null,\r\n };\r\n\r\n return Promise.resolve()\r\n .then(() => {\r\n if (category) {\r\n return fetchCategories({}).then((categories) => {\r\n const categoryItem =\r\n <Category | null>findCategoryById(category, categories) || null;\r\n return {\r\n ...activeFilterBadges,\r\n guideCategory: categoryItem,\r\n tooltip: getTooltip(category, categories) || null,\r\n };\r\n });\r\n }\r\n return {\r\n ...activeFilterBadges,\r\n guideCategory: null,\r\n tooltip: null,\r\n };\r\n })\r\n .then((next) => {\r\n if (tag) {\r\n return fetchTags({}).then((tags) => {\r\n return {\r\n ...next,\r\n tag: tags.find((t) => t.id === tag) || null,\r\n };\r\n });\r\n }\r\n return {\r\n ...next,\r\n tag: null,\r\n };\r\n })\r\n .then((next) => {\r\n return component.writeProperties({\r\n activeFilterBadges: { ...next, initial: !!initial },\r\n });\r\n });\r\n }\r\n );\r\n\r\n component.actions.create('quick-filter:remove', ({ types }: { types: string[] }) => {\r\n const { activeFilterBadges } = component.properties<SearchComponentProps>();\r\n\r\n component.writeProperties({\r\n activeFilterBadges: {\r\n ...activeFilterBadges,\r\n initial: false,\r\n guideCategory:\r\n types.indexOf('guideCategory') > -1\r\n ? null\r\n : activeFilterBadges?.guideCategory,\r\n tag: types.indexOf('tag') > -1 ? null : activeFilterBadges?.tag,\r\n },\r\n });\r\n });\r\n\r\n component.actions.create('quick-filter:close', () => {\r\n return component.writeProperties({\r\n quickFilter: {\r\n items: [],\r\n loading: false,\r\n open: false,\r\n },\r\n });\r\n });\r\n\r\n component.actions.create('quick-filter:open', ({ symbol, type }) => {\r\n component.writeProperties({\r\n quickFilter: {\r\n type,\r\n symbol,\r\n items: [],\r\n loading: true,\r\n open: true,\r\n },\r\n });\r\n\r\n return getRouterParams().then(({ tag, guideCategory, phrase }) => {\r\n if (type === 'guideCategory') {\r\n return fetchCategories({\r\n tagId: tag,\r\n searchPhrase: phrase,\r\n }).then((items) => {\r\n const clone = deepClone(items);\r\n\r\n component.writeProperties({\r\n quickFilter: {\r\n items: sortRecursive(clone),\r\n loading: false,\r\n },\r\n });\r\n });\r\n }\r\n\r\n if (type === 'tag') {\r\n return fetchTags({\r\n categories: guideCategory,\r\n searchPhrase: phrase,\r\n }).then((items) => {\r\n const clone = deepClone(items);\r\n component.writeProperties({\r\n quickFilter: {\r\n items: sortRecursive(clone),\r\n loading: false,\r\n },\r\n });\r\n });\r\n }\r\n });\r\n });\r\n\r\n const fetchCategories = (params: QueryParameters) => {\r\n return container\r\n .getAsync('dataClient')\r\n .then((dataClient: DataClient) =>\r\n dataClient.fetch(DataType.GuideCategories, params)\r\n )\r\n .then((categoriesResult: CategoriesResult) => categoriesResult.categories || []);\r\n };\r\n\r\n const fetchTags = (params: QueryParameters) => {\r\n return container\r\n .getAsync('dataClient')\r\n .then((dataClient: DataClient) => dataClient.fetch(DataType.TagsOnGuides, params))\r\n .then((tags: TagsResult = []) => tags);\r\n };\r\n\r\n getRouterParams().then((params) => {\r\n load(params);\r\n });\r\n\r\n subscribe('router:changed', (_, { current }) => {\r\n const {\r\n routeData: { params },\r\n } = current;\r\n load(params);\r\n });\r\n\r\n subscribe('data-client:fetched', (event, data) => {\r\n const { filterBadges } = component.properties<SearchComponentProps>();\r\n\r\n const showTag = typeof filterBadges === 'object' ? !!filterBadges.tag : !!filterBadges;\r\n\r\n if (data.type === 'match' && showTag) {\r\n getRouterParams().then(({ tag: tagId }) => {\r\n const { tags = [] }: MatchResult = data.response;\r\n const tag = tags.find((t) => t.id === tagId) || null;\r\n component.writeProperties({ filters: { tag } });\r\n });\r\n }\r\n });\r\n\r\n return () => {\r\n unsubscribe();\r\n };\r\n });\r\n};\r\n\r\nexport default SearchComponent;\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAqEA,MAAM,uBAAuB,CAAC,YAAgC;AAC1D,SAAO,CAAC,CAAC,QAAQ,iBAAiB,CAAC,CAAC,QAAQ;AAChD;AAEA,MAAM,aAAa,CAAC,YAAoB,eAA2B;AACzD,QAAA,WAAqB,cAAc,YAAY,UAAU;AACzD,QAAA,cAAc,0BAA0B,UAAU,UAAU;AAClE,QAAM,QAAQ,SAAS,IAAI,CAAC,OAAO;;AAAA,8BAAY,IAAI,EAAE,MAAlB,mBAAqB,UAAS;AAAA,GAAE,EAAE,KAAK,KAAK;AACxE,SAAA;AACX;AAEA,MAAM,gBAAgB,CAAC,UAAiB;AAC9B,QAAA,QAAQ,UAAU,KAAK;AAEvB,QAAA,KAAK,CAAC,GAAQ,MAAW;AACvB,QAAA,EAAE,QAAQ,EAAE,OAAO;AACZ,aAAA;AAAA,IACX;AACO,WAAA;AAAA,EAAA,CACV;AAEK,QAAA,QAAQ,CAAC,SAAc;AACzB,QAAI,KAAK,OAAO;AACP,WAAA,QAAQ,cAAc,KAAK,KAAK;AAAA,IACzC;AAAA,EAAA,CACH;AAEM,SAAA;AACX;AAEM,MAAA,kBAAkB,CAAC,cAAyB;AAC9C,SAAO,q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,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,OAAO,KAAK,KAAK;AAChD,oBAAU,gBAAgB,EAAE,SAAS,EAAE,IAAA,EAAO,CAAA;AAAA,QAAA,CACjD;AAAA,MACL;AAAA,IAAA,CACH;AAED,WAAO,MAAM;AACG;IAAA;AAAA,EAChB,CACH;AACL;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/search-component.ts"],"sourcesContent":["import { Category, createEventSubscriber, Tag } from '@telia-ace/knowledge-widget-core';\r\nimport {\r\n CategoriesResult,\r\n DataClient,\r\n DataType,\r\n MatchResult,\r\n QueryParameters,\r\n TagsResult,\r\n} from '@telia-ace/knowledge-widget-types-grid';\r\nimport { createReactComponent } from '@telia-ace/knowledge-widget-ui';\r\nimport { RoutingService } from '@telia-ace/widget-routing';\r\nimport {\r\n categoryTrail,\r\n createParams,\r\n deepClone,\r\n findCategoryById,\r\n getCategoryTrailAsObjects,\r\n Params,\r\n} from '@telia-ace/widget-utilities';\r\nimport { Container } from '@webprovisions/platform';\r\n\r\nexport type SearchComponentProps = {\r\n route?: string;\r\n role?: string;\r\n\r\n showSearchButton: boolean;\r\n showClearButton: boolean;\r\n showChildren: boolean;\r\n\r\n searchButtonLabel: string;\r\n clearButtonLabel: string;\r\n ariaLabel?: string;\r\n\r\n placeholder: string;\r\n autoFocus: boolean;\r\n incremental?: boolean | number;\r\n\r\n filterBadges?: FilterConfig | boolean;\r\n activeFilterBadges?: ActiveFilterBadges; // internal\r\n deleteFilterBadgeAriaLabel?: string;\r\n\r\n quickFilters?: FilterConfig | boolean;\r\n quickFilter?: Filter; // internal\r\n\r\n patchParams?: boolean;\r\n};\r\n\r\nexport type Filter = {\r\n items?: Category[] | Tag[];\r\n type?: 'guideCategory' | 'tag';\r\n symbol?: string;\r\n loading: boolean;\r\n open: boolean;\r\n};\r\n\r\nexport type ActiveFilterBadges = {\r\n guideCategory?: Category | null;\r\n tag?: Tag | null;\r\n tooltip?: string | null;\r\n initial?: boolean;\r\n};\r\n\r\nexport type FilterConfig = {\r\n autoSelect?: boolean;\r\n guideCategory?: boolean;\r\n tag?: boolean;\r\n position?: 'inside' | 'below';\r\n};\r\n\r\nconst hasActiveFilterBadge = (filters: ActiveFilterBadges) => {\r\n return !!filters.guideCategory || !!filters.tag;\r\n};\r\n\r\nconst getTooltip = (categoryId: string, categories: Category[]) => {\r\n const trailIds: string[] = categoryTrail(categoryId, categories);\r\n const categoryMap = getCategoryTrailAsObjects(trailIds, categories);\r\n const trail = trailIds.map((id) => categoryMap.get(id)?.title || '').join(' / ');\r\n return trail;\r\n};\r\n\r\nconst sortRecursive = (items: any[]) => {\r\n const clone = deepClone(items);\r\n\r\n clone.sort((a: any, b: any) => {\r\n if (a.title > b.title) {\r\n return 1;\r\n }\r\n return -1;\r\n });\r\n\r\n clone.forEach((item: any) => {\r\n if (item.items) {\r\n item.items = sortRecursive(item.items);\r\n }\r\n });\r\n\r\n return clone;\r\n};\r\n\r\nconst SearchComponent = (container: Container) => {\r\n return createReactComponent(container, 'search', import('./search'), (component) => {\r\n const { events } = container.get('$widget');\r\n const [subscribe, unsubscribe] = createEventSubscriber(events);\r\n\r\n const load = (params: Params) => {\r\n const { activeFilterBadges } = component.properties<SearchComponentProps>();\r\n\r\n if (\r\n activeFilterBadges?.guideCategory?.id !== params.guideCategory ||\r\n activeFilterBadges?.tag?.id !== params.tag\r\n ) {\r\n component.actions.dispatch('quick-filter:add', {\r\n tag: params.tag,\r\n category: params.guideCategory,\r\n initial: true,\r\n });\r\n }\r\n };\r\n\r\n component.actions.create('search', (data) => {\r\n const { value, filters, filtersChanged } = data;\r\n const { route = 'search', patchParams = false } =\r\n component.properties<SearchComponentProps>();\r\n\r\n if (\r\n value.length > 0 ||\r\n ((hasActiveFilterBadge(filters) || filtersChanged) && !filters?.initial)\r\n ) {\r\n container.getAsync('router').then((router: RoutingService) => {\r\n const { params } = router.getRouteData();\r\n\r\n let searchParams: { [key: string]: string | undefined } = {\r\n guide: undefined,\r\n id: undefined,\r\n accordion: undefined,\r\n contactMethod: undefined,\r\n };\r\n\r\n searchParams.phrase = value.length > 0 ? encodeURIComponent(value) : '';\r\n\r\n if (patchParams) {\r\n searchParams = {\r\n ...params,\r\n ...searchParams,\r\n };\r\n }\r\n\r\n if (filters?.guideCategory || filtersChanged) {\r\n searchParams.guideCategory = filters.guideCategory?.id || undefined;\r\n }\r\n\r\n if (filters?.tag || filtersChanged) {\r\n searchParams.tag = filters.tag?.id || undefined;\r\n }\r\n\r\n router.navigate(route, createParams(searchParams));\r\n });\r\n }\r\n });\r\n\r\n component.actions.create('clear', (data, options) => {\r\n if (data.navigateToHome) {\r\n container.getAsync('router').then((router: RoutingService) => {\r\n const { name }: any = router.getInitialRoute();\r\n router.navigate(name);\r\n });\r\n }\r\n });\r\n\r\n const getRouterParams: () => Promise<Params> = () =>\r\n container\r\n .getAsync('router')\r\n .then((router: RoutingService) => router.getRouteData().params);\r\n\r\n component.actions.create(\r\n 'quick-filter:add',\r\n (data: { category?: string; tag?: string; initial?: boolean }) => {\r\n const { category, tag, initial } = data;\r\n const { activeFilterBadges: previous } =\r\n component.properties<SearchComponentProps>();\r\n\r\n const activeFilterBadges: ActiveFilterBadges = previous || {\r\n initial,\r\n guideCategory: null,\r\n tag: null,\r\n tooltip: null,\r\n };\r\n\r\n return Promise.resolve()\r\n .then(() => {\r\n if (category) {\r\n return fetchCategories({}).then((categories) => {\r\n const categoryItem =\r\n <Category | null>findCategoryById(category, categories) || null;\r\n return {\r\n ...activeFilterBadges,\r\n guideCategory: categoryItem,\r\n tooltip: getTooltip(category, categories) || null,\r\n };\r\n });\r\n }\r\n return {\r\n ...activeFilterBadges,\r\n guideCategory: null,\r\n tooltip: null,\r\n };\r\n })\r\n .then((next) => {\r\n if (tag) {\r\n return fetchTags({}).then((tags) => {\r\n return {\r\n ...next,\r\n tag: tags.find((t) => t.id === tag) || null,\r\n };\r\n });\r\n }\r\n return {\r\n ...next,\r\n tag: null,\r\n };\r\n })\r\n .then((next) => {\r\n return component.writeProperties({\r\n activeFilterBadges: { ...next, initial: !!initial },\r\n });\r\n });\r\n }\r\n );\r\n\r\n component.actions.create('quick-filter:remove', ({ types }: { types: string[] }) => {\r\n const { activeFilterBadges } = component.properties<SearchComponentProps>();\r\n\r\n component.writeProperties({\r\n activeFilterBadges: {\r\n ...activeFilterBadges,\r\n initial: false,\r\n guideCategory:\r\n types.indexOf('guideCategory') > -1\r\n ? null\r\n : activeFilterBadges?.guideCategory,\r\n tag: types.indexOf('tag') > -1 ? null : activeFilterBadges?.tag,\r\n },\r\n });\r\n });\r\n\r\n component.actions.create('quick-filter:close', () => {\r\n return component.writeProperties({\r\n quickFilter: {\r\n items: [],\r\n loading: false,\r\n open: false,\r\n },\r\n });\r\n });\r\n\r\n component.actions.create('quick-filter:open', ({ symbol, type }) => {\r\n component.writeProperties({\r\n quickFilter: {\r\n type,\r\n symbol,\r\n items: [],\r\n loading: true,\r\n open: true,\r\n },\r\n });\r\n\r\n return getRouterParams().then(({ tag, guideCategory, phrase }) => {\r\n if (type === 'guideCategory') {\r\n return fetchCategories({\r\n tagId: tag,\r\n searchPhrase: phrase,\r\n }).then((items) => {\r\n const clone = deepClone(items);\r\n\r\n component.writeProperties({\r\n quickFilter: {\r\n items: sortRecursive(clone),\r\n loading: false,\r\n },\r\n });\r\n });\r\n }\r\n\r\n if (type === 'tag') {\r\n return fetchTags({\r\n categories: guideCategory,\r\n searchPhrase: phrase,\r\n }).then((items) => {\r\n const clone = deepClone(items);\r\n component.writeProperties({\r\n quickFilter: {\r\n items: sortRecursive(clone),\r\n loading: false,\r\n },\r\n });\r\n });\r\n }\r\n });\r\n });\r\n\r\n const fetchCategories = (params: QueryParameters) => {\r\n return container\r\n .getAsync('dataClient')\r\n .then((dataClient: DataClient) =>\r\n dataClient.fetch(DataType.GuideCategories, params)\r\n )\r\n .then((categoriesResult: CategoriesResult) => categoriesResult.categories || []);\r\n };\r\n\r\n const fetchTags = (params: QueryParameters) => {\r\n return container\r\n .getAsync('dataClient')\r\n .then((dataClient: DataClient) => dataClient.fetch(DataType.TagsOnGuides, params))\r\n .then((tags: TagsResult = []) => tags);\r\n };\r\n\r\n getRouterParams().then((params) => {\r\n load(params);\r\n });\r\n\r\n subscribe('router:changed', (_, { current }) => {\r\n const {\r\n routeData: { params },\r\n } = current;\r\n load(params);\r\n });\r\n\r\n subscribe('data-client:fetched', (event, data) => {\r\n const { filterBadges } = component.properties<SearchComponentProps>();\r\n\r\n const showTag = typeof filterBadges === 'object' ? !!filterBadges.tag : !!filterBadges;\r\n\r\n if (data.type === 'match' && showTag) {\r\n getRouterParams().then(({ tag: tagId }) => {\r\n const { tags = [] }: MatchResult = data.response;\r\n const tag = tags.find((t) => t.id === tagId) || null;\r\n component.writeProperties({ filters: { tag } });\r\n });\r\n }\r\n });\r\n\r\n return () => {\r\n unsubscribe();\r\n };\r\n });\r\n};\r\n\r\nexport default SearchComponent;\r\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAqEA,MAAM,IAAuB,CAAC,MACnB,CAAC,CAAC,EAAQ,iBAAiB,CAAC,CAAC,EAAQ,KAG1C,IAAa,CAAC,GAAoB,MAA2B;AACzD,QAAA,IAAqB,EAAc,GAAY,CAAU,GACzD,IAAc,EAA0B,GAAU,CAAU;AAE3D,SADO,EAAS,IAAI,CAAC,MAAO;;AAAA,mBAAY,IAAI,CAAE,MAAlB,kBAAqB,UAAS;AAAA,GAAE,EAAE,KAAK,KAAK;AAEnF,GAEM,IAAgB,CAAC,MAAiB;AAC9B,QAAA,IAAQ,EAAU,CAAK;AAEvB,WAAA,KAAK,CAAC,GAAQ,MACZ,EAAE,QAAQ,EAAE,QACL,IAEJ,EACV,GAEK,EAAA,QAAQ,CAAC,MAAc;AACzB,IAAI,EAAK,SACA,GAAA,QAAQ,EAAc,EAAK,KAAK;AAAA,EACzC,CACH,GAEM;AACX,GAEM,IAAkB,CAAC,MACd,EAAqB,GAAW,UAAU,OAAO,yBAAa,CAAC,MAAc;AAChF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