-
Notifications
You must be signed in to change notification settings - Fork 89
fix(list, filter): fix sync between list items and filtered data #10342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
21073fe
6f39567
f327703
f4abe6e
eee1082
499875e
a41ef76
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,7 +163,7 @@ export class List | |
| @Prop() filterProps: string[]; | ||
|
|
||
| @Watch("filterProps") | ||
| async handlefilterPropsChange(): Promise<void> { | ||
| async handleFilterPropsChange(): Promise<void> { | ||
| this.performFilter(); | ||
| } | ||
|
|
||
|
|
@@ -232,7 +232,7 @@ export class List | |
| @Watch("selectionMode") | ||
| @Watch("selectionAppearance") | ||
| handleListItemChange(): void { | ||
| this.updateListItems(); | ||
| this.updateListItems({ performFilter: true }); | ||
| } | ||
|
|
||
| //-------------------------------------------------------------------------- | ||
|
|
@@ -409,7 +409,7 @@ export class List | |
| connectLocalized(this); | ||
| connectMessages(this); | ||
| this.connectObserver(); | ||
| this.updateListItems(); | ||
| this.updateListItems({ performFilter: true }); | ||
| this.setUpSorting(); | ||
| this.setParentList(); | ||
| } | ||
|
|
@@ -471,7 +471,9 @@ export class List | |
|
|
||
| listItems: HTMLCalciteListItemElement[] = []; | ||
|
|
||
| mutationObserver = createObserver("mutation", () => this.updateListItems()); | ||
| mutationObserver = createObserver("mutation", () => | ||
| this.updateListItems({ performFilter: true }), | ||
| ); | ||
|
|
||
| visibleItems: HTMLCalciteListItemElement[] = []; | ||
|
|
||
|
|
@@ -807,10 +809,15 @@ export class List | |
| this.filteredData = filterEl.filteredItems as ItemData; | ||
| } | ||
|
|
||
| this.updateListItems(emit); | ||
| this.updateListItems({ emitFilterChange: emit }); | ||
| } | ||
|
|
||
| private async filterAndUpdateData(): Promise<void> { | ||
| await this.filterEl?.filter(this.filterText); | ||
| this.updateFilteredData(); | ||
| } | ||
|
|
||
| private async performFilter(): Promise<void> { | ||
| private performFilter(): void { | ||
| const { filterEl, filterText, filterProps } = this; | ||
|
|
||
| if (!filterEl) { | ||
|
|
@@ -819,8 +826,7 @@ export class List | |
|
|
||
| filterEl.value = filterText; | ||
| filterEl.filterProps = filterProps; | ||
| await filterEl.filter(filterText); | ||
| this.updateFilteredData(); | ||
| this.filterAndUpdateData(); | ||
| } | ||
|
|
||
| private setFilterEl = (el: HTMLCalciteFilterElement): void => { | ||
|
|
@@ -844,39 +850,47 @@ export class List | |
| })); | ||
| }; | ||
|
|
||
| private updateListItems = debounce((emitFilterChange = false): void => { | ||
| const { selectionAppearance, selectionMode, dragEnabled, el } = this; | ||
| private updateListItems = debounce( | ||
| (options?: { emitFilterChange?: boolean; performFilter?: boolean }): void => { | ||
| const emitFilterChange = options?.emitFilterChange ?? false; | ||
| const performFilter = options?.performFilter ?? false; | ||
|
|
||
| const { selectionAppearance, selectionMode, dragEnabled, el, filterEl, filterEnabled } = this; | ||
|
|
||
| const items = Array.from(this.el.querySelectorAll(listItemSelector)); | ||
|
|
||
| const items = Array.from(this.el.querySelectorAll(listItemSelector)); | ||
| items.forEach((item) => { | ||
| item.selectionAppearance = selectionAppearance; | ||
| item.selectionMode = selectionMode; | ||
| if (item.closest("calcite-list") === el) { | ||
| item.dragHandle = dragEnabled; | ||
| } | ||
| }); | ||
|
|
||
| items.forEach((item) => { | ||
| item.selectionAppearance = selectionAppearance; | ||
| item.selectionMode = selectionMode; | ||
| if (item.closest("calcite-list") === el) { | ||
| item.dragHandle = dragEnabled; | ||
| if (this.parentListEl) { | ||
| this.setUpSorting(); | ||
| return; | ||
| } | ||
| }); | ||
|
|
||
| if (this.parentListEl) { | ||
| this.setUpSorting(); | ||
| return; | ||
| } | ||
| this.listItems = items; | ||
| if (filterEnabled && performFilter) { | ||
| this.dataForFilter = this.getItemData(); | ||
|
|
||
| this.listItems = items; | ||
| if (this.filterEnabled) { | ||
| this.dataForFilter = this.getItemData(); | ||
| if (this.filterEl) { | ||
| this.filterEl.items = this.dataForFilter; | ||
| if (filterEl) { | ||
| filterEl.items = this.dataForFilter; | ||
| this.filterAndUpdateData(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be awaited on to avoid synchronization issues?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jcfranco It doesn't. The filter component will fire an event once the filter actually occurs. This is part of the oddness of having a filter component that does the filtering. The syncing is odd. |
||
| } | ||
| } | ||
| } | ||
| this.visibleItems = this.listItems.filter((item) => !item.closed && !item.hidden); | ||
| this.updateFilteredItems(emitFilterChange); | ||
| this.borderItems(); | ||
| this.focusableItems = this.filteredItems.filter((item) => !item.disabled); | ||
| this.setActiveListItem(); | ||
| this.updateSelectedItems(); | ||
| this.setUpSorting(); | ||
| }, debounceTimeout); | ||
| this.visibleItems = this.listItems.filter((item) => !item.closed && !item.hidden); | ||
| this.updateFilteredItems(emitFilterChange); | ||
| this.borderItems(); | ||
| this.focusableItems = this.filteredItems.filter((item) => !item.disabled); | ||
| this.setActiveListItem(); | ||
| this.updateSelectedItems(); | ||
| this.setUpSorting(); | ||
| }, | ||
| debounceTimeout, | ||
| ); | ||
|
|
||
| private focusRow = (focusEl: HTMLCalciteListItemElement): void => { | ||
| const { focusableItems } = this; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.