@salesforcedevs/dx-components 0.34.0 → 0.35.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/package.json +2 -2
- package/src/modules/dx/button/button.ts +2 -0
- package/src/modules/dx/contentArchive/contentArchive.html +8 -8
- package/src/modules/dx/contentArchive/contentArchive.ts +65 -7
- package/src/modules/dx/contentArchive/contentArchive.types.ts +6 -0
- package/src/modules/dx/filterMenu/filterMenu.html +1 -0
- package/src/modules/dx/filterMenu/filterMenu.ts +6 -2
- package/src/modules/utils/queryCoordinator/queryCoordinator.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.0",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@types/debounce": "^1.2.0",
|
|
27
27
|
"@types/lodash.get": "^4.4.6"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "f7fc8ed1e4ba14038343beeeed60324f50622117"
|
|
30
30
|
}
|
|
@@ -21,6 +21,8 @@ export default class Button extends LightningElement {
|
|
|
21
21
|
@api variant: ButtonVariant = "primary";
|
|
22
22
|
@api inlineTextColor: ButtonTextColor = "dark";
|
|
23
23
|
@api font: "display" | "sans" = "display";
|
|
24
|
+
@api name?: string;
|
|
25
|
+
@api value?: any;
|
|
24
26
|
|
|
25
27
|
// button props
|
|
26
28
|
@api type: "submit" | "reset" | "button" = "button";
|
|
@@ -29,28 +29,28 @@
|
|
|
29
29
|
name="site"
|
|
30
30
|
title={contentTypeTitle}
|
|
31
31
|
options={contentTypeList}
|
|
32
|
-
onchange={
|
|
32
|
+
onchange={handleUpdateSiteFilter}
|
|
33
33
|
></dx-filter-menu>
|
|
34
34
|
<dx-filter-menu
|
|
35
35
|
name="dates"
|
|
36
36
|
title={dateTitle}
|
|
37
37
|
options={dateList}
|
|
38
38
|
variant="nested"
|
|
39
|
-
onchange={
|
|
39
|
+
onchange={handleFiltersEvent}
|
|
40
40
|
></dx-filter-menu>
|
|
41
41
|
<template if:false={hideBlogFilters}>
|
|
42
42
|
<dx-filter-menu
|
|
43
43
|
name="authors"
|
|
44
44
|
title={authorTitle}
|
|
45
45
|
options={authorList}
|
|
46
|
-
onchange={
|
|
46
|
+
onchange={handleFiltersEvent}
|
|
47
47
|
></dx-filter-menu>
|
|
48
48
|
</template>
|
|
49
49
|
<dx-filter-menu
|
|
50
50
|
name="categories"
|
|
51
51
|
title={categoryTitle}
|
|
52
52
|
options={categoryList}
|
|
53
|
-
onchange={
|
|
53
|
+
onchange={handleFiltersEvent}
|
|
54
54
|
></dx-filter-menu>
|
|
55
55
|
</template>
|
|
56
56
|
</dx-modal-drawer>
|
|
@@ -76,28 +76,28 @@
|
|
|
76
76
|
name="site"
|
|
77
77
|
title={contentTypeTitle}
|
|
78
78
|
options={contentTypeList}
|
|
79
|
-
onchange={
|
|
79
|
+
onchange={handleUpdateSiteFilter}
|
|
80
80
|
></dx-filter-menu>
|
|
81
81
|
<dx-filter-menu
|
|
82
82
|
name="dates"
|
|
83
83
|
title={dateTitle}
|
|
84
84
|
options={dateList}
|
|
85
85
|
variant="nested"
|
|
86
|
-
onchange={
|
|
86
|
+
onchange={handleFiltersEvent}
|
|
87
87
|
></dx-filter-menu>
|
|
88
88
|
<template if:false={hideBlogFilters}>
|
|
89
89
|
<dx-filter-menu
|
|
90
90
|
name="authors"
|
|
91
91
|
title={authorTitle}
|
|
92
92
|
options={authorList}
|
|
93
|
-
onchange={
|
|
93
|
+
onchange={handleFiltersEvent}
|
|
94
94
|
></dx-filter-menu>
|
|
95
95
|
</template>
|
|
96
96
|
<dx-filter-menu
|
|
97
97
|
name="categories"
|
|
98
98
|
title={categoryTitle}
|
|
99
99
|
options={categoryList}
|
|
100
|
-
onchange={
|
|
100
|
+
onchange={handleFiltersEvent}
|
|
101
101
|
></dx-filter-menu>
|
|
102
102
|
</template>
|
|
103
103
|
</template>
|
|
@@ -2,10 +2,19 @@ import { LightningElement } from "lwc";
|
|
|
2
2
|
import cx from "classnames";
|
|
3
3
|
import { getArchivePosts, getArchiveFilterList } from "utils/contentArchive";
|
|
4
4
|
import { sortSplittedPostsByMonth } from "utils/dates";
|
|
5
|
+
import { Filters } from "./contentArchive.types";
|
|
6
|
+
import { QueryCoordinator } from "utils/queryCoordinator";
|
|
5
7
|
|
|
6
8
|
const MOBILE_MATCH = "767px";
|
|
7
9
|
|
|
10
|
+
const QUERY_SITE_FILTER = "c__filter";
|
|
11
|
+
const PODCASTS = { id: 2, name: "Podcasts" };
|
|
12
|
+
const BLOGS = { id: 1, name: "Blogs" };
|
|
8
13
|
export default class ContentArchive extends LightningElement {
|
|
14
|
+
private _contentTypeList = [
|
|
15
|
+
{ ...BLOGS, checked: false },
|
|
16
|
+
{ ...PODCASTS, checked: false }
|
|
17
|
+
];
|
|
9
18
|
private totalResults: number | null = null;
|
|
10
19
|
private currentPage: number = 1;
|
|
11
20
|
private totalPages: number = 1;
|
|
@@ -22,7 +31,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
22
31
|
private isMobile: boolean = false;
|
|
23
32
|
private mobileMatchMedia!: MediaQueryList;
|
|
24
33
|
|
|
25
|
-
private selectedFilterMenuData:
|
|
34
|
+
private selectedFilterMenuData: Filters = {
|
|
26
35
|
site: [],
|
|
27
36
|
dates: [],
|
|
28
37
|
authors: [],
|
|
@@ -88,10 +97,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
get contentTypeList() {
|
|
91
|
-
return
|
|
92
|
-
{ id: 1, name: "Blogs" },
|
|
93
|
-
{ id: 2, name: "Podcasts" }
|
|
94
|
-
];
|
|
100
|
+
return this._contentTypeList;
|
|
95
101
|
}
|
|
96
102
|
|
|
97
103
|
get hideBlogFilters() {
|
|
@@ -146,9 +152,37 @@ export default class ContentArchive extends LightningElement {
|
|
|
146
152
|
});
|
|
147
153
|
}
|
|
148
154
|
|
|
149
|
-
private
|
|
155
|
+
private handleUpdateSiteFilter(e: CustomEvent) {
|
|
150
156
|
const { value, name, checked } = e.detail;
|
|
151
157
|
|
|
158
|
+
let selectedFilters: string[] | null = [];
|
|
159
|
+
this._contentTypeList.forEach((option) => {
|
|
160
|
+
if (option.name === value.name) {
|
|
161
|
+
option.checked = checked;
|
|
162
|
+
}
|
|
163
|
+
if (option.checked) {
|
|
164
|
+
selectedFilters?.push(option.name);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (selectedFilters?.length === 0) {
|
|
169
|
+
selectedFilters = null;
|
|
170
|
+
}
|
|
171
|
+
QueryCoordinator.setUrlParamValue(QUERY_SITE_FILTER, selectedFilters);
|
|
172
|
+
|
|
173
|
+
this.updateSelectedFilters(value, name, checked);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private handleFiltersEvent(e: CustomEvent) {
|
|
177
|
+
const { value, name, checked } = e.detail;
|
|
178
|
+
this.updateSelectedFilters(value, name, checked);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private updateSelectedFilters(
|
|
182
|
+
value: any,
|
|
183
|
+
name: keyof Filters,
|
|
184
|
+
checked: any
|
|
185
|
+
) {
|
|
152
186
|
let copy = {
|
|
153
187
|
...this.selectedFilterMenuData
|
|
154
188
|
};
|
|
@@ -217,7 +251,7 @@ export default class ContentArchive extends LightningElement {
|
|
|
217
251
|
private removeFilterItem(e: any) {
|
|
218
252
|
const { name, value } = e.target;
|
|
219
253
|
|
|
220
|
-
this.
|
|
254
|
+
this.handleUpdateSiteFilter(
|
|
221
255
|
new CustomEvent("updateselectedfilters", {
|
|
222
256
|
detail: {
|
|
223
257
|
name,
|
|
@@ -395,8 +429,32 @@ export default class ContentArchive extends LightningElement {
|
|
|
395
429
|
this.onMobileChange(this.mobileMatchMedia);
|
|
396
430
|
this.mobileMatchMedia.addEventListener("change", this.onMobileChange);
|
|
397
431
|
|
|
432
|
+
const presetFilters: string[] =
|
|
433
|
+
QueryCoordinator.getUrlParamValue(QUERY_SITE_FILTER);
|
|
434
|
+
if (
|
|
435
|
+
presetFilters?.some((filterString) => filterString === BLOGS.name)
|
|
436
|
+
) {
|
|
437
|
+
this.presetSiteFilter(BLOGS);
|
|
438
|
+
}
|
|
439
|
+
if (
|
|
440
|
+
presetFilters?.some(
|
|
441
|
+
(filterString) => filterString === PODCASTS.name
|
|
442
|
+
)
|
|
443
|
+
) {
|
|
444
|
+
this.presetSiteFilter(PODCASTS);
|
|
445
|
+
}
|
|
446
|
+
|
|
398
447
|
if (this.posts.length === 0) {
|
|
399
448
|
this.fetchPostsByCardType();
|
|
400
449
|
}
|
|
401
450
|
}
|
|
451
|
+
|
|
452
|
+
presetSiteFilter(filter: any) {
|
|
453
|
+
this._contentTypeList.forEach((option) => {
|
|
454
|
+
if (option.name === filter.name) {
|
|
455
|
+
option.checked = true;
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
this.updateSelectedFilters(filter, "site", true);
|
|
459
|
+
}
|
|
402
460
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { LightningElement, api } from "lwc";
|
|
2
2
|
|
|
3
|
+
interface Option {
|
|
4
|
+
id: number;
|
|
5
|
+
name: string;
|
|
6
|
+
checked: boolean;
|
|
7
|
+
}
|
|
3
8
|
export default class FilterMenu extends LightningElement {
|
|
4
9
|
@api name: string = "";
|
|
5
10
|
@api title: string = "Filter Menu";
|
|
6
|
-
@api options:
|
|
11
|
+
@api options: Option[] = [];
|
|
7
12
|
@api variant: string = "base";
|
|
8
13
|
|
|
9
14
|
private showMore: boolean = false;
|
|
@@ -80,7 +85,6 @@ export default class FilterMenu extends LightningElement {
|
|
|
80
85
|
|
|
81
86
|
private onChange(e: any) {
|
|
82
87
|
const { checked, value } = e.detail;
|
|
83
|
-
|
|
84
88
|
this.dispatchEvent(
|
|
85
89
|
new CustomEvent("change", {
|
|
86
90
|
detail: {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class QueryCoordinator {
|
|
2
|
+
static getUrlParamValue(key: string) {
|
|
3
|
+
return JSON.parse(
|
|
4
|
+
new URL(window.location.href).searchParams.get(key) || "null"
|
|
5
|
+
);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static setUrlParamValue(key: string, value: any) {
|
|
9
|
+
const newUrl = new URL(window.location.href);
|
|
10
|
+
if (value) {
|
|
11
|
+
newUrl.searchParams.set(key, JSON.stringify(value));
|
|
12
|
+
} else {
|
|
13
|
+
newUrl.searchParams.delete(key);
|
|
14
|
+
}
|
|
15
|
+
window.history.replaceState(null, "", newUrl.href);
|
|
16
|
+
}
|
|
17
|
+
}
|