@brightspace-ui/core 2.124.0 → 2.126.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.
@@ -13,8 +13,9 @@ class FilterSearchDemo extends LitElement {
13
13
 
14
14
  constructor() {
15
15
  super();
16
- this._fullData = Array.from(initialData);
17
- this._fullDataSingle = Array.from(initialData);
16
+ this._fullData = JSON.parse(JSON.stringify(initialData));
17
+ this._fullDataSingle = JSON.parse(JSON.stringify(initialData));
18
+ this._fullDataInitialSubset = JSON.parse(JSON.stringify(initialData));
18
19
  }
19
20
 
20
21
  render() {
@@ -40,6 +41,11 @@ class FilterSearchDemo extends LitElement {
40
41
  <d2l-filter-dimension-set-value key="${value.key}" text="${value.text}" ?selected="${value.selected}"></d2l-filter-dimension-set-value>
41
42
  `)}
42
43
  </d2l-filter-dimension-set>
44
+ <d2l-filter-dimension-set key="event-initial-subset" text="Event on Search - Initial Subset" search-type="manual" header-text="Related Roles at D2L" selected-first>
45
+ ${this._fullDataInitialSubset.map(value => html`
46
+ <d2l-filter-dimension-set-value key="${value.key}" text="${value.text}" ?selected="${value.selected}"></d2l-filter-dimension-set-value>
47
+ `)}
48
+ </d2l-filter-dimension-set>
43
49
  <d2l-filter-dimension-set key="auto" text="Automatic Search" search-type="automatic">
44
50
  <d2l-filter-dimension-set-value key="admin" text="Admin"></d2l-filter-dimension-set-value>
45
51
  <d2l-filter-dimension-set-value key="instructor" text="Instructor"></d2l-filter-dimension-set-value>
@@ -60,7 +66,12 @@ class FilterSearchDemo extends LitElement {
60
66
  e.detail.dimensions.forEach(dimension => {
61
67
  if (!dimension.dimensionKey.includes('event')) return;
62
68
 
63
- const dataToUpdate = dimension.dimensionKey === 'event-single' ? this._fullDataSingle : this._fullData;
69
+ const dataToUpdateMap = {
70
+ 'event': this._fullData,
71
+ 'event-single': this._fullDataSingle,
72
+ 'event-initial-subset': this._fullDataInitialSubset,
73
+ };
74
+ const dataToUpdate = dataToUpdateMap[dimension.dimensionKey];
64
75
  if (dimension.cleared) {
65
76
  dataToUpdate.forEach(value => value.selected = false);
66
77
  } else {
@@ -71,6 +82,7 @@ class FilterSearchDemo extends LitElement {
71
82
  if (e.detail.allCleared) {
72
83
  console.log('(All dimensions cleared)'); // eslint-disable-line no-console
73
84
  }
85
+ this.requestUpdate();
74
86
  }
75
87
 
76
88
  _handleFirstOpen(e) {
@@ -81,20 +93,43 @@ class FilterSearchDemo extends LitElement {
81
93
  _handleSearch(e) {
82
94
  if (!e.detail.key.includes('event')) return;
83
95
 
84
- const keysToDisplay = [];
85
- this._fullData.forEach(value => {
86
- if (value.text.toLowerCase().indexOf(e.detail.value.toLowerCase()) > -1) {
87
- keysToDisplay.push(value.key);
88
- }
89
- });
96
+ let keysToDisplay = [];
97
+ if (e.detail.key === 'event-initial-subset') keysToDisplay = this._performInitialSubsetSearch(e.detail.value);
98
+ else {
99
+ this._fullData.forEach(value => {
100
+ if (value.text.toLowerCase().indexOf(e.detail.value.toLowerCase()) > -1) {
101
+ keysToDisplay.push(value.key);
102
+ }
103
+ });
104
+ }
90
105
 
91
106
  setTimeout(() => {
92
- e.detail.searchCompleteCallback(keysToDisplay);
107
+ e.detail.searchCompleteCallback({ keysToDisplay: keysToDisplay });
93
108
  // eslint-disable-next-line no-console
94
109
  console.log(`Filter dimension "${e.detail.key}" searched: ${e.detail.value}`);
95
110
  }, 2000);
96
111
 
97
112
  }
98
113
 
114
+ _performInitialSubsetSearch(searchValue) {
115
+ const initialSubset = ['admin', 'instructor'];
116
+ let keysToDisplay = [];
117
+ if (searchValue === '') {
118
+ keysToDisplay = initialSubset;
119
+ this._fullDataInitialSubset.forEach(value => {
120
+ if (value.selected) {
121
+ if (!keysToDisplay.includes(value.key)) keysToDisplay.push(value.key);
122
+ }
123
+ });
124
+ } else {
125
+ this._fullDataInitialSubset.forEach(value => {
126
+ if (value.text.toLowerCase().indexOf(searchValue.toLowerCase()) > -1) {
127
+ keysToDisplay.push(value.key);
128
+ }
129
+ });
130
+ }
131
+ return keysToDisplay;
132
+ }
133
+
99
134
  }
100
135
  customElements.define('d2l-filter-search-demo', FilterSearchDemo);
@@ -590,10 +590,13 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
590
590
  this._activeFiltersSubscribers.updateSubscribers();
591
591
  }
592
592
 
593
- _dispatchDimensionFirstOpenEvent(key) {
594
- if (!this._openedDimensions.includes(key)) {
595
- this.dispatchEvent(new CustomEvent('d2l-filter-dimension-first-open', { bubbles: true, composed: false, detail: { key: key } }));
596
- this._openedDimensions.push(key);
593
+ _dispatchDimensionFirstOpenEvent(dimension) {
594
+ if (!this._openedDimensions.includes(dimension.key)) {
595
+ this.dispatchEvent(new CustomEvent('d2l-filter-dimension-first-open', { bubbles: true, composed: false, detail: { key: dimension.key } }));
596
+ if (dimension.searchType === 'manual') {
597
+ this._search(dimension);
598
+ }
599
+ this._openedDimensions.push(dimension.key);
597
600
  }
598
601
  }
599
602
 
@@ -636,7 +639,7 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
636
639
  this._dimensions.forEach(dimension => {
637
640
  if (dimension.searchType !== 'none' && dimension.searchValue !== '') {
638
641
  dimension.searchValue = '';
639
- this._performDimensionSearch(dimension);
642
+ this._search(dimension);
640
643
  }
641
644
  this._performDimensionClear(dimension);
642
645
  });
@@ -675,7 +678,7 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
675
678
  }
676
679
  this._activeFiltersSubscribers.updateSubscribers();
677
680
  } else if (prop === 'values') {
678
- if (dimension.searchValue) shouldSearch = true;
681
+ if (dimension.searchValue || dimension.searchType === 'manual') shouldSearch = true;
679
682
  shouldRecount = true;
680
683
  shouldResizeDropdown = true;
681
684
  this._activeFiltersSubscribers.updateSubscribers();
@@ -718,7 +721,7 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
718
721
  const dimension = this._dimensions.find(dimension => dimension.key === this._activeDimensionKey);
719
722
  if (dimension.introductoryText) announce(dimension.introductoryText);
720
723
  if (dimension.selectedFirst) this._updateDimensionShouldBubble(dimension);
721
- this._dispatchDimensionFirstOpenEvent(this._activeDimensionKey);
724
+ this._dispatchDimensionFirstOpenEvent(dimension);
722
725
  }
723
726
 
724
727
  _handleDropdownClose(e) {
@@ -730,8 +733,9 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
730
733
  _handleDropdownOpen(e) {
731
734
  this.opened = true;
732
735
  if (this._dimensions.length === 1) {
733
- this._dispatchDimensionFirstOpenEvent(this._dimensions[0].key);
734
- if (this._dimensions[0].introductoryText) announce(this._dimensions[0].introductoryText);
736
+ const dimension = this._dimensions[0];
737
+ this._dispatchDimensionFirstOpenEvent(dimension);
738
+ if (dimension.introductoryText) announce(dimension.introductoryText);
735
739
  }
736
740
  this._stopPropagation(e);
737
741
  }
@@ -752,30 +756,7 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
752
756
  if (dimension.selectedFirst) {
753
757
  this._updateDimensionShouldBubble(dimension);
754
758
  }
755
-
756
- if (dimension.searchType === 'automatic' || searchValue === '') {
757
- this._performDimensionSearch(dimension);
758
- } else if (dimension.searchType === 'manual') {
759
- dimension.loading = true;
760
- this.requestUpdate();
761
-
762
- this.dispatchEvent(new CustomEvent('d2l-filter-dimension-search', {
763
- bubbles: false,
764
- composed: false,
765
- detail: {
766
- key: dimension.key,
767
- value: searchValue,
768
- searchCompleteCallback: function(keysToDisplay) {
769
- requestAnimationFrame(() => {
770
- dimension.searchKeysToDisplay = keysToDisplay;
771
- this._performDimensionSearch(dimension);
772
- dimension.loading = false;
773
- this.requestUpdate();
774
- });
775
- }.bind(this)
776
- }
777
- }));
778
- }
759
+ this._search(dimension);
779
760
  }
780
761
 
781
762
  _handleSlotChange(e) {
@@ -861,7 +842,10 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
861
842
  switch (dimension.type) {
862
843
  case 'd2l-filter-dimension-set':
863
844
  dimension.values.forEach(value => {
864
- if (dimension.searchValue === '') {
845
+ if (
846
+ (dimension.searchType === 'automatic' && dimension.searchValue === '')
847
+ || dimension.displayAllKeys
848
+ ) {
865
849
  value.hidden = false;
866
850
  return;
867
851
  }
@@ -885,6 +869,33 @@ class Filter extends FocusMixin(LocalizeCoreElement(RtlMixin(LitElement))) {
885
869
  }
886
870
  }
887
871
 
872
+ _search(dimension) {
873
+ if (dimension.searchType === 'automatic') {
874
+ this._performDimensionSearch(dimension);
875
+ } else if (dimension.searchType === 'manual') {
876
+ dimension.loading = true;
877
+ this.requestUpdate();
878
+
879
+ this.dispatchEvent(new CustomEvent('d2l-filter-dimension-search', {
880
+ bubbles: false,
881
+ composed: false,
882
+ detail: {
883
+ key: dimension.key,
884
+ value: dimension.searchValue,
885
+ searchCompleteCallback: function({ keysToDisplay = [], displayAllKeys = false } = {}) {
886
+ requestAnimationFrame(() => {
887
+ dimension.displayAllKeys = displayAllKeys;
888
+ dimension.searchKeysToDisplay = keysToDisplay;
889
+ this._performDimensionSearch(dimension);
890
+ dimension.loading = false;
891
+ this.requestUpdate();
892
+ });
893
+ }.bind(this)
894
+ }
895
+ }));
896
+ }
897
+ }
898
+
888
899
  _setDimensionChangeEvent(dimension, change, dimensionCleared) {
889
900
  if (!this._changeEventsToDispatch.has(dimension.key)) {
890
901
  this._changeEventsToDispatch.set(dimension.key, { dimensionKey: dimension.key, cleared: false, changes: new Map() });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.124.0",
3
+ "version": "2.126.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",