Skip to content

A local-first personal finance app

[TypeScript] More specific types on budget table components (#4524)

Joel Jeremy Marquez866f4891ce38
diff --git a/packages/desktop-client/src/components/budget/IncomeCategory.tsx b/packages/desktop-client/src/components/budget/IncomeCategory.tsx
index e368b9d36a..cfde4e5868 100644
--- a/packages/desktop-client/src/components/budget/IncomeCategory.tsx
+++ b/packages/desktop-client/src/components/budget/IncomeCategory.tsx
@@ -18,16 +18,16 @@ import { SidebarCategory } from './SidebarCategory';
type IncomeCategoryProps = {
cat: CategoryEntity;
isLast?: boolean;
- editingCell: { id: string; cell: string } | null;
+ editingCell: { id: CategoryEntity['id']; cell: string } | null;
MonthComponent: ComponentProps<typeof RenderMonths>['component'];
onEditName: ComponentProps<typeof SidebarCategory>['onEditName'];
- onEditMonth?: (id: string, month: string) => void;
+ onEditMonth?: (id: CategoryEntity['id'], month: string) => void;
onSave: ComponentProps<typeof SidebarCategory>['onSave'];
onDelete: ComponentProps<typeof SidebarCategory>['onDelete'];
onDragChange: OnDragChangeCallback<CategoryEntity>;
onBudgetAction: (month: string, action: string, arg: unknown) => void;
onReorder: OnDropCallback;
- onShowActivity: (id: string, month: string) => void;
+ onShowActivity: (id: CategoryEntity['id'], month: string) => void;
};
export function IncomeCategory({
diff --git a/packages/desktop-client/src/components/budget/IncomeGroup.tsx b/packages/desktop-client/src/components/budget/IncomeGroup.tsx
index 6a25adeff4..cdae91e03a 100644
--- a/packages/desktop-client/src/components/budget/IncomeGroup.tsx
+++ b/packages/desktop-client/src/components/budget/IncomeGroup.tsx
@@ -1,6 +1,8 @@
// @ts-strict-ignore
import React from 'react';
+import { type CategoryGroupEntity } from 'loot-core/types/models';
+
import { theme } from '../../style';
import { Row } from '../table';
@@ -8,22 +10,14 @@ import { RenderMonths } from './RenderMonths';
import { SidebarGroup } from './SidebarGroup';
type IncomeGroupProps = {
- group: {
- id: string;
- hidden: number;
- categories: object[];
- is_income: number;
- name: string;
- sort_order: number;
- tombstone: number;
- };
- editingCell: { id: string; cell: string } | null;
+ group: CategoryGroupEntity;
+ editingCell: { id: CategoryGroupEntity['id']; cell: string } | null;
collapsed: boolean;
MonthComponent: () => JSX.Element;
- onEditName: (id: string) => void;
- onSave: (group: object) => Promise<void>;
- onToggleCollapse: (id: string) => void;
- onShowNewCategory: (groupId: string) => void;
+ onEditName: (id: CategoryGroupEntity['id']) => void;
+ onSave: (group: CategoryGroupEntity) => Promise<void>;
+ onToggleCollapse: (id: CategoryGroupEntity['id']) => void;
+ onShowNewCategory: (groupId: CategoryGroupEntity['id']) => void;
};
export function IncomeGroup({
diff --git a/packages/desktop-client/src/components/budget/SidebarCategory.tsx b/packages/desktop-client/src/components/budget/SidebarCategory.tsx
index 0b08646ce7..e52761e50c 100644
--- a/packages/desktop-client/src/components/budget/SidebarCategory.tsx
+++ b/packages/desktop-client/src/components/budget/SidebarCategory.tsx
@@ -32,9 +32,9 @@ type SidebarCategoryProps = {
style?: CSSProperties;
borderColor?: string;
isLast?: boolean;
- onEditName: (id: string) => void;
+ onEditName: (id: CategoryEntity['id']) => void;
onSave: (category: CategoryEntity) => void;
- onDelete: (id: string) => Promise<void>;
+ onDelete: (id: CategoryEntity['id']) => Promise<void>;
onHideNewCategory?: () => void;
};
diff --git a/packages/desktop-client/src/components/budget/SidebarGroup.tsx b/packages/desktop-client/src/components/budget/SidebarGroup.tsx
index a31da30834..ce626b388a 100644
--- a/packages/desktop-client/src/components/budget/SidebarGroup.tsx
+++ b/packages/desktop-client/src/components/budget/SidebarGroup.tsx
@@ -9,6 +9,11 @@ import { Popover } from '@actual-app/components/popover';
import { Text } from '@actual-app/components/text';
import { View } from '@actual-app/components/view';
+import {
+ type CategoryEntity,
+ type CategoryGroupEntity,
+} from 'loot-core/types/models';
+
import { useContextMenu } from '../../hooks/useContextMenu';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { SvgExpandArrow } from '../../icons/v0';
@@ -18,27 +23,21 @@ import { NotesButton } from '../NotesButton';
import { InputCell } from '../table';
type SidebarGroupProps = {
- group: {
- id: string;
- hidden: number;
- categories: object[];
- is_income: number;
- name: string;
- sort_order: number;
- tombstone: number;
- };
+ group: CategoryGroupEntity;
editing?: boolean;
collapsed: boolean;
dragPreview?: boolean;
innerRef?: ConnectDragSource;
style?: CSSProperties;
- onEdit?: (id: string) => void;
- onSave?: (group: object) => Promise<void>;
- onDelete?: (id: string) => Promise<void>;
- onApplyBudgetTemplatesInGroup?: (categories: object[]) => void;
- onShowNewCategory?: (groupId: string) => void;
+ onEdit?: (id: CategoryGroupEntity['id']) => void;
+ onSave?: (group: CategoryGroupEntity) => Promise<void>;
+ onDelete?: (id: CategoryGroupEntity['id']) => Promise<void>;
+ onApplyBudgetTemplatesInGroup?: (
+ categories: Array<CategoryEntity['id']>,
+ ) => void;
+ onShowNewCategory?: (groupId: CategoryGroupEntity['id']) => void;
onHideNewGroup?: () => void;
- onToggleCollapse?: (id: string) => void;
+ onToggleCollapse?: (id: CategoryGroupEntity['id']) => void;
};
export function SidebarGroup({
@@ -139,9 +138,7 @@ export function SidebarGroup({
onSave({ ...group, hidden: !group.hidden });
} else if (type === 'apply-multiple-category-template') {
onApplyBudgetTemplatesInGroup?.(
- group.categories
- .filter(c => !c['hidden'])
- .map(c => c['id']),
+ group.categories.filter(c => !c.hidden).map(c => c.id),
);
}
setMenuOpen(false);
diff --git a/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx b/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
index eee049d135..758522f5e5 100644
--- a/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
+++ b/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
@@ -17,6 +17,10 @@ import { envelopeBudget } from 'loot-core/client/queries';
import { evalArithmetic } from 'loot-core/shared/arithmetic';
import * as monthUtils from 'loot-core/shared/months';
import { integerToCurrency, amountToInteger } from 'loot-core/shared/util';
+import {
+ type CategoryGroupEntity,
+ type CategoryEntity,
+} from 'loot-core/types/models';
import { useContextMenu } from '../../../hooks/useContextMenu';
import { useUndo } from '../../../hooks/useUndo';
@@ -131,7 +135,7 @@ export function IncomeHeaderMonth() {
type ExpenseGroupMonthProps = {
month: string;
- group: { id: string };
+ group: CategoryGroupEntity;
};
export const ExpenseGroupMonth = memo(function ExpenseGroupMonth({
month,
@@ -189,11 +193,11 @@ export const ExpenseGroupMonth = memo(function ExpenseGroupMonth({
type ExpenseCategoryMonthProps = {
month: string;
- category: { id: string; name: string; is_income: boolean };
+ category: CategoryEntity;
editing: boolean;
- onEdit: (id: string | null, month?: string) => void;
+ onEdit: (id: CategoryEntity['id'] | null, month?: string) => void;
onBudgetAction: (month: string, action: string, arg?: unknown) => void;
- onShowActivity: (id: string, month: string) => void;
+ onShowActivity: (id: CategoryEntity['id'], month: string) => void;
};
export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
month,
@@ -483,10 +487,10 @@ export function IncomeGroupMonth({ month }: IncomeGroupMonthProps) {
}
type IncomeCategoryMonthProps = {
- category: { id: string; name: string };
+ category: CategoryEntity;
isLast: boolean;
month: string;
- onShowActivity: (id: string, month: string) => void;
+ onShowActivity: (id: CategoryEntity['id'], month: string) => void;
};
export function IncomeCategoryMonth({
category,
diff --git a/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx b/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
index 3afc6948e0..0514d8dbfc 100644
--- a/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
+++ b/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
@@ -19,6 +19,10 @@ import { trackingBudget } from 'loot-core/client/queries';
import { evalArithmetic } from 'loot-core/shared/arithmetic';
import * as monthUtils from 'loot-core/shared/months';
import { integerToCurrency, amountToInteger } from 'loot-core/shared/util';
+import {
+ type CategoryEntity,
+ type CategoryGroupEntity,
+} from 'loot-core/types/models';
import { useUndo } from '../../../hooks/useUndo';
import { SvgCheveronDown } from '../../../icons/v1';
@@ -134,7 +138,7 @@ export function IncomeHeaderMonth() {
type GroupMonthProps = {
month: string;
- group: { id: string; is_income: boolean };
+ group: CategoryGroupEntity;
};
export const GroupMonth = memo(function GroupMonth({
month,
@@ -194,11 +198,11 @@ export const GroupMonth = memo(function GroupMonth({
type CategoryMonthProps = {
month: string;
- category: { id: string; name: string; is_income: boolean };
+ category: CategoryEntity;
editing: boolean;
- onEdit: (id: string | null, month?: string) => void;
+ onEdit: (id: CategoryEntity['id'] | null, month?: string) => void;
onBudgetAction: (month: string, action: string, arg: unknown) => void;
- onShowActivity: (id: string, month: string) => void;
+ onShowActivity: (id: CategoryEntity['id'], month: string) => void;
};
export const CategoryMonth = memo(function CategoryMonth({
month,
diff --git a/upcoming-release-notes/4524.md b/upcoming-release-notes/4524.md
new file mode 100644
index 0000000000..89898a615f
--- /dev/null
+++ b/upcoming-release-notes/4524.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [joel-jeremy]
+---
+
+[TypeScript] More specific types on budget table components