-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract menus to separate files (change split from #2472)
- Loading branch information
1 parent
38ffccb
commit a521e7e
Showing
14 changed files
with
625 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/desktop-client/src/components/budget/report/BalanceMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, { type ComponentPropsWithoutRef } from 'react'; | ||
|
||
import { reportBudget } from 'loot-core/src/client/queries'; | ||
|
||
import { Menu } from '../../common/Menu'; | ||
import { useSheetValue } from '../../spreadsheet/useSheetValue'; | ||
|
||
export type BalanceMenuProps = Omit< | ||
ComponentPropsWithoutRef<typeof Menu>, | ||
'onMenuSelect' | 'items' | ||
> & { | ||
categoryId: string; | ||
onCarryover: (carryover: boolean) => void; | ||
}; | ||
|
||
export function BalanceMenu({ | ||
categoryId, | ||
onCarryover, | ||
...props | ||
}: BalanceMenuProps) { | ||
const carryover = useSheetValue(reportBudget.catCarryover(categoryId)); | ||
return ( | ||
<Menu | ||
{...props} | ||
onMenuSelect={name => { | ||
switch (name) { | ||
case 'carryover': | ||
onCarryover?.(!carryover); | ||
break; | ||
default: | ||
throw new Error(`Unsupported item: ${name}`); | ||
} | ||
}} | ||
items={[ | ||
{ | ||
name: 'carryover', | ||
text: carryover | ||
? 'Remove overspending rollover' | ||
: 'Rollover overspending', | ||
}, | ||
]} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/desktop-client/src/components/budget/rollover/BalanceMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { type ComponentPropsWithoutRef } from 'react'; | ||
|
||
import { rolloverBudget } from 'loot-core/src/client/queries'; | ||
|
||
import { Menu } from '../../common/Menu'; | ||
import { useSheetValue } from '../../spreadsheet/useSheetValue'; | ||
|
||
type BalanceMenuProps = Omit< | ||
ComponentPropsWithoutRef<typeof Menu>, | ||
'onMenuSelect' | 'items' | ||
> & { | ||
categoryId: string; | ||
onTransfer: () => void; | ||
onCarryover: (carryOver: boolean) => void; | ||
onCover: () => void; | ||
}; | ||
|
||
export function BalanceMenu({ | ||
categoryId, | ||
onTransfer, | ||
onCarryover, | ||
onCover, | ||
...props | ||
}: BalanceMenuProps) { | ||
const carryover = useSheetValue(rolloverBudget.catCarryover(categoryId)); | ||
const balance = useSheetValue(rolloverBudget.catBalance(categoryId)); | ||
return ( | ||
<Menu | ||
{...props} | ||
onMenuSelect={name => { | ||
switch (name) { | ||
case 'transfer': | ||
onTransfer?.(); | ||
break; | ||
case 'carryover': | ||
onCarryover?.(!carryover); | ||
break; | ||
case 'cover': | ||
onCover?.(); | ||
break; | ||
default: | ||
throw new Error(`Unsupported item: ${name}`); | ||
} | ||
}} | ||
items={[ | ||
{ | ||
name: 'transfer', | ||
text: 'Transfer to another category', | ||
}, | ||
{ | ||
name: 'carryover', | ||
text: carryover | ||
? 'Remove overspending rollover' | ||
: 'Rollover overspending', | ||
}, | ||
...(balance < 0 | ||
? [ | ||
{ | ||
name: 'cover', | ||
text: 'Cover overspending', | ||
}, | ||
] | ||
: []), | ||
]} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.