From b611f3a2a2254c3b3af798e0836cdf63a692bf45 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 07:57:16 -0500 Subject: [PATCH 01/10] adding hidden property to category and categoryGroup for API models --- packages/loot-core/src/server/api-models.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/loot-core/src/server/api-models.ts b/packages/loot-core/src/server/api-models.ts index 04bdc76f417..4f82605ef5f 100644 --- a/packages/loot-core/src/server/api-models.ts +++ b/packages/loot-core/src/server/api-models.ts @@ -32,6 +32,7 @@ export const categoryModel = { id: category.id, name: category.name, is_income: category.is_income ? true : false, + is_hidden: category.is_hidden ? true : false, group_id: category.cat_group, }; }, @@ -41,6 +42,9 @@ export const categoryModel = { if ('is_income' in category) { result.is_income = category.is_income ? 1 : 0; } + if ('is_hidden' in category) { + result.hidden = category.is_hidden ? 1 : 0; + } if ('group_id' in category) { result.cat_group = category.group_id; } @@ -56,6 +60,7 @@ export const categoryGroupModel = { id: group.id, name: group.name, is_income: group.is_income ? true : false, + is_hidden: group.is_hidden ? true : false, categories: group.categories.map(categoryModel.toExternal), }; }, @@ -65,6 +70,9 @@ export const categoryGroupModel = { if ('is_income' in group) { result.is_income = group.is_income ? 1 : 0; } + if ('is_hidden' in group) { + result.hidden = group.is_hidden ? 1 : 0; + } if ('categories' in group) { result.categories = group.categories.map(categoryModel.fromExternal); } From 8f69b7f061c0b2ee4a3e1c732a2f88ecb7230617 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 08:50:00 -0500 Subject: [PATCH 02/10] adding tests and making them pass --- packages/api/methods.test.ts | 25 +++++++++++++++++++ packages/loot-core/src/server/api-models.ts | 13 +++++----- packages/loot-core/src/server/api.ts | 1 + packages/loot-core/src/server/main.ts | 2 ++ .../loot-core/src/types/server-handlers.d.ts | 2 +- upcoming-release-notes/2062.md | 8 ++++++ 6 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 upcoming-release-notes/2062.md diff --git a/packages/api/methods.test.ts b/packages/api/methods.test.ts index 3453975fe0f..bdf08e71386 100644 --- a/packages/api/methods.test.ts +++ b/packages/api/methods.test.ts @@ -117,7 +117,12 @@ describe('API CRUD operations', () => { }); const categoryId = await api.createCategory({ name: 'test-budget', + group_id: mainGroupId + }); + const categoryIdHidden = await api.createCategory({ + name: 'test-budget-hidden', group_id: mainGroupId, + hidden: true }); let categories = await api.getCategories(); @@ -126,6 +131,13 @@ describe('API CRUD operations', () => { expect.objectContaining({ id: categoryId, name: 'test-budget', + hidden: false, + group_id: mainGroupId, + }), + expect.objectContaining({ + id: categoryIdHidden, + name: 'test-budget-hidden', + hidden: true, group_id: mainGroupId, }), ]), @@ -137,12 +149,25 @@ describe('API CRUD operations', () => { group_id: secondaryGroupId, }); + await api.updateCategory(categoryIdHidden, { + name: 'updated-budget-hidden', + group_id: secondaryGroupId, + hidden: false, + }); + categories = await api.getCategories(); expect(categories).toEqual( expect.arrayContaining([ expect.objectContaining({ id: categoryId, name: 'updated-budget', + hidden: false, + group_id: secondaryGroupId, + }), + expect.objectContaining({ + id: categoryIdHidden, + name: 'updated-budget-hidden', + hidden: false, group_id: secondaryGroupId, }), ]), diff --git a/packages/loot-core/src/server/api-models.ts b/packages/loot-core/src/server/api-models.ts index 4f82605ef5f..931b2ca3c2a 100644 --- a/packages/loot-core/src/server/api-models.ts +++ b/packages/loot-core/src/server/api-models.ts @@ -28,11 +28,12 @@ export const categoryModel = { ...models.categoryModel, toExternal(category) { + console.log(category.hidden) return { id: category.id, name: category.name, is_income: category.is_income ? true : false, - is_hidden: category.is_hidden ? true : false, + hidden: category.hidden ? true : false, group_id: category.cat_group, }; }, @@ -42,8 +43,8 @@ export const categoryModel = { if ('is_income' in category) { result.is_income = category.is_income ? 1 : 0; } - if ('is_hidden' in category) { - result.hidden = category.is_hidden ? 1 : 0; + if ('hidden' in category) { + result.hidden = category.hidden ? 1 : 0; } if ('group_id' in category) { result.cat_group = category.group_id; @@ -60,7 +61,7 @@ export const categoryGroupModel = { id: group.id, name: group.name, is_income: group.is_income ? true : false, - is_hidden: group.is_hidden ? true : false, + hidden: group.hidden ? true : false, categories: group.categories.map(categoryModel.toExternal), }; }, @@ -70,8 +71,8 @@ export const categoryGroupModel = { if ('is_income' in group) { result.is_income = group.is_income ? 1 : 0; } - if ('is_hidden' in group) { - result.hidden = group.is_hidden ? 1 : 0; + if ('hidden' in group) { + result.hidden = group.hidden ? 1 : 0; } if ('categories' in group) { result.categories = group.categories.map(categoryModel.fromExternal); diff --git a/packages/loot-core/src/server/api.ts b/packages/loot-core/src/server/api.ts index 29288bdc8d6..0e2e84cf585 100644 --- a/packages/loot-core/src/server/api.ts +++ b/packages/loot-core/src/server/api.ts @@ -556,6 +556,7 @@ handlers['api/category-create'] = withMutation(async function ({ category }) { name: category.name, groupId: category.group_id, isIncome: category.is_income, + hidden: category.hidden }); }); diff --git a/packages/loot-core/src/server/main.ts b/packages/loot-core/src/server/main.ts index 851f2a601d7..3fadbf0bb91 100644 --- a/packages/loot-core/src/server/main.ts +++ b/packages/loot-core/src/server/main.ts @@ -278,6 +278,7 @@ handlers['category-create'] = mutator(async function ({ name, groupId, isIncome, + hidden, }) { return withUndo(async () => { if (!groupId) { @@ -288,6 +289,7 @@ handlers['category-create'] = mutator(async function ({ name, cat_group: groupId, is_income: isIncome ? 1 : 0, + hidden: hidden ? 1 : 0, }); }); }); diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts index 9553f836363..20491426a9a 100644 --- a/packages/loot-core/src/types/server-handlers.d.ts +++ b/packages/loot-core/src/types/server-handlers.d.ts @@ -74,7 +74,7 @@ export interface ServerHandlers { 'budget-set-type': (arg: { type }) => Promise; - 'category-create': (arg: { name; groupId; isIncome }) => Promise; + 'category-create': (arg: { name; groupId; isIncome; hidden }) => Promise; 'category-update': (category) => Promise; diff --git a/upcoming-release-notes/2062.md b/upcoming-release-notes/2062.md new file mode 100644 index 00000000000..cb7ba297708 --- /dev/null +++ b/upcoming-release-notes/2062.md @@ -0,0 +1,8 @@ +--- +category: API Features +authors: iOSLife +--- + +Adds a property to the returned items in the API for category and categoryGroup to inform if it is hidden. + +Not sure if there are more changes needed for this functionality, but willing to make them if I can get some direction. \ No newline at end of file From 73508a63896dab103d8f3d426927dd84a23587d0 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 08:52:33 -0500 Subject: [PATCH 03/10] updating release note category --- upcoming-release-notes/2062.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upcoming-release-notes/2062.md b/upcoming-release-notes/2062.md index cb7ba297708..358db84d31b 100644 --- a/upcoming-release-notes/2062.md +++ b/upcoming-release-notes/2062.md @@ -1,5 +1,5 @@ --- -category: API Features +category: Enhancements authors: iOSLife --- From 77742ca9762d5c09092e49641f733ff78b5d8b7d Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 08:53:38 -0500 Subject: [PATCH 04/10] updating release note authors to be a list --- upcoming-release-notes/2062.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/upcoming-release-notes/2062.md b/upcoming-release-notes/2062.md index 358db84d31b..13857dfec68 100644 --- a/upcoming-release-notes/2062.md +++ b/upcoming-release-notes/2062.md @@ -1,6 +1,6 @@ --- category: Enhancements -authors: iOSLife +authors: [iOSLife] --- Adds a property to the returned items in the API for category and categoryGroup to inform if it is hidden. From ad7d3d77abdbd6df402ecfe62ca290cccfd0c88d Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 08:54:27 -0500 Subject: [PATCH 05/10] removing extra comment from release note --- upcoming-release-notes/2062.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/upcoming-release-notes/2062.md b/upcoming-release-notes/2062.md index 13857dfec68..c8cb99f6039 100644 --- a/upcoming-release-notes/2062.md +++ b/upcoming-release-notes/2062.md @@ -3,6 +3,4 @@ category: Enhancements authors: [iOSLife] --- -Adds a property to the returned items in the API for category and categoryGroup to inform if it is hidden. - -Not sure if there are more changes needed for this functionality, but willing to make them if I can get some direction. \ No newline at end of file +Adds a property to the returned items in the API for category and categoryGroup to inform if it is hidden. \ No newline at end of file From 2764d83d2c3b74d8b13bd59fd6b241bac21d10d6 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 08:59:09 -0500 Subject: [PATCH 06/10] addressing linting issues --- packages/api/methods.test.ts | 4 ++-- packages/loot-core/src/server/api.ts | 2 +- packages/loot-core/src/types/server-handlers.d.ts | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/api/methods.test.ts b/packages/api/methods.test.ts index bdf08e71386..cca376242fc 100644 --- a/packages/api/methods.test.ts +++ b/packages/api/methods.test.ts @@ -117,12 +117,12 @@ describe('API CRUD operations', () => { }); const categoryId = await api.createCategory({ name: 'test-budget', - group_id: mainGroupId + group_id: mainGroupId, }); const categoryIdHidden = await api.createCategory({ name: 'test-budget-hidden', group_id: mainGroupId, - hidden: true + hidden: true, }); let categories = await api.getCategories(); diff --git a/packages/loot-core/src/server/api.ts b/packages/loot-core/src/server/api.ts index 0e2e84cf585..34a9730575b 100644 --- a/packages/loot-core/src/server/api.ts +++ b/packages/loot-core/src/server/api.ts @@ -556,7 +556,7 @@ handlers['api/category-create'] = withMutation(async function ({ category }) { name: category.name, groupId: category.group_id, isIncome: category.is_income, - hidden: category.hidden + hidden: category.hidden, }); }); diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts index 20491426a9a..abbc3ed5ac2 100644 --- a/packages/loot-core/src/types/server-handlers.d.ts +++ b/packages/loot-core/src/types/server-handlers.d.ts @@ -74,7 +74,12 @@ export interface ServerHandlers { 'budget-set-type': (arg: { type }) => Promise; - 'category-create': (arg: { name; groupId; isIncome; hidden }) => Promise; + 'category-create': (arg: { + name; + groupId; + isIncome; + hidden + }) => Promise; 'category-update': (category) => Promise; From f716f3ee28bdfaa96b363f75710c7555ff5b5bb4 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 09:03:29 -0500 Subject: [PATCH 07/10] addressing more linting issues --- packages/loot-core/src/server/api-models.ts | 1 - packages/loot-core/src/types/server-handlers.d.ts | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/loot-core/src/server/api-models.ts b/packages/loot-core/src/server/api-models.ts index 931b2ca3c2a..e1741d68aaf 100644 --- a/packages/loot-core/src/server/api-models.ts +++ b/packages/loot-core/src/server/api-models.ts @@ -28,7 +28,6 @@ export const categoryModel = { ...models.categoryModel, toExternal(category) { - console.log(category.hidden) return { id: category.id, name: category.name, diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts index abbc3ed5ac2..8479e70bcbb 100644 --- a/packages/loot-core/src/types/server-handlers.d.ts +++ b/packages/loot-core/src/types/server-handlers.d.ts @@ -74,11 +74,11 @@ export interface ServerHandlers { 'budget-set-type': (arg: { type }) => Promise; - 'category-create': (arg: { - name; - groupId; - isIncome; - hidden + 'category-create': (arg: { + name; + groupId; + isIncome; + hidden; }) => Promise; 'category-update': (category) => Promise; From 95208d144fccaee04c1ae9771299141b8ffbeafa Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 09:03:46 -0500 Subject: [PATCH 08/10] adding hidden to createCategory query --- packages/loot-core/src/client/actions/queries.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/loot-core/src/client/actions/queries.ts b/packages/loot-core/src/client/actions/queries.ts index 0482d17dafc..6c64b08c09a 100644 --- a/packages/loot-core/src/client/actions/queries.ts +++ b/packages/loot-core/src/client/actions/queries.ts @@ -134,12 +134,14 @@ export function createCategory( name: string, groupId: string, isIncome: boolean, + hidden: boolean, ) { return async (dispatch: Dispatch) => { const id = await send('category-create', { name, groupId, isIncome, + hidden, }); dispatch(getCategories()); return id; From 8ad67d260cf73631b509529dff8890804cff8aa5 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Mon, 11 Dec 2023 09:07:22 -0500 Subject: [PATCH 09/10] adding hidden to desktop-client create --- packages/desktop-client/src/components/budget/index.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/desktop-client/src/components/budget/index.tsx b/packages/desktop-client/src/components/budget/index.tsx index db90edc0817..f32d592150c 100644 --- a/packages/desktop-client/src/components/budget/index.tsx +++ b/packages/desktop-client/src/components/budget/index.tsx @@ -274,6 +274,7 @@ function Budget(props: BudgetProps) { category.name, category.cat_group, category.is_income, + category.hidden, ); setNewCategoryForGroup(null); From 55b1771242a983b7e2a5699a7eaf97d98f1aae66 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Thu, 14 Dec 2023 20:44:36 +0000 Subject: [PATCH 10/10] adding type to new field, per PR suggestion Co-authored-by: Matiss Janis Aboltins --- packages/loot-core/src/types/server-handlers.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts index 3235c74b989..1e85f00458d 100644 --- a/packages/loot-core/src/types/server-handlers.d.ts +++ b/packages/loot-core/src/types/server-handlers.d.ts @@ -78,7 +78,7 @@ export interface ServerHandlers { name; groupId; isIncome; - hidden; + hidden: boolean; }) => Promise; 'category-update': (category) => Promise;