Skip to content

A local-first personal finance app

Mobile balance cover/transfer/rollover overspending (#1802)

Joel Jeremy Marquez7325153da1a2
diff --git a/packages/desktop-client/e2e/budget.test.js-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png b/packages/desktop-client/e2e/budget.test.js-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png
index 2646cc85e0..38e8e4570a 100644
Binary files a/packages/desktop-client/e2e/budget.test.js-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png and b/packages/desktop-client/e2e/budget.test.js-snapshots/Budget-transfer-funds-to-another-category-1-chromium-linux.png differ
diff --git a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png
index fcc9a4669d..90efef73ea 100644
Binary files a/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png and b/packages/desktop-client/e2e/mobile.test.js-snapshots/Mobile-loads-the-budget-page-with-budgeted-amounts-1-chromium-linux.png differ
diff --git a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
index bf7164aff9..05641edfa8 100644
--- a/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
+++ b/packages/desktop-client/src/components/autocomplete/CategoryAutocomplete.tsx
@@ -7,6 +7,11 @@ import React, {
import { css } from 'glamor';
+import {
+ type CategoryEntity,
+ type CategoryGroupEntity,
+} from 'loot-core/src/types/models';
+
import Split from '../../icons/v0/Split';
import { theme } from '../../style';
import Text from '../common/Text';
@@ -14,21 +19,8 @@ import View from '../common/View';
import Autocomplete, { defaultFilterSuggestion } from './Autocomplete';
-export type Category = {
- id: string;
- cat_group: unknown;
- groupName: string;
- name: string;
-};
-
-export type CategoryGroup = {
- id: string;
- name: string;
- categories: Array<Category>;
-};
-
export type CategoryListProps = {
- items: Array<Category>;
+ items: Array<CategoryEntity & { group?: CategoryGroupEntity }>;
getItemProps?: (arg: { item }) => Partial<ComponentProps<typeof View>>;
highlightedIndex: number;
embedded: boolean;
@@ -122,7 +114,7 @@ function CategoryList({
}}
data-testid="category-item-group"
>
- {item.groupName}
+ {`${item.group?.name}`}
</div>
)}
<div
@@ -157,7 +149,7 @@ function CategoryList({
}
type CategoryAutocompleteProps = ComponentProps<typeof Autocomplete> & {
- categoryGroups: CategoryGroup[];
+ categoryGroups: Array<CategoryGroupEntity>;
showSplitOption?: boolean;
groupHeaderStyle?: object;
};
@@ -169,19 +161,23 @@ export default function CategoryAutocomplete({
groupHeaderStyle,
...props
}: CategoryAutocompleteProps) {
- let categorySuggestions = useMemo(
+ let categorySuggestions: Array<
+ CategoryEntity & { group?: CategoryGroupEntity }
+ > = useMemo(
() =>
categoryGroups.reduce(
(list, group) =>
list.concat(
- group.categories.map(category => ({
- ...category,
- groupName: group.name,
- })),
+ group.categories
+ .filter(category => category.cat_group === group.id)
+ .map(category => ({
+ ...category,
+ group: group,
+ })),
),
- showSplitOption ? [{ id: 'split', name: '' }] : [],
+ showSplitOption ? [{ id: 'split', name: '' } as CategoryEntity] : [],
),
- [categoryGroups],
+ [showSplitOption, categoryGroups],
);
return (
diff --git a/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx b/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx
index 93d1df5312..b3e2beb897 100644
--- a/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx
+++ b/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx
@@ -1,6 +1,7 @@
import React, { type ComponentProps } from 'react';
import ArrowThinRight from '../../icons/v1/ArrowThinRight';
+import { type CSSProperties } from '../../style';
import View from '../common/View';
import CellValue from '../spreadsheet/CellValue';
import useSheetValue from '../spreadsheet/useSheetValue';
@@ -11,17 +12,23 @@ type BalanceWithCarryoverProps = {
carryover: ComponentProps<typeof CellValue>['binding'];
balance: ComponentProps<typeof CellValue>['binding'];
disabled?: boolean;
+ style?: CSSProperties;
+ balanceStyle?: CSSProperties;
+ carryoverStyle?: CSSProperties;
};
export default function BalanceWithCarryover({
carryover,
balance,
disabled,
+ style,
+ balanceStyle,
+ carryoverStyle,
}: BalanceWithCarryoverProps) {
let carryoverValue = useSheetValue(carryover);
let balanceValue = useSheetValue(balance);
return (
- <>
+ <View style={style}>
<CellValue
binding={balance}
type="financial"
@@ -32,9 +39,10 @@ export default function BalanceWithCarryover({
cursor: 'pointer',
':hover': { textDecoration: 'underline' },
}),
+ ...balanceStyle,
}}
/>
- {carryoverValue === true && (
+ {carryoverValue && (
<View
style={{
alignSelf: 'center',
@@ -44,6 +52,7 @@ export default function BalanceWithCarryover({
top: 0,
bottom: 0,
justifyContent: 'center',
+ ...carryoverStyle,
}}
>
<ArrowThinRight
@@ -53,6 +62,6 @@ export default function BalanceWithCarryover({
/>
</View>
)}
- </>
+ </View>
);
}
diff --git a/packages/desktop-client/src/components/budget/CategoryGroupsContext.js b/packages/desktop-client/src/components/budget/CategoryGroupsContext.js
deleted file mode 100644
index b1d9eb6899..0000000000
--- a/packages/desktop-client/src/components/budget/CategoryGroupsContext.js
+++ /dev/null
@@ -1,3 +0,0 @@
-import { createContext } from 'react';
-
-export let CategoryGroupsContext = createContext([]);
diff --git a/packages/desktop-client/src/components/budget/DynamicBudgetTable.js b/packages/desktop-client/src/components/budget/DynamicBudgetTable.js
index fec4a39786..dbd83c50ab 100644
--- a/packages/desktop-client/src/components/budget/DynamicBudgetTable.js
+++ b/packages/desktop-client/src/components/budget/DynamicBudgetTable.js
@@ -8,7 +8,6 @@ import View from '../common/View';
import { useBudgetMonthCount } from './BudgetMonthCountContext';
import BudgetPageHeader from './BudgetPageHeader';
import BudgetTable from './BudgetTable';
-import { CategoryGroupsContext } from './CategoryGroupsContext';
function getNumPossibleMonths(width) {
let estimatedTableWidth = width - 200;
@@ -61,36 +60,34 @@ const DynamicBudgetTableInner = forwardRef(
}
return (
- <CategoryGroupsContext.Provider value={categoryGroups}>
- <View
- style={{
- width,
- height,
- alignItems: 'center',
- opacity: width <= 0 || height <= 0 ? 0 : 1,
- }}
- >
- <View style={{ width: '100%', maxWidth }}>
- <BudgetPageHeader
- startMonth={prewarmStartMonth}
- numMonths={numMonths}
- monthBounds={monthBounds}
- onMonthSelect={onMonthSelect}
- />
- <BudgetTable
- ref={ref}
- categoryGroups={categoryGroups}
- prewarmStartMonth={prewarmStartMonth}
- startMonth={startMonth}
- numMonths={numMonths}
- monthBounds={monthBounds}
- prefs={prefs}
- {...actions}
- {...props}
- />
- </View>
+ <View
+ style={{
+ width,
+ height,
+ alignItems: 'center',
+ opacity: width <= 0 || height <= 0 ? 0 : 1,
+ }}
+ >
+ <View style={{ width: '100%', maxWidth }}>
+ <BudgetPageHeader
+ startMonth={prewarmStartMonth}
+ numMonths={numMonths}
+ monthBounds={monthBounds}
+ onMonthSelect={onMonthSelect}
+ />
+ <BudgetTable
+ ref={ref}
+ categoryGroups={categoryGroups}
+ prewarmStartMonth={prewarmStartMonth}
+ startMonth={startMonth}
+ numMonths={numMonths}
+ monthBounds={monthBounds}
+ prefs={prefs}
+ {...actions}
+ {...props}
+ />
</View>
- </CategoryGroupsContext.Provider>
+ </View>
);
},
);
diff --git a/packages/desktop-client/src/components/budget/MobileBudgetTable.js b/packages/desktop-client/src/components/budget/MobileBudgetTable.js
index e02095ab70..986476f7a3 100644
--- a/packages/desktop-client/src/components/budget/MobileBudgetTable.js
+++ b/packages/desktop-client/src/components/budget/MobileBudgetTable.js
@@ -32,7 +32,9 @@ import { AmountInput } from '../util/AmountInput';
// } from '../mobile/AmountInput';
// import { DragDrop, Draggable, Droppable, DragDropHighlight } from './dragdrop';
+import BalanceWithCarryover from './BalanceWithCarryover';
import { ListItem, ROW_HEIGHT } from './MobileTable';
+import BalanceTooltip from './rollover/BalanceTooltip';
import { makeAmountGrey } from './util';
function ToBudget({ toBudget, onClick }) {
@@ -49,6 +51,7 @@ function ToBudget({ toBudget, onClick }) {
...styles.underlinedText,
color: theme.formInputText,
flexShrink: 0,
+ textAlign: 'left',
}}
/>
<CellValue
@@ -77,18 +80,17 @@ function Saved({ projected }) {
style={{
flexDirection: 'column',
alignItems: 'flex-start',
- flexBasis: '80px',
}}
>
{projected ? (
<Label
title="PROJECTED SAVINGS"
- style={{ color: theme.formInputText }}
+ style={{ color: theme.formInputText, textAlign: 'left' }}
/>
) : (
<Label
title={isNegative ? 'OVERSPENT' : 'SAVED'}
- style={{ color: theme.formInputText }}
+ style={{ color: theme.formInputText, textAlign: 'left' }}
/>
)}
@@ -140,7 +142,7 @@ function BudgetCell({
initialValue={sheetValue}
zeroSign="+"
style={{
- height: ROW_HEIGHT - 4,
+ height: ROW_HEIGHT,
transform: 'translateX(6px)',
}}
focused={isEditing}
@@ -153,9 +155,10 @@ function BudgetCell({
role="button"
style={{
justifyContent: 'center',
- height: ROW_HEIGHT - 4,
+ alignItems: 'flex-end',
+ height: ROW_HEIGHT,
}}
- onPointerUp={onAmountClick}
+ onPointerDown={onAmountClick}
>
<CellValue
binding={binding}
@@ -227,6 +230,8 @@ const ExpenseCategory = memo(function ExpenseCategory({
onEditBudget,
onSave,
onDelete,
+ isBudgetActionMenuOpen,
+ onOpenBudgetActionMenu,
onBudgetAction,
show3Cols,
showBudgetedCol,
@@ -238,16 +243,22 @@ const ExpenseCategory = memo(function ExpenseCategory({
let [isHidden, setIsHidden] = useState(category.hidden);
let budgeted = rolloverBudget.catBudgeted(category.id);
- let balance = rolloverBudget.catBalance(category.id);
let spent = rolloverBudget.catSumAmount(category.id);
let tooltip = useTooltip();
+ let balanceTooltip = useTooltip();
+
+ useEffect(() => {
+ if (isBudgetActionMenuOpen) {
+ balanceTooltip.open();
+ }
+ }, [isBudgetActionMenuOpen, balanceTooltip]);
useEffect(() => {
if (!isEditing && tooltip.isOpen) {
tooltip.close();
}
- }, [isEditing]);
+ }, [isEditing, tooltip]);
let onSubmit = () => {
if (categoryName) {
@@ -301,19 +312,49 @@ const ExpenseCategory = memo(function ExpenseCategory({
...(!showEditables && { display: 'none' }),
flexDirection: 'row',
flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ height: ROW_HEIGHT,
}}
>
<InputWithContent
focused={isEditing}
inputRef={inputRef}
rightContent={
- <Button
- type="bare"
- style={{ padding: 10 }}
- {...tooltip.getOpenEvents()}
- >
- <DotsHorizontalTriple width={12} height={12} />
- </Button>
+ <>
+ <Button
+ type="bare"
+ style={{ padding: 10 }}
+ {...tooltip.getOpenEvents()}
+ >
+ <DotsHorizontalTriple width={12} height={12} />
+ </Button>
+ {tooltip.isOpen && (
+ <Tooltip
+ position="bottom-stretch"
+ offset={1}
+ style={{ padding: 0 }}
+ onClose={() => {
+ tooltip.close();
+ inputRef.current?.focus();
+ }}
+ >
+ <Menu
+ onMenuSelect={onMenuSelect}
+ items={[
+ {
+ name: 'toggle-visibility',
+ text: isHidden ? 'Show' : 'Hide',
+ },
+ {
+ name: 'delete',
+ text: 'Delete',
+ },
+ ]}
+ />
+ </Tooltip>
+ )}
+ </>
}
style={{ width: '100%' }}
placeholder="Category Name"
@@ -326,44 +367,17 @@ const ExpenseCategory = memo(function ExpenseCategory({
}
}}
/>
- {tooltip.isOpen && (
- <Tooltip
- position="bottom-stretch"
- offset={1}
- style={{ padding: 0 }}
- onClose={() => {
- tooltip.close();
- inputRef.current?.focus();
- }}
- >
- <Menu
- onMenuSelect={onMenuSelect}
- items={[
- {
- name: 'toggle-visibility',
- text: isHidden ? 'Show' : 'Hide',
- },
- {
- name: 'delete',
- text: 'Delete',
- },
- ]}
- />
- </Tooltip>
- )}
</View>
<View
role="button"
- onPointerUp={() => onEdit?.(category.id)}
+ onPointerDown={() => onEdit?.(category.id)}
style={{ ...(showEditables && { display: 'none' }), flex: 1 }}
>
<Text
style={{
...styles.smallText,
...styles.underlinedText,
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
+ ...styles.lineClamp(2),
}}
data-testid="category-name"
>
@@ -373,6 +387,7 @@ const ExpenseCategory = memo(function ExpenseCategory({
<View
style={{
...(showEditables && { display: 'none' }),
+ justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
opacity,
@@ -392,31 +407,70 @@ const ExpenseCategory = memo(function ExpenseCategory({
isEditing={isEditingBudget}
onEdit={onEditBudget}
/>
- <CellValue
- name="spent"
- binding={spent}
+ <View
style={{
...(!show3Cols && showBudgetedCol && { display: 'none' }),
- ...styles.smallText,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
width: 90,
- textAlign: 'right',
+ height: ROW_HEIGHT,
}}
- getStyle={makeAmountGrey}
- type="financial"
- />
- <CellValue
- name="balance"
- binding={balance}
+ >
+ <CellValue
+ name="spent"
+ binding={spent}
+ style={{
+ ...styles.smallText,
+ textAlign: 'right',
+ }}
+ getStyle={makeAmountGrey}
+ type="financial"
+ />
+ </View>
+ <View
style={{
- ...styles.smallText,
+ ...styles.noTapHighlight,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
width: 90,
- textAlign: 'right',
+ height: ROW_HEIGHT,
}}
- getStyle={value =>
- value < 0 ? { color: theme.errorText } : makeAmountGrey(value)
- }
- type="financial"
- />
+ >
+ <span
+ role="button"
+ onPointerDown={() => onOpenBudgetActionMenu?.(category.id)}
+ >
+ <BalanceWithCarryover
+ carryover={rolloverBudget.catCarryover(category.id)}
+ balance={rolloverBudget.catBalance(category.id)}
+ balanceStyle={{
+ ...styles.smallText,
+ ...styles.underlinedText,
+ }}
+ />
+ {balanceTooltip.isOpen && (
+ <BalanceTooltip
+ offset={5}
+ categoryId={category.id}
+ tooltip={balanceTooltip}
+ monthIndex={monthUtils.getMonthIndex(month)}
+ onBudgetAction={(monthIndex, action, arg) => {
+ onBudgetAction?.(
+ monthUtils.getMonthFromIndex(
+ monthUtils.getYear(month),
+ monthIndex,
+ ),
+ action,
+ arg,
+ );
+ }}
+ onClose={() => {
+ onOpenBudgetActionMenu?.(null);
+ }}
+ />
+ )}
+ </span>
+ </View>
</View>
</ListItem>
);
@@ -533,19 +587,53 @@ const ExpenseGroupTotals = memo(function ExpenseGroupTotals({
...(!showEditables && { display: 'none' }),
flexDirection: 'row',
flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ height: ROW_HEIGHT,
}}
>
<InputWithContent
focused={isEditing}
inputRef={inputRef}
rightContent={
- <Button
- type="bare"
- style={{ padding: 10 }}
- {...tooltip.getOpenEvents()}
- >
- <DotsHorizontalTriple width={12} height={12} />
- </Button>
+ <>
+ <Button
+ type="bare"
+ style={{ padding: 10 }}
+ {...tooltip.getOpenEvents()}
+ >
+ <DotsHorizontalTriple width={12} height={12} />
+ </Button>
+ {tooltip.isOpen && (
+ <Tooltip
+ position="bottom-stretch"
+ offset={1}
+ style={{ padding: 0 }}
+ onClose={() => {
+ tooltip.close();
+ inputRef.current?.focus();
+ }}
+ >
+ <Menu
+ onMenuSelect={onMenuSelect}
+ items={[
+ {
+ name: 'add-category',
+ text: 'Add category',
+ },
+ {
+ name: 'toggle-visibility',
+ text: isHidden ? 'Show' : 'Hide',
+ },
+ {
+ name: 'delete',
+ text: 'Delete',
+ },
+ ]}
+ />
+ </Tooltip>
+ )}
+ </>
}
style={{ width: '100%' }}
placeholder="Category Group Name"
@@ -558,39 +646,10 @@ const ExpenseGroupTotals = memo(function ExpenseGroupTotals({
}
}}
/>
- {tooltip.isOpen && (
- <Tooltip
- position="bottom-stretch"
- offset={1}
- style={{ padding: 0 }}
- onClose={() => {
- tooltip.close();
- inputRef.current?.focus();
- }}
- >
- <Menu
- onMenuSelect={onMenuSelect}
- items={[
- {
- name: 'add-category',
- text: 'Add category',
- },
- {
- name: 'toggle-visibility',
- text: isHidden ? 'Show' : 'Hide',
- },
- {
- name: 'delete',
- text: 'Delete',
- },
- ]}
- />
- </Tooltip>
- )}
</View>
<View
role="button"
- onPointerUp={() => onEdit?.(group.id)}
+ onPointerDown={() => onEdit?.(group.id)}
style={{ ...(showEditables && { display: 'none' }), flex: 1 }}
>
<Text
@@ -598,10 +657,8 @@ const ExpenseGroupTotals = memo(function ExpenseGroupTotals({
style={{
...styles.smallText,
...styles.underlinedText,
+ ...styles.lineClamp(2),
fontWeight: '500',
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- textOverflow: 'ellipsis',
}}
data-testid="name"
>
@@ -612,42 +669,68 @@ const ExpenseGroupTotals = memo(function ExpenseGroupTotals({
style={{
...(showEditables && { display: 'none' }),
flexDirection: 'row',
+ justifyContent: 'center',
alignItems: 'center',
+ height: ROW_HEIGHT,
opacity,
}}
>
- <CellValue
- binding={rolloverBudget.groupBudgeted(group.id)}
+ <View
style={{
...(!show3Cols && !showBudgetedCol && { display: 'none' }),
- ...styles.smallText,
width: 90,
- fontWeight: '500',
- textAlign: 'right',
+ height: ROW_HEIGHT,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
}}
- type="financial"
- />
- <CellValue
- binding={rolloverBudget.groupSumAmount(group.id)}
+ >
+ <CellValue
+ binding={rolloverBudget.groupBudgeted(group.id)}
+ style={{
+ ...styles.smallText,
+ fontWeight: '500',
+ textAlign: 'right',
+ }}
+ type="financial"
+ />
+ </View>
+ <View
style={{
...(!show3Cols && showBudgetedCol && { display: 'none' }),
- ...styles.smallText,
width: 90,
- fontWeight: '500',
- textAlign: 'right',
+ height: ROW_HEIGHT,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
}}
- type="financial"
- />
- <CellValue
- binding={rolloverBudget.groupBalance(group.id)}
+ >
+ <CellValue
+ binding={rolloverBudget.groupSumAmount(group.id)}
+ style={{
+ ...styles.smallText,
+ fontWeight: '500',
+ textAlign: 'right',
+ }}
+ type="financial"
+ />
+ </View>
+ <View
style={{
- ...styles.smallText,
width: 90,
- fontWeight: '500',
- textAlign: 'right',
+ height: ROW_HEIGHT,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
}}
- type="financial"
- />
+ >
+ <CellValue
+ binding={rolloverBudget.groupBalance(group.id)}
+ style={{
+ ...styles.smallText,
+ fontWeight: '500',
+ textAlign: 'right',
+ }}
+ type="financial"
+ />
+ </View>
</View>
{/* {editMode && (
@@ -686,8 +769,6 @@ const IncomeGroupTotals = memo(function IncomeGroupTotals({
budget,
balance,
style,
- nameTextStyle,
- amountTextStyle,
onAddCategory,
onSave,
onDelete,
@@ -760,19 +841,53 @@ const IncomeGroupTotals = memo(function IncomeGroupTotals({
...(!showEditables && { display: 'none' }),
flexDirection: 'row',
flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ height: ROW_HEIGHT,
}}
>
<InputWithContent
focused={isEditing}
inputRef={inputRef}
rightContent={
- <Button
- type="bare"
- style={{ padding: 10 }}
- {...tooltip.getOpenEvents()}
- >
- <DotsHorizontalTriple width={12} height={12} />
- </Button>
+ <>
+ <Button
+ type="bare"
+ style={{ padding: 10 }}
+ {...tooltip.getOpenEvents()}
+ >
+ <DotsHorizontalTriple width={12} height={12} />
+ </Button>
+ {tooltip.isOpen && (
+ <Tooltip
+ position="bottom-stretch"
+ offset={1}
+ style={{ padding: 0 }}
+ onClose={() => {
+ tooltip.close();
+ inputRef.current?.focus();
+ }}
+ >
+ <Menu
+ onMenuSelect={onMenuSelect}
+ items={[
+ {
+ name: 'add-category',
+ text: 'Add category',
+ },
+ {
+ name: 'toggle-visibility',
+ text: isHidden ? 'Show' : 'Hide',
+ },
+ {
+ name: 'delete',
+ text: 'Delete',
+ },
+ ]}
+ />
+ </Tooltip>
+ )}
+ </>
}
style={{ width: '100%' }}
placeholder="Category Group Name"
@@ -785,46 +900,24 @@ const IncomeGroupTotals = memo(function IncomeGroupTotals({
}
}}
/>
- {tooltip.isOpen && (
- <Tooltip
- position="bottom-stretch"
- offset={1}
- style={{ padding: 0 }}
- onClose={() => {
- tooltip.close();
- inputRef.current?.focus();
- }}
- >
- <Menu
- onMenuSelect={onMenuSelect}
- items={[
- {
- name: 'add-category',
- text: 'Add category',
- },
- {
- name: 'toggle-visibility',
- text: isHidden ? 'Show' : 'Hide',
- },
- {
- name: 'delete',
- text: 'Delete',
- },
- ]}
- />
- </Tooltip>
- )}
</View>
<View
role="button"
- style={{ ...(showEditables && { display: 'none' }) }}
- onPointerUp={() => onEdit?.(group.id)}
+ style={{
+ ...(showEditables && { display: 'none' }),
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'flex-start',
+ height: ROW_HEIGHT,
+ }}
+ onPointerDown={() => onEdit?.(group.id)}
>
<Text
- tabIndex={-1}
style={{
...styles.smallText,
- ...nameTextStyle,
+ ...styles.underlinedText,
+ ...styles.lineClamp(2),
+ fontWeight: '500',
}}
data-testid="name"
>
@@ -832,29 +925,45 @@ const IncomeGroupTotals = memo(function IncomeGroupTotals({
</Text>
</View>
{budget && (
- <CellValue
- binding={budget}
+ <View
style={{
...(showEditables && { display: 'none' }),
- ...styles.smallText,
- textAlign: 'right',
- ...amountTextStyle,
- flex: 1,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ width: 90,
+ height: ROW_HEIGHT,
}}
- type="financial"
- />
+ >
+ <CellValue
+ binding={budget}
+ style={{
+ ...styles.smallText,
+ textAlign: 'right',
+ fontWeight: '500',
+ }}
+ type="financial"
+ />
+ </View>
)}
- <CellValue
- binding={balance}
+ <View
style={{
...(showEditables && { display: 'none' }),
- ...styles.smallText,
- textAlign: 'right',
- ...amountTextStyle,
- flex: 1,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ width: 90,
+ height: ROW_HEIGHT,
}}
- type="financial"
- />
+ >
+ <CellValue
+ binding={balance}
+ style={{
+ ...styles.smallText,
+ textAlign: 'right',
+ fontWeight: '500',
+ }}
+ type="financial"
+ />
+ </View>
</ListItem>
);
});
@@ -864,8 +973,6 @@ const IncomeCategory = memo(function IncomeCategory({
budget,
balance,
style,
- nameTextStyle,
- amountTextStyle,
onSave,
onDelete,
editMode,
@@ -934,19 +1041,49 @@ const IncomeCategory = memo(function IncomeCategory({
...(!showEditables && { display: 'none' }),
flexDirection: 'row',
flex: 1,
+ justifyContent: 'center',
+ alignItems: 'center',
+ height: ROW_HEIGHT,
}}
>
<InputWithContent
focused={isEditing}
inputRef={inputRef}
rightContent={
- <Button
- type="bare"
- style={{ padding: 10 }}
- {...tooltip.getOpenEvents()}
- >
- <DotsHorizontalTriple width={12} height={12} />
- </Button>
+ <>
+ <Button
+ type="bare"
+ style={{ padding: 10 }}
+ {...tooltip.getOpenEvents()}
+ >
+ <DotsHorizontalTriple width={12} height={12} />
+ </Button>
+ {tooltip.isOpen && (
+ <Tooltip
+ position="bottom-stretch"
+ offset={1}
+ style={{ padding: 0 }}
+ onClose={() => {
+ tooltip.close();
+ inputRef.current?.focus();
+ }}
+ >
+ <Menu
+ onMenuSelect={onMenuSelect}
+ items={[
+ {
+ name: 'toggle-visibility',
+ text: isHidden ? 'Show' : 'Hide',
+ },
+ {
+ name: 'delete',
+ text: 'Delete',
+ },
+ ]}
+ />
+ </Tooltip>
+ )}
+ </>
}
style={{ width: '100%' }}
placeholder="Category Name"
@@ -959,43 +1096,24 @@ const IncomeCategory = memo(function IncomeCategory({
}
}}
/>
- {tooltip.isOpen && (
- <Tooltip
- position="bottom-stretch"
- offset={1}
- style={{ padding: 0 }}
- onClose={() => {
- tooltip.close();
- inputRef.current?.focus();
- }}
- >
- <Menu
- onMenuSelect={onMenuSelect}
- items={[
- {
- name: 'toggle-visibility',
- text: isHidden ? 'Show' : 'Hide',
- },
- {
- name: 'delete',
- text: 'Delete',
- },
- ]}
- />
- </Tooltip>
- )}
</View>
<View
role="button"
- style={{ ...(showEditables && { display: 'none' }) }}
- onPointerUp={() => onEdit?.(category.id)}
+ style={{
+ ...(showEditables && { display: 'none' }),
+ flex: 1,
+ justifyContent: 'center',
+ alignItems: 'flex-start',
+ height: ROW_HEIGHT,
+ }}
+ onPointerDown={() => onEdit?.(category.id)}
>
<Text
tabIndex={-1}
style={{
...styles.smallText,
- ...nameTextStyle,
...styles.underlinedText,
+ ...styles.lineClamp(2),
}}
data-testid="name"
>
@@ -1003,29 +1121,43 @@ const IncomeCategory = memo(function IncomeCategory({
</Text>
</View>
{budget && (
- <CellValue
- binding={budget}
+ <View
style={{
...(showEditables && { display: 'none' }),
- ...styles.smallText,
- textAlign: 'right',
- ...amountTextStyle,
- flex: 1,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ width: 90,
+ height: ROW_HEIGHT,
}}
- type="financial"
- />
+ >
+ <CellValue
+ binding={budget}
+ style={{
+ ...styles.smallText,
+ textAlign: 'right',
+ }}
+ type="financial"
+ />
+ </View>
)}
- <CellValue
- binding={balance}
+ <View
style={{
...(showEditables && { display: 'none' }),
- ...styles.smallText,
- textAlign: 'right',
- ...amountTextStyle,
- flex: 1,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ width: 90,
+ height: ROW_HEIGHT,
}}
- type="financial"
- />
+ >
+ <CellValue
+ binding={balance}
+ style={{
+ ...styles.smallText,
+ textAlign: 'right',
+ }}
+ type="financial"
+ />
+ </View>
</ListItem>
);
});
@@ -1078,6 +1210,8 @@ const ExpenseGroup = memo(function ExpenseGroup({
onEditCategory,
editingBudgetCategoryId,
onEditCategoryBudget,
+ openBudgetActionMenuId,
+ onOpenBudgetActionMenu,
// gestures,
month,
onSaveCategory,
@@ -1149,6 +1283,7 @@ const ExpenseGroup = memo(function ExpenseGroup({
const isEditingCategory = editingCategoryId === category.id;
const isEditingCategoryBudget =
editingBudgetCategoryId === category.id;
+ const isBudgetActionMenuOpen = openBudgetActionMenuId === category.id;
return (
<ExpenseCategory
show3Cols={show3Cols}
@@ -1161,6 +1296,8 @@ const ExpenseGroup = memo(function ExpenseGroup({
onEdit={onEditCategory}
isEditingBudget={isEditingCategoryBudget}
onEditBudget={onEditCategoryBudget}
+ isBudgetActionMenuOpen={isBudgetActionMenuOpen}
+ onOpenBudgetActionMenu={onOpenBudgetActionMenu}
// gestures={gestures}
month={month}
onSave={onSaveCategory}
@@ -1216,8 +1353,6 @@ function IncomeGroup({
? reportBudget.groupSumAmount(group.id)
: rolloverBudget.groupSumAmount(group.id)
}
- nameTextStyle={{ fontWeight: '500', ...styles.underlinedText }}
- amountTextStyle={{ fontWeight: '500' }}
style={{
backgroundColor: theme.altTableBackground,
}}
@@ -1270,6 +1405,8 @@ function BudgetGroups({
onEditCategory,
editingBudgetCategoryId,
onEditCategoryBudget,
+ openBudgetActionMenuId,
+ onOpenBudgetActionMenu,
editMode,
gestures,
month,
@@ -1317,6 +1454,8 @@ function BudgetGroups({
onEditCategory={onEditCategory}
editingBudgetCategoryId={editingBudgetCategoryId}
onEditCategoryBudget={onEditCategoryBudget}
+ openBudgetActionMenuId={openBudgetActionMenuId}
+ onOpenBudgetActionMenu={onOpenBudgetActionMenu}
onSaveCategory={onSaveCategory}
onDeleteCategory={onDeleteCategory}
onAddCategory={onAddCategory}
@@ -1388,36 +1527,50 @@ export function BudgetTable(props) {
savePrefs,
} = props;
- const GROUP_TYPE = 'group';
+ const GROUP_EDIT_ACTION = 'group';
const [editingGroupId, setEditingGroupId] = useState(null);
function onEditGroup(id) {
- onEdit(GROUP_TYPE, id);
+ onEdit(GROUP_EDIT_ACTION, id);
}
- const CATEGORY_TYPE = 'category';
+ const CATEGORY_EDIT_ACTION = 'category';
const [editingCategoryId, setEditingCategoryId] = useState(null);
function onEditCategory(id) {
- onEdit(CATEGORY_TYPE, id);
+ onEdit(CATEGORY_EDIT_ACTION, id);
}
- const CATEGORY_BUDGET_TYPE = 'category-budget';
+ const CATEGORY_BUDGET_EDIT_ACTION = 'category-budget';
const [editingBudgetCategoryId, setEditingBudgetCategoryId] = useState(null);
function onEditCategoryBudget(id) {
- onEdit(CATEGORY_BUDGET_TYPE, id);
+ onEdit(CATEGORY_BUDGET_EDIT_ACTION, id);
}
- function onEdit(type, id) {
+ const BUDGET_MENU_OPEN_ACTION = 'budget-menu';
+ const [openBudgetActionMenuId, setOpenBudgetActionMenuId] = useState(null);
+ function onOpenBudgetActionMenu(id) {
+ onEdit(BUDGET_MENU_OPEN_ACTION, id);
+ }
+
+ function onEdit(action, id) {
// Do not allow editing if another field is currently being edited.
// Cancel the currently editing field in that case.
const currentlyEditing =
- editingGroupId || editingCategoryId || editingBudgetCategoryId;
+ editingGroupId ||
+ editingCategoryId ||
+ editingBudgetCategoryId ||
+ openBudgetActionMenuId;
- setEditingGroupId(type === GROUP_TYPE && !currentlyEditing ? id : null);
+ setEditingGroupId(
+ action === GROUP_EDIT_ACTION && !currentlyEditing ? id : null,
+ );
setEditingCategoryId(
- type === CATEGORY_TYPE && !currentlyEditing ? id : null,
+ action === CATEGORY_EDIT_ACTION && !currentlyEditing ? id : null,
);
setEditingBudgetCategoryId(
- type === CATEGORY_BUDGET_TYPE && !currentlyEditing ? id : null,
+ action === CATEGORY_BUDGET_EDIT_ACTION && !currentlyEditing ? id : null,
+ );
+ setOpenBudgetActionMenuId(
+ action === BUDGET_MENU_OPEN_ACTION && !currentlyEditing ? id : null,
);
}
@@ -1489,25 +1642,29 @@ export function BudgetTable(props) {
/>
)}
<View style={{ flex: 1 }} />
- <Button
- type="bare"
- disabled={show3Cols}
- onClick={toggleDisplay}
- style={{
- ...buttonStyle,
- padding: '0 8px',
- margin: '0 -8px',
- background:
- showBudgetedCol && !show3Cols
- ? `linear-gradient(-45deg, ${theme.formInputBackgroundSelection} 8px, transparent 0)`
- : !show3Cols
- ? `linear-gradient(45deg, ${theme.formInputBackgroundSelection} 8px, transparent 0)`
- : null,
- // 45deg to flip it to the lower left corner
- }}
- >
- {show3Cols || showBudgetedCol ? (
- <View style={{ width: 90, justifyContent: 'center' }}>
+ {(show3Cols || showBudgetedCol) && (
+ <Button
+ type="bare"
+ disabled={show3Cols}
+ onClick={toggleDisplay}
+ style={{
+ ...buttonStyle,
+ padding: '0 8px',
+ margin: '0 -8px',
+ background:
+ showBudgetedCol && !show3Cols
+ ? `linear-gradient(-45deg, ${theme.formInputBackgroundSelection} 8px, transparent 0)`
+ : null,
+ }}
+ >
+ <View
+ style={{
+ flexBasis: 90,
+ width: 90,
+ justifyContent: 'center',
+ alignItems: 'flex-end',
+ }}
+ >
<Label
title="BUDGETED"
style={{ color: theme.buttonNormalText }}
@@ -1526,12 +1683,26 @@ export function BudgetTable(props) {
}}
/>
</View>
- ) : null}
- {show3Cols || !showBudgetedCol ? (
+ </Button>
+ )}
+ {(show3Cols || !showBudgetedCol) && (
+ <Button
+ type="bare"
+ disabled={show3Cols}
+ onClick={toggleDisplay}
+ style={{
+ ...buttonStyle,
+ background:
+ !showBudgetedCol && !show3Cols
+ ? `linear-gradient(45deg, ${theme.formInputBackgroundSelection} 8px, transparent 0)`
+ : null,
+ }}
+ >
<View
style={{
width: 90,
justifyContent: 'center',
+ alignItems: 'flex-end',
}}
>
<Label title="SPENT" style={{ color: theme.formInputText }} />
@@ -1546,12 +1717,13 @@ export function BudgetTable(props) {
}}
/>
</View>
- ) : null}
- </Button>
+ </Button>
+ )}
<View
style={{
width: 90,
justifyContent: 'center',
+ alignItems: 'flex-end',
}}
>
<Label title="BALANCE" style={{ color: theme.formInputText }} />
@@ -1592,6 +1764,8 @@ export function BudgetTable(props) {
onEditCategory={onEditCategory}
editingBudgetCategoryId={editingBudgetCategoryId}
onEditCategoryBudget={onEditCategoryBudget}
+ openBudgetActionMenuId={openBudgetActionMenuId}
+ onOpenBudgetActionMenu={onOpenBudgetActionMenu}
onSaveCategory={onSaveCategory}
onDeleteCategory={onDeleteCategory}
onAddCategory={onAddCategory}
@@ -1777,15 +1951,22 @@ function BudgetHeader({
}}
>
{!editMode ? (
- <Button
- type="bare"
- style={{
- backgroundColor: 'transparent',
- paddingLeft: 12,
- paddingRight: 12,
- }}
- {...tooltip.getOpenEvents()}
- >
+ <>
+ <Button
+ type="bare"
+ style={{
+ backgroundColor: 'transparent',
+ paddingLeft: 12,
+ paddingRight: 12,
+ }}
+ {...tooltip.getOpenEvents()}
+ >
+ <DotsHorizontalTriple
+ width="20"
+ height="20"
+ style={{ color: 'white' }}
+ />
+ </Button>
{tooltip.isOpen && (
<Tooltip
position="bottom-right"
@@ -1805,12 +1986,7 @@ function BudgetHeader({
/>
</Tooltip>
)}
- <DotsHorizontalTriple
- width="20"
- height="20"
- style={{ color: 'white' }}
- />
- </Button>
+ </>
) : (
<Button
type="bare"
diff --git a/packages/desktop-client/src/components/budget/rollover/BalanceTooltip.tsx b/packages/desktop-client/src/components/budget/rollover/BalanceTooltip.tsx
new file mode 100644
index 0000000000..cf959c9a94
--- /dev/null
+++ b/packages/desktop-client/src/components/budget/rollover/BalanceTooltip.tsx
@@ -0,0 +1,106 @@
+import React, { useState } from 'react';
+
+import { rolloverBudget } from 'loot-core/src/client/queries';
+
+import Menu from '../../common/Menu';
+import useSheetValue from '../../spreadsheet/useSheetValue';
+import { Tooltip } from '../../tooltips';
+
+import CoverTooltip from './CoverTooltip';
+import TransferTooltip from './TransferTooltip';
+
+type BalanceTooltipProps = {
+ categoryId: string;
+ tooltip: { close: () => void };
+ monthIndex: number;
+ onBudgetAction: (idx: number, action: string, arg?: unknown) => void;
+ onClose?: () => void;
+};
+export default function BalanceTooltip({
+ categoryId,
+ tooltip,
+ monthIndex,
+ onBudgetAction,
+ onClose,
+ ...tooltipProps
+}: BalanceTooltipProps) {
+ let carryover = useSheetValue(rolloverBudget.catCarryover(categoryId));
+ let balance = useSheetValue(rolloverBudget.catBalance(categoryId));
+ let [menu, setMenu] = useState('menu');
+
+ let _onClose = () => {
+ tooltip.close();
+ onClose?.();
+ };
+
+ return (
+ <>
+ {menu === 'menu' && (
+ <Tooltip
+ position="bottom-right"
+ width={200}
+ style={{ padding: 0 }}
+ onClose={_onClose}
+ {...tooltipProps}
+ >
+ <Menu
+ onMenuSelect={type => {
+ if (type === 'carryover') {
+ onBudgetAction(monthIndex, 'carryover', {
+ category: categoryId,
+ flag: !carryover,
+ });
+ _onClose();
+ } else {
+ setMenu(type);
+ }
+ }}
+ items={[
+ {
+ name: 'transfer',
+ text: 'Transfer to another category',
+ },
+ {
+ name: 'carryover',
+ text: carryover
+ ? 'Remove overspending rollover'
+ : 'Rollover overspending',
+ },
+ balance < 0 && {
+ name: 'cover',
+ text: 'Cover overspending',
+ },
+ ].filter(x => x)}
+ />
+ </Tooltip>
+ )}
+
+ {menu === 'transfer' && (
+ <TransferTooltip
+ initialAmountName={rolloverBudget.catBalance(categoryId)}
+ showToBeBudgeted={true}
+ onClose={_onClose}
+ onSubmit={(amount, toCategory) => {
+ onBudgetAction(monthIndex, 'transfer-category', {
+ amount,
+ from: categoryId,
+ to: toCategory,
+ });
+ }}
+ />
+ )}
+
+ {menu === 'cover' && (
+ <CoverTooltip
+ onClose={_onClose}
+ onSubmit={fromCategory => {
+ onBudgetAction(monthIndex, 'cover', {
+ to: categoryId,
+ from: fromCategory,
+ });
+ }}
+ />
+ )}
+ </>
+ );
+}
diff --git a/packages/desktop-client/src/components/budget/rollover/CoverTooltip.tsx b/packages/desktop-client/src/components/budget/rollover/CoverTooltip.tsx
new file mode 100644
index 0000000000..9e24fcaf68
--- /dev/null
+++ b/packages/desktop-client/src/components/budget/rollover/CoverTooltip.tsx
@@ -0,0 +1,83 @@
+import React, { type ComponentProps, useState } from 'react';
+
+import useCategories from '../../../hooks/useCategories';
+import CategoryAutocomplete from '../../autocomplete/CategoryAutocomplete';
+import Button from '../../common/Button';
+import InitialFocus from '../../common/InitialFocus';
+import View from '../../common/View';
+import { Tooltip } from '../../tooltips';
+import { addToBeBudgetedGroup } from '../util';
+
+type CoverTooltipProps = {
+ tooltipProps?: ComponentProps<typeof Tooltip>;
+ onSubmit: (category: unknown) => void;
+ onClose: () => void;
+};
+export default function CoverTooltip({
+ tooltipProps,
+ onSubmit,
+ onClose,
+}: CoverTooltipProps) {
+ let { grouped: categoryGroups } = useCategories();
+ categoryGroups = addToBeBudgetedGroup(
+ categoryGroups.filter(g => !g.is_income),
+ );
+ let [category, setCategory] = useState(null);
+
+ function submit() {
+ if (category) {
+ onSubmit(category);
+ onClose();
+ }
+ }
+
+ return (
+ <Tooltip
+ position="bottom-right"
+ width={200}
+ style={{ padding: 10 }}
+ {...tooltipProps}
+ onClose={onClose}
+ >
+ <View style={{ marginBottom: 5 }}>Cover from category:</View>
+
+ <InitialFocus>
+ {node => (
+ <CategoryAutocomplete
+ categoryGroups={categoryGroups}
+ value={null}
+ openOnFocus={true}
+ onUpdate={id => {}}
+ onSelect={id => setCategory(id)}
+ inputProps={{
+ inputRef: node,
+ onKeyDown: e => {
+ if (e.key === 'Enter') {
+ submit();
+ }
+ },
+ }}
+ />
+ )}
+ </InitialFocus>
+
+ <View
+ style={{
+ alignItems: 'flex-end',
+ marginTop: 10,
+ }}
+ >
+ <Button
+ type="primary"
+ style={{
+ fontSize: 12,
+ paddingTop: 3,
+ }}
+ onClick={submit}
+ >
+ Transfer
+ </Button>
+ </View>
+ </Tooltip>
+ );
+}
diff --git a/packages/desktop-client/src/components/budget/rollover/TransferTooltip.tsx b/packages/desktop-client/src/components/budget/rollover/TransferTooltip.tsx
index bdf02fef1f..06e8a099f4 100644
--- a/packages/desktop-client/src/components/budget/rollover/TransferTooltip.tsx
+++ b/packages/desktop-client/src/components/budget/rollover/TransferTooltip.tsx
@@ -9,6 +9,7 @@ import { useSpreadsheet } from 'loot-core/src/client/SpreadsheetProvider';
import evalArithmetic from 'loot-core/src/shared/arithmetic';
import { integerToCurrency, amountToInteger } from 'loot-core/src/shared/util';
+import useCategories from '../../../hooks/useCategories';
import CategoryAutocomplete from '../../autocomplete/CategoryAutocomplete';
import Button from '../../common/Button';
import InitialFocus from '../../common/InitialFocus';
@@ -16,7 +17,6 @@ import Input from '../../common/Input';
import View from '../../common/View';
import NamespaceContext from '../../spreadsheet/NamespaceContext';
import { Tooltip } from '../../tooltips';
-import { CategoryGroupsContext } from '../CategoryGroupsContext';
import { addToBeBudgetedGroup } from '../util';
type TransferTooltipProps = {
@@ -37,7 +37,7 @@ export default function TransferTooltip({
}: TransferTooltipProps) {
let spreadsheet = useSpreadsheet();
let sheetName = useContext(NamespaceContext);
- let categoryGroups = useContext(CategoryGroupsContext);
+ let { grouped: categoryGroups } = useCategories();
categoryGroups = categoryGroups.filter(g => !g.is_income);
if (showToBeBudgeted) {
diff --git a/packages/desktop-client/src/components/budget/rollover/rollover-components.tsx b/packages/desktop-client/src/components/budget/rollover/rollover-components.tsx
index ff0c26e339..a15f06b76e 100644
--- a/packages/desktop-client/src/components/budget/rollover/rollover-components.tsx
+++ b/packages/desktop-client/src/components/budget/rollover/rollover-components.tsx
@@ -1,4 +1,4 @@
-import React, { type ComponentProps, memo, useContext, useState } from 'react';
+import React, { memo, useState } from 'react';
import { rolloverBudget } from 'loot-core/src/client/queries';
import evalArithmetic from 'loot-core/src/shared/arithmetic';
@@ -7,181 +7,21 @@ import { integerToCurrency, amountToInteger } from 'loot-core/src/shared/util';
import useFeatureFlag from '../../../hooks/useFeatureFlag';
import CheveronDown from '../../../icons/v1/CheveronDown';
import { styles, theme, type CSSProperties } from '../../../style';
-import CategoryAutocomplete from '../../autocomplete/CategoryAutocomplete';
import Button from '../../common/Button';
-import InitialFocus from '../../common/InitialFocus';
import Menu from '../../common/Menu';
import Text from '../../common/Text';
import View from '../../common/View';
import CellValue from '../../spreadsheet/CellValue';
import useFormat from '../../spreadsheet/useFormat';
-import useSheetValue from '../../spreadsheet/useSheetValue';
import { Row, Field, SheetCell } from '../../table';
import { Tooltip, useTooltip } from '../../tooltips';
import BalanceWithCarryover from '../BalanceWithCarryover';
-import { CategoryGroupsContext } from '../CategoryGroupsContext';
-import { makeAmountGrey, addToBeBudgetedGroup } from '../util';
+import { makeAmountGrey } from '../util';
-import TransferTooltip from './TransferTooltip';
+import BalanceTooltip from './BalanceTooltip';
export { BudgetSummary } from './BudgetSummary';
-type CoverTooltipProps = {
- tooltipProps?: ComponentProps<typeof Tooltip>;
- onSubmit: (category: unknown) => void;
- onClose: () => void;
-};
-function CoverTooltip({ tooltipProps, onSubmit, onClose }: CoverTooltipProps) {
- let categoryGroups = useContext(CategoryGroupsContext);
- categoryGroups = addToBeBudgetedGroup(
- categoryGroups.filter(g => !g.is_income),
- );
- let [category, setCategory] = useState(null);
-
- function submit() {
- if (category) {
- onSubmit(category);
- onClose();
- }
- }
-
- return (
- <Tooltip
- position="bottom-right"
- width={200}
- style={{ padding: 10 }}
- {...tooltipProps}
- onClose={onClose}
- >
- <View style={{ marginBottom: 5 }}>Cover from category:</View>
-
- <InitialFocus>
- {node => (
- <CategoryAutocomplete
- categoryGroups={categoryGroups}
- value={null}
- openOnFocus={true}
- onUpdate={id => {}}
- onSelect={id => setCategory(id)}
- inputProps={{
- inputRef: node,
- onKeyDown: e => {
- if (e.key === 'Enter') {
- submit();
- }
- },
- }}
- />
- )}
- </InitialFocus>
-
- <View
- style={{
- alignItems: 'flex-end',
- marginTop: 10,
- }}
- >
- <Button
- type="primary"
- style={{
- fontSize: 12,
- paddingTop: 3,
- }}
- onClick={submit}
- >
- Transfer
- </Button>
- </View>
- </Tooltip>
- );
-}
-
-type BalanceTooltipProps = {
- categoryId: string;
- tooltip: { close: () => void };
- monthIndex: number;
- onBudgetAction: (idx: number, action: string, arg?: unknown) => void;
-};
-function BalanceTooltip({
- categoryId,
- tooltip,
- monthIndex,
- onBudgetAction,
-}: BalanceTooltipProps) {
- let carryover = useSheetValue(rolloverBudget.catCarryover(categoryId));
- let balance = useSheetValue(rolloverBudget.catBalance(categoryId));
- let [menu, setMenu] = useState('menu');
-
- return (
- <>
- {menu === 'menu' && (
- <Tooltip
- position="bottom-right"
- width={200}
- style={{ padding: 0 }}
- onClose={tooltip.close}
- >
- <Menu
- onMenuSelect={type => {
- if (type === 'carryover') {
- onBudgetAction(monthIndex, 'carryover', {
- category: categoryId,
- flag: !carryover,
- });
- tooltip.close();
- } else {
- setMenu(type);
- }
- }}
- items={[
- {
- name: 'transfer',
- text: 'Transfer to another category',
- },
- {
- name: 'carryover',
- text: carryover
- ? 'Remove overspending rollover'
- : 'Rollover overspending',
- },
- balance < 0 && {
- name: 'cover',
- text: 'Cover overspending',
- },
- ].filter(x => x)}
- />
- </Tooltip>
- )}
-
- {menu === 'transfer' && (
- <TransferTooltip
- initialAmountName={rolloverBudget.catBalance(categoryId)}
- showToBeBudgeted={true}
- onClose={tooltip.close}
- onSubmit={(amount, toCategory) => {
- onBudgetAction(monthIndex, 'transfer-category', {
- amount,
- from: categoryId,
- to: toCategory,
- });
- }}
- />
- )}
-
- {menu === 'cover' && (
- <CoverTooltip
- onClose={tooltip.close}
- onSubmit={fromCategory => {
- onBudgetAction(monthIndex, 'cover', {
- to: categoryId,
- from: fromCategory,
- });
- }}
- />
- )}
- </>
- );
-}
let headerLabelStyle: CSSProperties = {
flex: 1,
padding: '0 5px',
diff --git a/packages/desktop-client/src/components/budget/util.ts b/packages/desktop-client/src/components/budget/util.ts
index 82f97f4d25..bda8e59e22 100644
--- a/packages/desktop-client/src/components/budget/util.ts
+++ b/packages/desktop-client/src/components/budget/util.ts
@@ -8,7 +8,17 @@ export function addToBeBudgetedGroup(groups: CategoryGroupEntity[]) {
{
id: 'to-be-budgeted',
name: 'To Be Budgeted',
- categories: [{ id: 'to-be-budgeted', name: 'To Be Budgeted' }],
+ categories: [
+ {
+ id: 'to-be-budgeted',
+ name: 'To Be Budgeted',
+ cat_group: 'to-be-budgeted',
+ group: {
+ id: 'to-be-budgeted',
+ name: 'To Be Budgeted',
+ },
+ },
+ ],
},
...groups,
];
diff --git a/packages/desktop-client/src/components/reports/CategorySelector.tsx b/packages/desktop-client/src/components/reports/CategorySelector.tsx
index 8dc2da84da..d41a512722 100644
--- a/packages/desktop-client/src/components/reports/CategorySelector.tsx
+++ b/packages/desktop-client/src/components/reports/CategorySelector.tsx
@@ -1,19 +1,20 @@
import React, { Fragment, useState } from 'react';
+import {
+ type CategoryEntity,
+ type CategoryGroupEntity,
+} from 'loot-core/src/types/models';
+
import Eye from '../../icons/v2/Eye';
import EyeSlashed from '../../icons/v2/EyeSlashed';
-import {
- type Category,
- type CategoryGroup,
- type CategoryListProps,
-} from '../autocomplete/CategoryAutocomplete';
+import { type CategoryListProps } from '../autocomplete/CategoryAutocomplete';
import Button from '../common/Button';
import { Checkbox } from '../forms';
type CategorySelectorProps = {
- categoryGroups: Array<CategoryGroup>;
+ categoryGroups: Array<CategoryGroupEntity>;
selectedCategories: CategoryListProps['items'];
- setSelectedCategories: (selectedCategories: Category[]) => null;
+ setSelectedCategories: (selectedCategories: CategoryEntity[]) => null;
};
export default function CategorySelector({
diff --git a/packages/desktop-client/src/components/tooltips.js b/packages/desktop-client/src/components/tooltips.js
index ba82ea6560..6969e63d3f 100644
--- a/packages/desktop-client/src/components/tooltips.js
+++ b/packages/desktop-client/src/components/tooltips.js
@@ -19,6 +19,7 @@ export function useTooltip() {
},
}),
isOpen,
+ open: () => setIsOpen(true),
close: () => setIsOpen(false),
};
}
diff --git a/packages/desktop-client/src/style/styles.ts b/packages/desktop-client/src/style/styles.ts
index 7ec156c7b4..78bf4b7d95 100644
--- a/packages/desktop-client/src/style/styles.ts
+++ b/packages/desktop-client/src/style/styles.ts
@@ -103,6 +103,16 @@ export const styles = {
outline: 'none',
},
},
+ lineClamp: (lines: number) => {
+ return {
+ display: '-webkit-box',
+ WebkitLineClamp: lines,
+ WebkitBoxOrient: 'vertical',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ wordBreak: 'break-word',
+ };
+ },
// Dynamically set
lightScrollbar: null as CSSProperties | null,
darkScrollbar: null as CSSProperties | null,
diff --git a/packages/loot-core/src/mocks/budget.ts b/packages/loot-core/src/mocks/budget.ts
index 5d4849e49b..2993722a67 100644
--- a/packages/loot-core/src/mocks/budget.ts
+++ b/packages/loot-core/src/mocks/budget.ts
@@ -10,7 +10,6 @@ import { batchMessages, setSyncingMode } from '../server/sync';
import * as monthUtils from '../shared/months';
import q from '../shared/query';
import type {
- CategoryEntity,
CategoryGroupEntity,
PayeeEntity,
TransactionEntity,
@@ -609,9 +608,7 @@ export async function createTestBudget(handlers) {
}),
);
- let categoryGroups: Array<
- CategoryGroupEntity & { categories: Omit<CategoryEntity, 'group'>[] }
- > = [
+ let categoryGroups: Array<CategoryGroupEntity> = [
{
name: 'Usual Expenses',
categories: [
diff --git a/packages/loot-core/src/server/db/index.ts b/packages/loot-core/src/server/db/index.ts
index 5e7d36cc98..a06e08dc2d 100644
--- a/packages/loot-core/src/server/db/index.ts
+++ b/packages/loot-core/src/server/db/index.ts
@@ -12,6 +12,7 @@ import { v4 as uuidv4 } from 'uuid';
import * as fs from '../../platform/server/fs';
import * as sqlite from '../../platform/server/sqlite';
import { groupById } from '../../shared/util';
+import { CategoryEntity, CategoryGroupEntity } from '../../types/models';
import {
schema,
schemaConfig,
@@ -271,28 +272,28 @@ export function updateWithSchema(table, fields) {
// Data-specific functions. Ideally this would be split up into
// different files
-export async function getCategories() {
- return all(`
- SELECT c.* FROM categories c
- LEFT JOIN category_groups cg ON c.cat_group = cg.id
- WHERE c.tombstone = 0
- ORDER BY cg.sort_order, cg.id, c.sort_order, c.id
+export async function getCategories(): Promise<CategoryEntity[]> {
+ return await all(`
+ SELECT c.* FROM categories c WHERE c.tombstone = 0
+ ORDER BY c.sort_order, c.id
`);
}
-export async function getCategoriesGrouped() {
- const groups = await all(
- 'SELECT * FROM category_groups WHERE tombstone = 0 ORDER BY is_income, sort_order, id',
- );
- const rows = await all(`
- SELECT * FROM categories WHERE tombstone = 0
- ORDER BY sort_order, id
+export async function getCategoriesGrouped(): Promise<
+ Array<CategoryGroupEntity>
+> {
+ const groups = await all(`
+ SELECT cg.* FROM category_groups cg WHERE cg.tombstone = 0 ORDER BY cg.is_income, cg.sort_order, cg.id
+ `);
+ const categories = await all(`
+ SELECT c.* FROM categories c WHERE c.tombstone = 0
+ ORDER BY c.sort_order, c.id
`);
return groups.map(group => {
return {
...group,
- categories: rows.filter(row => row.cat_group === group.id),
+ categories: categories.filter(c => c.cat_group === group.id),
};
});
}
diff --git a/packages/loot-core/src/shared/months.ts b/packages/loot-core/src/shared/months.ts
index 1233a7a331..4ea2221359 100644
--- a/packages/loot-core/src/shared/months.ts
+++ b/packages/loot-core/src/shared/months.ts
@@ -220,6 +220,11 @@ export function dayRangeInclusive(start: DateLike, end: DateLike) {
return _dayRange(start, end, true);
}
+export function getMonthFromIndex(year: string, monthIndex: number) {
+ const formatMonth = `${monthIndex + 1}`.padStart(2, '0');
+ return `${year}-${formatMonth}`;
+}
+
export function getMonthIndex(month: string): number {
return parseInt(month.slice(5, 7)) - 1;
}
diff --git a/packages/loot-core/src/types/models/category-group.d.ts b/packages/loot-core/src/types/models/category-group.d.ts
index eca289e442..4225ad6838 100644
--- a/packages/loot-core/src/types/models/category-group.d.ts
+++ b/packages/loot-core/src/types/models/category-group.d.ts
@@ -4,4 +4,6 @@ export interface CategoryGroupEntity {
is_income?: boolean;
sort_order?: number;
tombstone?: boolean;
+ hidden?: boolean;
+ categories?: CategoryEntity[];
}
diff --git a/packages/loot-core/src/types/models/category.d.ts b/packages/loot-core/src/types/models/category.d.ts
index b495fe0d04..2eb075de37 100644
--- a/packages/loot-core/src/types/models/category.d.ts
+++ b/packages/loot-core/src/types/models/category.d.ts
@@ -1,10 +1,9 @@
-import type { CategoryGroupEntity } from './category-group';
-
export interface CategoryEntity {
id?: string;
name: string;
is_income?: boolean;
- group: CategoryGroupEntity;
+ cat_group?: string;
sort_order?: number;
tombstone?: boolean;
+ hidden?: boolean;
}
diff --git a/packages/loot-core/src/types/server-handlers.d.ts b/packages/loot-core/src/types/server-handlers.d.ts
index 8266072216..252ec501fe 100644
--- a/packages/loot-core/src/types/server-handlers.d.ts
+++ b/packages/loot-core/src/types/server-handlers.d.ts
@@ -5,7 +5,7 @@ import { Backup } from '../server/backups';
import { RemoteFile } from '../server/cloud-storage';
import { Message } from '../server/sync';
-import { AccountEntity, PayeeEntity } from './models';
+import { AccountEntity, CategoryEntity, CategoryGroupEntity } from './models';
import { EmptyObject } from './util';
export interface ServerHandlers {
@@ -43,23 +43,8 @@ export interface ServerHandlers {
'transactions-export-query': (arg: { query: queryState }) => Promise<unknown>;
'get-categories': () => Promise<{
- grouped: {
- id: string;
- name: string;
- is_income: number;
- sort_order: number;
- tombstone: number;
- hidden: boolean;
- }[];
- list: {
- id: string;
- name: string;
- is_income: number;
- cat_group: string;
- sort_order: number;
- tombstone: number;
- hidden: boolean;
- }[];
+ grouped: Array<CategoryGroupEntity>;
+ list: Array<CategoryEntity>;
}>;
'get-earliest-transaction': () => Promise<unknown>;
diff --git a/upcoming-release-notes/1802.md b/upcoming-release-notes/1802.md
new file mode 100644
index 0000000000..f76c713bf1
--- /dev/null
+++ b/upcoming-release-notes/1802.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [joel-jeremy]
+---
+
+Mobile balance cover/transfer/rollover overspending