From 704c654d8268181e54702f655a5ba2f4dc1e6256 Mon Sep 17 00:00:00 2001 From: iOSLife Date: Fri, 15 Dec 2023 18:09:14 +0000 Subject: [PATCH] =?UTF-8?q?API=20=E2=80=93=20=20Return=20Hidden=20for=20Ca?= =?UTF-8?q?tegory=20and=20CategoryGroup=20(#2062)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/api/methods.test.ts | 25 +++++++++++++++++++ .../src/components/budget/index.tsx | 1 + .../loot-core/src/client/actions/queries.ts | 2 ++ packages/loot-core/src/server/api-models.ts | 8 ++++++ packages/loot-core/src/server/api.ts | 1 + packages/loot-core/src/server/main.ts | 2 ++ .../loot-core/src/types/server-handlers.d.ts | 7 +++++- upcoming-release-notes/2062.md | 6 +++++ 8 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 upcoming-release-notes/2062.md diff --git a/packages/api/methods.test.ts b/packages/api/methods.test.ts index 3453975fe0f..cca376242fc 100644 --- a/packages/api/methods.test.ts +++ b/packages/api/methods.test.ts @@ -119,6 +119,11 @@ describe('API CRUD operations', () => { 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(); expect(categories).toEqual( @@ -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/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); 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; diff --git a/packages/loot-core/src/server/api-models.ts b/packages/loot-core/src/server/api-models.ts index 04bdc76f417..e1741d68aaf 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, + hidden: category.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 ('hidden' in category) { + result.hidden = category.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, + hidden: group.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 ('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..34a9730575b 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 384500214a2..431023d76b4 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 c62104a18ff..1e85f00458d 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 }) => Promise; + 'category-create': (arg: { + name; + groupId; + isIncome; + hidden: boolean; + }) => 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..c8cb99f6039 --- /dev/null +++ b/upcoming-release-notes/2062.md @@ -0,0 +1,6 @@ +--- +category: Enhancements +authors: [iOSLife] +--- + +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