@salesforcedevs/dw-components 0.0.0
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/LICENSE +12 -0
- package/lwc.config.json +24 -0
- package/package.json +26 -0
- package/src/modules/dw/blogsGrid/blogsGrid.css +89 -0
- package/src/modules/dw/blogsGrid/blogsGrid.html +73 -0
- package/src/modules/dw/blogsGrid/blogsGrid.ts +28 -0
- package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.css +3 -0
- package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.html +16 -0
- package/src/modules/dw/cardBlogPostProvider/cardBlogPostProvider.ts +29 -0
- package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.css +3 -0
- package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.html +12 -0
- package/src/modules/dw/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.ts +29 -0
- package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.css +171 -0
- package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.html +138 -0
- package/src/modules/dw/codeSamplesGrid/codeSamplesGrid.ts +431 -0
- package/src/modules/dw/contentArchive/altData.js +3 -0
- package/src/modules/dw/contentArchive/contentArchive.css +242 -0
- package/src/modules/dw/contentArchive/contentArchive.html +340 -0
- package/src/modules/dw/contentArchive/contentArchive.ts +519 -0
- package/src/modules/dw/contentArchive/contentArchive.types.ts +98 -0
- package/src/modules/dw/contentArchive/utils.ts +193 -0
- package/src/modules/dw/deSignupForm/deSignupForm.css +75 -0
- package/src/modules/dw/deSignupForm/deSignupForm.html +117 -0
- package/src/modules/dw/deSignupForm/deSignupForm.ts +269 -0
- package/src/modules/dw/deSignupForm/submitForm.ts +93 -0
- package/src/modules/dw/docsGrid/docsGrid.css +83 -0
- package/src/modules/dw/docsGrid/docsGrid.html +89 -0
- package/src/modules/dw/docsGrid/docsGrid.ts +540 -0
- package/src/modules/dw/eventsList/eventsList.css +113 -0
- package/src/modules/dw/eventsList/eventsList.html +98 -0
- package/src/modules/dw/eventsList/eventsList.ts +192 -0
- package/src/modules/dw/instrumentation/instrumentation.html +1 -0
- package/src/modules/dw/instrumentation/instrumentation.ts +97 -0
- package/src/modules/dw/newsletterForm/newsletterForm.css +74 -0
- package/src/modules/dw/newsletterForm/newsletterForm.html +67 -0
- package/src/modules/dw/newsletterForm/newsletterForm.ts +233 -0
- package/src/modules/dw/podcastSubscription/podcastSubscription.css +91 -0
- package/src/modules/dw/podcastSubscription/podcastSubscription.html +24 -0
- package/src/modules/dw/podcastSubscription/podcastSubscription.ts +52 -0
- package/src/modules/dw/podcastsGrid/podcastsGrid.css +5 -0
- package/src/modules/dw/podcastsGrid/podcastsGrid.html +29 -0
- package/src/modules/dw/podcastsGrid/podcastsGrid.ts +9 -0
- package/src/modules/dw/podcastsPromo/podcastsPromo.css +32 -0
- package/src/modules/dw/podcastsPromo/podcastsPromo.html +36 -0
- package/src/modules/dw/podcastsPromo/podcastsPromo.ts +3 -0
- package/src/modules/dw/rcgTable/altData.ts +78 -0
- package/src/modules/dw/rcgTable/getTableData.ts +10 -0
- package/src/modules/dw/rcgTable/rcgTable.css +39 -0
- package/src/modules/dw/rcgTable/rcgTable.html +31 -0
- package/src/modules/dw/rcgTable/rcgTable.ts +34 -0
- package/src/modules/dw/slackCta/slackCta.css +47 -0
- package/src/modules/dw/slackCta/slackCta.html +17 -0
- package/src/modules/dw/slackCta/slackCta.ts +12 -0
- package/src/modules/dw/slackSuccess/slackSuccess.css +65 -0
- package/src/modules/dw/slackSuccess/slackSuccess.html +32 -0
- package/src/modules/dw/slackSuccess/slackSuccess.ts +34 -0
- package/src/modules/dwBaseElements/postsGrid/postsGrid.ts +80 -0
- package/src/modules/dwHelpers/postsGrid/postsGrid.css +9 -0
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { api, LightningElement } from "lwc";
|
|
2
|
+
import qs from "query-string";
|
|
3
|
+
import uniqBy from "lodash.uniqby";
|
|
4
|
+
import orderBy from "lodash.orderby";
|
|
5
|
+
import cloneDeep from "lodash.clonedeep";
|
|
6
|
+
import { DocsTile, DropdownItem, CodeSample } from "typings/custom";
|
|
7
|
+
import { toJson } from "dxUtils/normalizers";
|
|
8
|
+
|
|
9
|
+
const PRODUCT_FILTER_ALL_PRODUCTS = "all products";
|
|
10
|
+
const LANGUAGE_FILTER_LABEL = "Type";
|
|
11
|
+
const WAIT_TIME = 500;
|
|
12
|
+
const DEFAULT_BUTTON_TEXT = "Explore on GitHub";
|
|
13
|
+
export default class CodeSamplesGrid extends LightningElement {
|
|
14
|
+
private searchTerm = "";
|
|
15
|
+
private selectedProductFilter: string[] | null = null;
|
|
16
|
+
private selectedTypeFilter: string[] | null = null;
|
|
17
|
+
private selectedSourceFilter: string[] | null = null;
|
|
18
|
+
private page = 1;
|
|
19
|
+
private pageSize = 9;
|
|
20
|
+
private startingRecord = 1;
|
|
21
|
+
private endingRecord = 24;
|
|
22
|
+
private totalRecountCount = 0;
|
|
23
|
+
private totalPages = 1;
|
|
24
|
+
private _featuredCodeSample?: CodeSample = undefined;
|
|
25
|
+
private _samplesList?: CodeSample[] = [];
|
|
26
|
+
private _typesFiltersList?: DropdownItem[] = [];
|
|
27
|
+
private _sourceFiltersList?: DropdownItem[] = [];
|
|
28
|
+
private _productFiltersList?: DropdownItem[] = [];
|
|
29
|
+
private matchDesktop!: MediaQueryList;
|
|
30
|
+
private matchMobile!: MediaQueryList;
|
|
31
|
+
private matchMobileSmall!: MediaQueryList;
|
|
32
|
+
private deviceType: "desktop" | "mobile" | "mobile-small" = "desktop";
|
|
33
|
+
private _searchTimeout?: number;
|
|
34
|
+
private target = "_blank";
|
|
35
|
+
private isDesktop = "(min-width: 1024px)";
|
|
36
|
+
private isMobile = "(min-width: 401px) and (max-width: 1023px)";
|
|
37
|
+
private isMobileSmall = "(max-width: 400px)";
|
|
38
|
+
private showSourcesFilter = false;
|
|
39
|
+
private filtersDefaultValue = {
|
|
40
|
+
selectedSourceFilter: [],
|
|
41
|
+
selectedTypeFilter: [],
|
|
42
|
+
selectedProductFilter: [],
|
|
43
|
+
searchTerm: "",
|
|
44
|
+
page: "1"
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
connectedCallback(): void {
|
|
48
|
+
this.matchDesktop = window.matchMedia(this.isDesktop);
|
|
49
|
+
this.matchDesktop.addEventListener("change", this.handleView);
|
|
50
|
+
|
|
51
|
+
this.matchMobile = window.matchMedia(this.isMobile);
|
|
52
|
+
this.matchMobile.addEventListener("change", this.handleView);
|
|
53
|
+
|
|
54
|
+
this.matchMobileSmall = window.matchMedia(this.isMobileSmall);
|
|
55
|
+
this.matchMobileSmall.addEventListener("change", this.handleView);
|
|
56
|
+
window.addEventListener("popstate", this.handleURLStateChange);
|
|
57
|
+
if (this.matchDesktop.matches) {
|
|
58
|
+
this.deviceType = "desktop";
|
|
59
|
+
}
|
|
60
|
+
if (this.matchMobile.matches) {
|
|
61
|
+
this.deviceType = "mobile";
|
|
62
|
+
}
|
|
63
|
+
if (this.matchMobileSmall.matches) {
|
|
64
|
+
this.deviceType = "mobile-small";
|
|
65
|
+
}
|
|
66
|
+
this.evaluateQueryParams(false);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
handleURLStateChange(): void {
|
|
70
|
+
this.evaluateQueryParams(true);
|
|
71
|
+
this.scrollToTop();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
evaluateQueryParams(resetFilters: boolean): void {
|
|
75
|
+
let page = "1";
|
|
76
|
+
if (resetFilters) {
|
|
77
|
+
this.selectedSourceFilter =
|
|
78
|
+
this.filtersDefaultValue.selectedSourceFilter;
|
|
79
|
+
this.selectedTypeFilter =
|
|
80
|
+
this.filtersDefaultValue.selectedTypeFilter;
|
|
81
|
+
this.selectedProductFilter =
|
|
82
|
+
this.filtersDefaultValue.selectedProductFilter;
|
|
83
|
+
}
|
|
84
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
85
|
+
if (urlParams.toString()) {
|
|
86
|
+
if (urlParams.has("source")) {
|
|
87
|
+
this.selectedSourceFilter = urlParams.getAll("source");
|
|
88
|
+
}
|
|
89
|
+
if (urlParams.has("type")) {
|
|
90
|
+
this.selectedTypeFilter = urlParams.getAll("type");
|
|
91
|
+
}
|
|
92
|
+
if (urlParams.get("service")) {
|
|
93
|
+
this.selectedProductFilter = urlParams
|
|
94
|
+
.get("service")
|
|
95
|
+
.split(",");
|
|
96
|
+
}
|
|
97
|
+
if (urlParams.get("filter_text")) {
|
|
98
|
+
this.searchTerm = (
|
|
99
|
+
urlParams.get("filter_text") || ""
|
|
100
|
+
).toLowerCase();
|
|
101
|
+
}
|
|
102
|
+
if (urlParams.has("page")) {
|
|
103
|
+
page = urlParams.get("page");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.calculatePagination(page, true);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
disconnectedCallback(): void {
|
|
110
|
+
this.matchDesktop.removeEventListener("change", this.handleView);
|
|
111
|
+
this.matchMobile.removeEventListener("change", this.handleView);
|
|
112
|
+
this.matchMobileSmall.removeEventListener("change", this.handleView);
|
|
113
|
+
window.removeEventListener("popstate", this.handleURLStateChange);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@api
|
|
117
|
+
set featuredCodeSample(value: string) {
|
|
118
|
+
this._featuredCodeSample = toJson(value);
|
|
119
|
+
}
|
|
120
|
+
get featuredCodeSample(): CodeSample {
|
|
121
|
+
return this._featuredCodeSample;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@api
|
|
125
|
+
set samples(value: string) {
|
|
126
|
+
console.log(value);
|
|
127
|
+
const jsonSamples = toJson(value) || [];
|
|
128
|
+
this._samplesList = jsonSamples.map((sample, i) => ({
|
|
129
|
+
id: i,
|
|
130
|
+
title: sample.title,
|
|
131
|
+
body: sample.body,
|
|
132
|
+
buttonText: DEFAULT_BUTTON_TEXT,
|
|
133
|
+
href: sample.href,
|
|
134
|
+
imgSrc: sample.imgSrc,
|
|
135
|
+
product: sample.product,
|
|
136
|
+
type: sample.type,
|
|
137
|
+
// source: sample.source,
|
|
138
|
+
source: "none",
|
|
139
|
+
target: this.target
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
get samples(): CodeSample[] {
|
|
144
|
+
return this._samplesList;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@api
|
|
148
|
+
set products(value: string) {
|
|
149
|
+
const productsFilters = toJson(value).map((sample: string) => ({
|
|
150
|
+
label: sample,
|
|
151
|
+
value: sample.toLowerCase()
|
|
152
|
+
}));
|
|
153
|
+
|
|
154
|
+
this._productFiltersList = orderBy(
|
|
155
|
+
uniqBy([...productsFilters], "value"),
|
|
156
|
+
["value"],
|
|
157
|
+
["asc"]
|
|
158
|
+
);
|
|
159
|
+
this.selectedProductFilter = this._productFiltersList.map(
|
|
160
|
+
(filter) => filter.value
|
|
161
|
+
);
|
|
162
|
+
this.filtersDefaultValue.selectedProductFilter = cloneDeep(
|
|
163
|
+
this.selectedProductFilter
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
get products(): DropdownItem[] {
|
|
167
|
+
return this._productFiltersList;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@api
|
|
171
|
+
set types(value: string) {
|
|
172
|
+
const typesFilter = toJson(value).map((sample: string) => ({
|
|
173
|
+
label: sample,
|
|
174
|
+
value: sample.toLowerCase()
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
this._typesFiltersList = orderBy(
|
|
178
|
+
uniqBy([...typesFilter], "value"),
|
|
179
|
+
["value"],
|
|
180
|
+
["asc"]
|
|
181
|
+
);
|
|
182
|
+
this.selectedTypeFilter = this._typesFiltersList.map(
|
|
183
|
+
(filter) => filter.value
|
|
184
|
+
);
|
|
185
|
+
this.filtersDefaultValue.selectedTypeFilter = cloneDeep(
|
|
186
|
+
this.selectedTypeFilter
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
get types(): DropdownItem[] {
|
|
190
|
+
return this._typesFiltersList;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@api
|
|
194
|
+
set sources(value: string) {
|
|
195
|
+
const parsedValues = toJson(value);
|
|
196
|
+
this.showSourcesFilter = parsedValues.length > 0;
|
|
197
|
+
const sourcesFilter = parsedValues.map((sample: string) => ({
|
|
198
|
+
label: sample,
|
|
199
|
+
value: sample.toLowerCase()
|
|
200
|
+
}));
|
|
201
|
+
|
|
202
|
+
this._sourceFiltersList = orderBy(
|
|
203
|
+
uniqBy([...sourcesFilter], "value"),
|
|
204
|
+
["value"],
|
|
205
|
+
["asc"]
|
|
206
|
+
);
|
|
207
|
+
this.selectedSourceFilter = this._sourceFiltersList.map(
|
|
208
|
+
(filter) => filter.value
|
|
209
|
+
);
|
|
210
|
+
this.filtersDefaultValue.selectedSourceFilter = cloneDeep(
|
|
211
|
+
this.selectedSourceFilter
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
get sources(): DropdownItem[] {
|
|
215
|
+
return this._sourceFiltersList;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
get filteredSamples(): CodeSample[] {
|
|
219
|
+
return this.filterSamples([...this.samples]);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
get currentPageSamples(): DocsTile[] {
|
|
223
|
+
return this.filteredSamples.slice(
|
|
224
|
+
this.startingRecord - 1,
|
|
225
|
+
this.endingRecord
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
get typesList(): DropdownItem[] {
|
|
230
|
+
return this._typesFiltersList || [];
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
get productFiltersList(): DropdownItem[] {
|
|
234
|
+
return this._productFiltersList || [];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
get showEmptyState(): boolean {
|
|
238
|
+
return !this.filteredSamples.length;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
get typeFilterLabel(): string {
|
|
242
|
+
const selectedLanguage = this.typesList.find(
|
|
243
|
+
(language) => language.value === this.selectedTypeFilter
|
|
244
|
+
);
|
|
245
|
+
const label = selectedLanguage && selectedLanguage.label;
|
|
246
|
+
return label || LANGUAGE_FILTER_LABEL;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
get tileColumns(): string {
|
|
250
|
+
return this.deviceType === "desktop" ? "three" : "two";
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
get pagesToShow(): number {
|
|
254
|
+
return this.deviceType === "mobile-small" ? 3 : 5;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
get hidePagination(): boolean {
|
|
258
|
+
return this.totalPages < 2;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
get emptyStateSubtitle(): string {
|
|
262
|
+
return (
|
|
263
|
+
"No results" +
|
|
264
|
+
(this.searchTerm !== "" ? ` for "${this.searchTerm}"` : "")
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
handleView = (e: MediaQueryListEvent | MediaQueryList): void => {
|
|
269
|
+
if (e.media === this.isDesktop && e.matches) {
|
|
270
|
+
this.deviceType = "desktop";
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (e.media === this.isMobile && e.matches) {
|
|
275
|
+
this.deviceType = "mobile";
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (e.media === this.isMobileSmall && e.matches) {
|
|
280
|
+
this.deviceType = "mobile-small";
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
goToPage(e: CustomEvent): void {
|
|
285
|
+
const page = e.detail;
|
|
286
|
+
this.displayRecordsPerPage(page);
|
|
287
|
+
this.setSearchParams("page", page ? page.toString() : "1");
|
|
288
|
+
this.scrollToTop();
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
displayRecordsPerPage(page: number): void {
|
|
292
|
+
this.page = page;
|
|
293
|
+
this.startingRecord =
|
|
294
|
+
page === 1 ? page : (page - 1) * this.pageSize + 1;
|
|
295
|
+
this.endingRecord = this.pageSize * page;
|
|
296
|
+
this.endingRecord =
|
|
297
|
+
this.endingRecord > this.totalRecountCount
|
|
298
|
+
? this.totalRecountCount
|
|
299
|
+
: this.endingRecord;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
handleSearchChange(event: CustomEvent): void {
|
|
303
|
+
const value = event.detail;
|
|
304
|
+
this.searchTerm = value.toLowerCase();
|
|
305
|
+
window.clearTimeout(this._searchTimeout);
|
|
306
|
+
this._searchTimeout = window.setTimeout(() => {
|
|
307
|
+
this.calculatePagination();
|
|
308
|
+
}, WAIT_TIME);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
handleSourceFilterChange(event: CustomEvent): void {
|
|
312
|
+
this.selectedSourceFilter = event.detail.value;
|
|
313
|
+
this.calculatePagination();
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
handleTypeFilterChange(event: CustomEvent): void {
|
|
317
|
+
this.selectedTypeFilter = event.detail.value;
|
|
318
|
+
this.calculatePagination();
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
handleProductFilterChange(event: CustomEvent): void {
|
|
322
|
+
if (event.detail.checkedValue === PRODUCT_FILTER_ALL_PRODUCTS) {
|
|
323
|
+
if (event.detail.checked) {
|
|
324
|
+
this.selectedProductFilter = this.productFiltersList.map(
|
|
325
|
+
(filter) => filter.value
|
|
326
|
+
);
|
|
327
|
+
} else {
|
|
328
|
+
this.selectedProductFilter = [];
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
let newList = event.detail.value;
|
|
332
|
+
if (!event.detail.checked) {
|
|
333
|
+
newList = newList.filter(
|
|
334
|
+
(val) => val !== PRODUCT_FILTER_ALL_PRODUCTS
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
this.selectedProductFilter = newList;
|
|
338
|
+
}
|
|
339
|
+
this.calculatePagination();
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
handleLanguageFilterChange(event: CustomEvent): void {
|
|
343
|
+
this.selectedTypeFilter = event.detail.value;
|
|
344
|
+
this.setSearchParams("type", this.selectedTypeFilter);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
filterSamples(samples: CodeSample[]): CodeSample[] {
|
|
348
|
+
const filtered = samples
|
|
349
|
+
.filter((contentItem) => {
|
|
350
|
+
const matchesSearchTerm =
|
|
351
|
+
contentItem.body.toLowerCase().includes(this.searchTerm) ||
|
|
352
|
+
contentItem.title.toLowerCase().includes(this.searchTerm);
|
|
353
|
+
const matchesProductFilters =
|
|
354
|
+
!this.selectedProductFilter ||
|
|
355
|
+
!this.selectedProductFilter.length ||
|
|
356
|
+
this.selectedProductFilter.includes(
|
|
357
|
+
PRODUCT_FILTER_ALL_PRODUCTS
|
|
358
|
+
) ||
|
|
359
|
+
(typeof contentItem.product === "string" &&
|
|
360
|
+
this.selectedProductFilter.includes(
|
|
361
|
+
contentItem.product.toLowerCase()
|
|
362
|
+
));
|
|
363
|
+
const matchesTypeFilters =
|
|
364
|
+
!this.selectedTypeFilter ||
|
|
365
|
+
!this.selectedTypeFilter.length ||
|
|
366
|
+
(typeof contentItem.type === "string" &&
|
|
367
|
+
this.selectedTypeFilter.includes(
|
|
368
|
+
contentItem.type.toLowerCase()
|
|
369
|
+
));
|
|
370
|
+
const matchesSourceFilters =
|
|
371
|
+
!this.selectedSourceFilter ||
|
|
372
|
+
!this.selectedSourceFilter.length ||
|
|
373
|
+
(typeof contentItem.source === "string" &&
|
|
374
|
+
this.selectedSourceFilter.includes(
|
|
375
|
+
contentItem.source.toLowerCase()
|
|
376
|
+
));
|
|
377
|
+
|
|
378
|
+
return (
|
|
379
|
+
matchesSearchTerm &&
|
|
380
|
+
matchesProductFilters &&
|
|
381
|
+
matchesTypeFilters &&
|
|
382
|
+
matchesSourceFilters
|
|
383
|
+
);
|
|
384
|
+
})
|
|
385
|
+
.sort((a: CodeSample, b: CodeSample) => {
|
|
386
|
+
return a.title.localeCompare(b.title);
|
|
387
|
+
});
|
|
388
|
+
return filtered;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
calculatePagination(page?: string, skipSetSearchParams = false): void {
|
|
392
|
+
this.page = +parseInt(page, 10) || 1;
|
|
393
|
+
this.totalRecountCount = this.filteredSamples.length;
|
|
394
|
+
this.totalPages = Math.ceil(this.totalRecountCount / this.pageSize);
|
|
395
|
+
this.displayRecordsPerPage(this.page);
|
|
396
|
+
if (!skipSetSearchParams) {
|
|
397
|
+
this.setSearchParams();
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
scrollToTop(): void {
|
|
402
|
+
this.template
|
|
403
|
+
.querySelector(".docs-grid-container")
|
|
404
|
+
.scrollIntoView({ behavior: "smooth" });
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
setSearchParams(key?: string, val?: string[]): void {
|
|
408
|
+
const service =
|
|
409
|
+
this.selectedProductFilter.length === this.productFiltersList.length
|
|
410
|
+
? ""
|
|
411
|
+
: this.selectedProductFilter.join(",");
|
|
412
|
+
const params = {
|
|
413
|
+
filter_text: this.searchTerm,
|
|
414
|
+
service,
|
|
415
|
+
type: this.selectedTypeFilter,
|
|
416
|
+
page: this.page.toString(),
|
|
417
|
+
source: this.selectedSourceFilter
|
|
418
|
+
};
|
|
419
|
+
if (key) {
|
|
420
|
+
params[key] = key === "service" ? val.join(",") : val;
|
|
421
|
+
}
|
|
422
|
+
for (const _key in params) {
|
|
423
|
+
if (!params[_key]) {
|
|
424
|
+
delete params[_key];
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
const searchParams = qs.stringify(params);
|
|
428
|
+
const newurl = `${window.location.pathname}?${searchParams}`;
|
|
429
|
+
window.history.pushState({ path: newurl }, "", newurl);
|
|
430
|
+
}
|
|
431
|
+
}
|