-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix: properly render empty state when filtering S2 ComboBox with sections #8735
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,20 +17,17 @@ export class ListCollection<T> implements Collection<Node<T>> { | |
private iterable: Iterable<Node<T>>; | ||
private firstKey: Key | null = null; | ||
private lastKey: Key | null = null; | ||
private _size: number; | ||
|
||
constructor(nodes: Iterable<Node<T>>) { | ||
this.iterable = nodes; | ||
|
||
let visit = (node: Node<T>) => { | ||
// Skip the loader node so it isn't added to the keymap and thus | ||
// doesn't influence the size count. This should only matter for RAC and S2 | ||
if (node.type !== 'loader') { | ||
this.keyMap.set(node.key, node); | ||
|
||
if (node.childNodes && node.type === 'section') { | ||
for (let child of node.childNodes) { | ||
visit(child); | ||
} | ||
this.keyMap.set(node.key, node); | ||
|
||
if (node.childNodes && node.type === 'section') { | ||
for (let child of node.childNodes) { | ||
visit(child); | ||
} | ||
} | ||
}; | ||
|
@@ -41,6 +38,7 @@ export class ListCollection<T> implements Collection<Node<T>> { | |
|
||
let last: Node<T> | null = null; | ||
let index = 0; | ||
let size = 0; | ||
for (let [key, node] of this.keyMap) { | ||
if (last) { | ||
last.nextKey = key; | ||
|
@@ -54,13 +52,19 @@ export class ListCollection<T> implements Collection<Node<T>> { | |
node.index = index++; | ||
} | ||
|
||
// Only count sections and items when determining size so that | ||
// loaders and separators in RAC/S2 don't influence the emptyState determination | ||
if (node.type === 'section' || node.type === 'item') { | ||
size++; | ||
} | ||
|
||
Comment on lines
+55
to
+60
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. this shouldn't affect v3 theoretically since there wasn't a concept of loader/separator nodes |
||
last = node; | ||
|
||
// Set nextKey as undefined since this might be the last node | ||
// If it isn't the last node, last.nextKey will properly set at start of new loop | ||
last.nextKey = undefined; | ||
} | ||
|
||
this._size = size; | ||
this.lastKey = last?.key ?? null; | ||
} | ||
|
||
|
@@ -69,7 +73,7 @@ export class ListCollection<T> implements Collection<Node<T>> { | |
} | ||
|
||
get size(): number { | ||
return this.keyMap.size; | ||
return this._size; | ||
} | ||
|
||
getKeys(): IterableIterator<Key> { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't realize we had to do this for any action handlers due to storybook 8 making implicit actions error...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... it's awful :(