-
Notifications
You must be signed in to change notification settings - Fork 10
refactor(combo): Use native groupby implementation #1802
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 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf40148
refactor(combo): Use native groupby implementation
rkaraivanov c5ef5d5
Merge remote-tracking branch 'origin/master' into rkaraivanov/refacto…
rkaraivanov 400f496
Merge branch 'master' into rkaraivanov/refactor-combo-groupby
rkaraivanov 90455fc
Merge branch 'master' into rkaraivanov/refactor-combo-groupby
rkaraivanov 5bec58e
Merge branch 'master' into rkaraivanov/refactor-combo-groupby
rkaraivanov 78c17bf
Merge branch 'master' into rkaraivanov/refactor-combo-groupby
rkaraivanov 614957b
Merge branch 'master' into rkaraivanov/refactor-combo-groupby
rkaraivanov d48bd85
Update src/components/combo/operations/group.ts
rkaraivanov 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,45 +1,46 @@ | ||
| import { groupBy } from '../../common/util.js'; | ||
| import type { DataController } from '../controllers/data.js'; | ||
| import type { ComboRecord, Keys } from '../types.js'; | ||
|
|
||
| export default class GroupDataOperation<T extends object> { | ||
| protected orderBy = new Map( | ||
| Object.entries({ | ||
| asc: 1, | ||
| desc: -1, | ||
| }) | ||
| ); | ||
| const OrderBy = Object.freeze({ asc: 1, desc: -1 }); | ||
|
|
||
| public apply(data: ComboRecord<T>[], controller: DataController<T>) { | ||
| export default class GroupDataOperation<T extends object> { | ||
| public apply( | ||
| data: ComboRecord<T>[], | ||
| controller: DataController<T> | ||
| ): ComboRecord<T>[] { | ||
| const { | ||
| groupingOptions: { groupKey, valueKey, displayKey, direction }, | ||
| } = controller; | ||
|
|
||
| if (!groupKey) return data; | ||
| if (!groupKey) { | ||
| return data; | ||
| } | ||
|
|
||
| const groups = Object.entries( | ||
| groupBy(data, (item) => item.value[groupKey] ?? 'Other') | ||
| const grouped = Map.groupBy( | ||
| data, | ||
| (item) => (item.value[groupKey] as string) ?? 'Other' | ||
| ); | ||
|
|
||
| const keys = Array.from(grouped.keys()); | ||
|
|
||
| if (direction !== 'none') { | ||
| const orderBy = this.orderBy.get(direction); | ||
| groups.sort((a, b) => { | ||
| return orderBy! * controller.compareCollator.compare(a[0], b[0]); | ||
| }); | ||
| const orderBy = OrderBy[direction]; | ||
| keys.sort((a, b) => orderBy * controller.compareCollator.compare(a, b)); | ||
| } | ||
|
|
||
| return groups.flatMap(([group, items]) => { | ||
| items.unshift({ | ||
| dataIndex: -1, | ||
| header: true, | ||
| value: { | ||
| [valueKey as Keys<T>]: group, | ||
| [displayKey as Keys<T>]: group, | ||
| [groupKey as Keys<T>]: group, | ||
| } as T, | ||
| }); | ||
|
|
||
| return items; | ||
| return keys.flatMap((key) => { | ||
| return [ | ||
| { | ||
| value: { | ||
| [valueKey as Keys<T>]: key, | ||
| [displayKey as Keys<T>]: key, | ||
| [groupKey as Keys<T>]: key, | ||
| } as T, | ||
| header: true, | ||
| dataIndex: -1, | ||
| }, | ||
| ...grouped.get(key)!, | ||
| ]; | ||
| }); | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.