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> </script>
{#each categories as category, i (typeof category === 'object' ? category.name : category)} {#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 <ListCategory
{elementByIndex} {elementByIndex}
{indexById} {indexById}

View File

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