Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: allow prefix for budget templates #4032

Merged
merged 5 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/loot-core/src/server/budget/goal-template.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ repeat 'repeat interval'
/ 'year'i { return { annual: true }}
/ years: positive _ 'years'i { return { annual: true, repeat: +years }}

limit = _? upTo _ amount: amount _ 'per week starting'i _ start:date _? hold:hold?
limit = _? upTo _ amount: amount _ 'per week starting'i _ start:date _? hold:hold?
{ return {amount: amount, hold: hold, period: 'weekly', start: start }}
/ _? upTo _ amount: amount _ 'per day'i _? hold: hold?
{ return {amount: amount, hold: hold, period: 'daily', start:null }}
/ _? upTo _ amount: amount _? hold: hold?
/ _? upTo _ amount: amount _? hold: hold?
{ return {amount: amount, hold: hold, period: 'monthly', start:null }}

percentOf = percent:percent _ of _ 'previous'i _ { return { percent: percent, prev: true}}
Expand All @@ -63,7 +63,7 @@ schedule = 'schedule'i
full = 'full'i _ {return true}
priority = '-'i number: number {return number}
remainder = 'remainder'i _? weight: positive? { return +weight || 1 }
template = '#template' priority: priority? {return {priority: +priority, directive: 'template'}}
template = [^#]* '#template' priority: priority? {return {priority: +priority, directive: 'template'}}
UnderKoen marked this conversation as resolved.
Show resolved Hide resolved
goal = '#goal'i { return 'goal'}

_ 'space' = ' '+
Expand Down
20 changes: 20 additions & 0 deletions packages/loot-core/src/server/budget/template-notes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,26 @@ describe('storeTemplates', () => {
},
],
},
{
description:
'Stores template when prefix is used with valid template notes',
mockTemplateNotes: [
{
id: 'cat1',
name: 'Category 1',
note: 'test: #template 12',
},
],
expectedTemplates: [
{
type: 'simple',
monthly: 12,
limit: null,
priority: 0,
directive: 'template',
},
],
},
{
description:
'Stores templates for categories with valid goal directive template notes',
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/budget/template-notes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async function getCategoriesWithTemplates(): Promise<CategoryWithTemplates[]> {
const trimmedLine = line.trim();

if (
!trimmedLine.startsWith(TEMPLATE_PREFIX) &&
!trimmedLine.match(new RegExp(`^[^#]*${TEMPLATE_PREFIX}`)) &&
!trimmedLine.startsWith(GOAL_PREFIX)
) {
return;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4032.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [UnderKoen]
---

Allow note prefixes in budget templates.
Loading