@salesforcedevs/dw-components 1.1.2-alpha.3 → 1.1.2-alpha.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dw-components",
3
- "version": "1.1.2-alpha.3",
3
+ "version": "1.1.2-alpha.4",
4
4
  "description": "Lightning web components for https://developer.salesforce.com",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -2,7 +2,7 @@
2
2
  <div class="panel-list-container">
3
3
  <h2 class="title">{title}</h2>
4
4
  <dx-tab-panel-list tabs={tabLabels} onchange={handleTabChange}>
5
- <template for:each={_trialsCopy} for:item="trial">
5
+ <template for:each={trials} for:item="trial">
6
6
  <dx-tab-panel key={trial.label}>
7
7
  <div
8
8
  key={trial.label}
@@ -20,7 +20,7 @@
20
20
  ></dx-button-toggle>
21
21
  </template>
22
22
  </div>
23
- <template for:each={trial.categories} for:item="category">
23
+ <template for:each={filteredCategories} for:item="category">
24
24
  <div key={category.title} class="category-container">
25
25
  <h2 class="dx-text-heading-4 category-title">
26
26
  {category.title}
@@ -8,13 +8,19 @@ export default class BrowseTrials extends LightningElement {
8
8
  get trials() {
9
9
  return this._trials;
10
10
  }
11
- set trials(value: [{ label: string }]) {
11
+ set trials(
12
+ value: [{ label: string; hideFilters: boolean; buttonLabels: string[] }]
13
+ ) {
12
14
  this._trials = toJson(value);
13
- this._trialsCopy = toJson(value);
14
15
  this.tabLabels = this._trials.map((trial) => ({ label: trial.label }));
15
16
  this.buttonLabels = this._trials.map((trial) =>
16
- trial.categories.map((category) => category.title)
17
+ trial.hideFilters ? [] : trial.buttonLabels
17
18
  );
19
+ this._filteredCategories = this._trials.map(
20
+ (trial) => trial.categories
21
+ );
22
+
23
+ console.log(this._filteredCategories);
18
24
  }
19
25
 
20
26
  get buttonLabelsForActiveTab() {
@@ -25,58 +31,65 @@ export default class BrowseTrials extends LightningElement {
25
31
  return this._trials[this.activeTabIndex].categories;
26
32
  }
27
33
 
28
- // we manipulate the copy of the trials to show the active tab's categories
29
- get activeCategoriesCopy() {
30
- return this._trialsCopy[this.activeTabIndex].categories;
34
+ get filteredCategories() {
35
+ return this._filteredCategories[this.activeTabIndex];
31
36
  }
32
- set activeCategoriesCopy(value) {
33
- this._trialsCopy[this.activeTabIndex].categories = value;
37
+ set filteredCategories(value: any) {
38
+ this._filteredCategories[this.activeTabIndex] = value;
34
39
  }
35
40
 
36
41
  @track
37
- private _trialsCopy!: [
38
- { label: string; categories: Array<{ title: string }> }
39
- ];
42
+ private _filteredCategories!: Array<any>;
40
43
 
44
+ private activeTabIndex = 0;
41
45
  private buttonLabels!: string[][];
46
+ private filteredTitles: string[] = [];
42
47
  private tabLabels!: Array<{ label: string }>;
43
- private _trials!: [{ label: string; categories: Array<{ title: string }> }];
44
- private activeTabIndex = 0;
48
+ private _trials!: [
49
+ {
50
+ label: string;
51
+ hideFilters: boolean;
52
+ buttonLabels: string[];
53
+ categories: Array<{ title: string }>;
54
+ }
55
+ ];
45
56
 
46
57
  handleTabChange(e: CustomEvent) {
47
58
  this.activeTabIndex = e.detail;
48
59
  }
49
60
 
50
- addFilter(label: string) {
51
- this.activeCategoriesCopy =
52
- this.activeCategories.length ===
53
- this.activeCategoriesCopy.length + 1
54
- ? [...this.activeCategories]
55
- : [
56
- ...this.activeCategories.filter(
57
- (category) => category.title === label
58
- )
59
- ];
61
+ filterCategories() {
62
+ this.filteredCategories = this.activeCategories.filter((category) =>
63
+ this.filteredTitles.includes(category.title)
64
+ );
65
+ }
66
+
67
+ addLabelToFilter(label: string) {
68
+ this.filteredTitles.push(label);
69
+ this.filterCategories();
70
+ }
71
+
72
+ removeLabelFromFilter(label: string) {
73
+ this.filteredTitles = this.filteredTitles.filter(
74
+ (filterTitle) => filterTitle !== label
75
+ );
76
+ this.filterCategories();
60
77
  }
61
78
 
62
- removeFilter(label: string) {
63
- this.activeCategoriesCopy =
64
- this.activeCategoriesCopy.length - 1 === 0
65
- ? [...this.activeCategories]
66
- : [
67
- ...this.activeCategories.filter(
68
- (category) => category.title !== label
69
- )
70
- ];
79
+ resetFilters() {
80
+ this.filteredTitles = [];
81
+ this.filteredCategories = this.activeCategories;
71
82
  }
72
83
 
73
84
  handleFilters(e: CustomEvent) {
74
85
  const { label, value } = e.detail;
75
86
 
76
87
  if (value) {
77
- this.addFilter(label);
88
+ this.addLabelToFilter(label);
89
+ } else if (this.filteredTitles.length !== 1) {
90
+ this.removeLabelFromFilter(label);
78
91
  } else {
79
- this.removeFilter(label);
92
+ this.resetFilters();
80
93
  }
81
94
  }
82
95
  }