mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-23 08:48:01 +00:00
Fix list undefined group (#2979)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
ad4394d541
commit
2a11846d6e
@ -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}
|
||||||
|
@ -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 []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user