Skip to content

Commit

Permalink
API – Return Hidden for Category and CategoryGroup (#2062)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioslife authored Dec 15, 2023
1 parent a5557ca commit af9efa0
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 1 deletion.
25 changes: 25 additions & 0 deletions packages/api/methods.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,25 @@ 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(
expect.arrayContaining([
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,
}),
]),
Expand All @@ -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,
}),
]),
Expand Down
1 change: 1 addition & 0 deletions packages/desktop-client/src/components/budget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ function Budget(props: BudgetProps) {
category.name,
category.cat_group,
category.is_income,
category.hidden,
);

setNewCategoryForGroup(null);
Expand Down
2 changes: 2 additions & 0 deletions packages/loot-core/src/client/actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions packages/loot-core/src/server/api-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
},
Expand All @@ -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;
}
Expand All @@ -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),
};
},
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

Expand Down
2 changes: 2 additions & 0 deletions packages/loot-core/src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ handlers['category-create'] = mutator(async function ({
name,
groupId,
isIncome,
hidden,
}) {
return withUndo(async () => {
if (!groupId) {
Expand All @@ -288,6 +289,7 @@ handlers['category-create'] = mutator(async function ({
name,
cat_group: groupId,
is_income: isIncome ? 1 : 0,
hidden: hidden ? 1 : 0,
});
});
});
Expand Down
7 changes: 6 additions & 1 deletion packages/loot-core/src/types/server-handlers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ export interface ServerHandlers {

'budget-set-type': (arg: { type }) => Promise<unknown>;

'category-create': (arg: { name; groupId; isIncome }) => Promise<unknown>;
'category-create': (arg: {
name;
groupId;
isIncome;
hidden: boolean;
}) => Promise<unknown>;

'category-update': (category) => Promise<unknown>;

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2062.md
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit af9efa0

Please sign in to comment.