Skip to content
Snippets Groups Projects
Unverified Commit 3daff438 authored by DHRUV RAMDEV's avatar DHRUV RAMDEV Committed by GitHub
Browse files

feat: Don't allow duplicate cat-groups in budget (#2262)

* feat: Don't allow duplicate cat-groups in budget

* Add release notes

* fix: error message

* pass group instead of name for accurate error message

* improve error message
parent 5914469b
No related branches found
No related tags found
No related merge requests found
......@@ -313,7 +313,24 @@ function BudgetInner(props: BudgetProps) {
}
};
const groupNameAlreadyExistsNotification = group => {
props.addNotification({
type: 'error',
message: `A ${group.hidden ? 'hidden ' : ''}${group.name}’ category group already exists.`,
});
};
const onSaveGroup = async group => {
const categories = await props.getCategories();
const matchingGroups = categories.grouped
.filter(g => g.name.toUpperCase() === group.name.toUpperCase())
.filter(g => group.id === 'new' || group.id !== g.id);
if (matchingGroups.length > 0) {
groupNameAlreadyExistsNotification(matchingGroups[0]);
return;
}
if (group.id === 'new') {
const id = await props.createGroup(group.name);
setIsAddingGroup(false);
......
......@@ -304,6 +304,17 @@ export async function getCategoriesGrouped(): Promise<
}
export async function insertCategoryGroup(group) {
// Don't allow duplicate group
const existingGroup = await first(
`SELECT id, name, hidden FROM category_groups WHERE UPPER(name) = ? and tombstone = 0 LIMIT 1`,
[group.name.toUpperCase()],
);
if (existingGroup) {
throw new Error(
`A ${existingGroup.hidden ? 'hidden ' : ''}${existingGroup.name}’ category group already exists.`,
);
}
const lastGroup = await first(`
SELECT sort_order FROM category_groups WHERE tombstone = 0 ORDER BY sort_order DESC, id DESC LIMIT 1
`);
......
---
category: Features
authors: [dhruvramdev]
---
Don't allow duplicate category groups
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment