From 34b8a29228fb916b358b50cc9bd2931ae44a0f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C3=BCmmel?= <7893682+janstuemmel@users.noreply.github.com> Date: Thu, 15 Jun 2023 17:52:10 +0200 Subject: [PATCH] fix: Fix show non-grouped items as `undefined` (#229) closes #66 --- src/common/util/groupBy.spec.ts | 9 +++++++++ src/common/util/groupBy.ts | 2 +- src/popup/components/SectionList.tsx | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/common/util/groupBy.spec.ts b/src/common/util/groupBy.spec.ts index 540659b..7d72816 100644 --- a/src/common/util/groupBy.spec.ts +++ b/src/common/util/groupBy.spec.ts @@ -10,11 +10,20 @@ it('should group items by \'group\'', () => { }, { foo: '1', group: 'bar' + }, { + foo: '1', + group: undefined }]; const grouped = groupBy(config, ['group']); expect(grouped).toMatchInlineSnapshot(` { + "": [ + { + "foo": "1", + "group": undefined, + }, + ], "bar": [ { "foo": "1", diff --git a/src/common/util/groupBy.ts b/src/common/util/groupBy.ts index 322c9c0..56f75df 100644 --- a/src/common/util/groupBy.ts +++ b/src/common/util/groupBy.ts @@ -1,6 +1,6 @@ export const groupBy = (arr: T[], keys: (keyof T)[]): { [key: string]: T[] } => { return arr.reduce((storage, item) => { - const objKey = keys.map(key => `${ item[key] }`).join(':'); + const objKey = keys.map(key => item[key]).join(':'); if (storage[objKey]) { storage[objKey].push(item); } else { diff --git a/src/popup/components/SectionList.tsx b/src/popup/components/SectionList.tsx index 8fd3071..43f4d38 100644 --- a/src/popup/components/SectionList.tsx +++ b/src/popup/components/SectionList.tsx @@ -111,7 +111,7 @@ export default ({ return item.type === 'section' ? renderSection({ key, style, - title: item.title || 'Ungrouped', + title: item.title ? item.title : 'Ungrouped', }) : renderItem({ key, style,