Fix list undefined group (#2979)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-13 23:24:52 +06:00 committed by GitHub
parent ad4394d541
commit 2a11846d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 13 deletions

View File

@ -132,7 +132,7 @@
</script>
{#each categories as category, i (typeof category === 'object' ? category.name : category)}
{@const items = groupByKey === noCategory || category === undefined ? docs : getGroupByValues(groupByDocs, category)}
{@const items = groupByKey === noCategory ? docs : getGroupByValues(groupByDocs, category)}
<ListCategory
{elementByIndex}
{indexById}

View File

@ -506,11 +506,7 @@ export type FixedWidthStore = Record<string, number>
export const fixedWidthStore = writable<FixedWidthStore>({})
export function groupBy<T extends Doc> (
docs: T[],
key: string,
categories?: CategoryType[]
): { [key: string | number]: T[] } {
export function groupBy<T extends Doc> (docs: T[], key: string, categories?: CategoryType[]): Record<any, T[]> {
return docs.reduce((storage: { [key: string]: T[] }, item: T) => {
let group = getObjectValue(key, item) ?? undefined
@ -536,16 +532,12 @@ export function groupBy<T extends Doc> (
/**
* @public
*/
export function getGroupByValues<T extends Doc> (
groupByDocs: Record<string | number, T[]>,
category: CategoryType
): T[] {
export function getGroupByValues<T extends Doc> (groupByDocs: Record<any, T[]>, category: CategoryType): T[] {
if (typeof category === 'object') {
return groupByDocs[category.name] ?? []
} else if (category !== undefined) {
return groupByDocs[category] ?? []
} else {
return groupByDocs[category as any] ?? []
}
return []
}
/**