Skip to content

A local-first personal finance app

Add upcoming/missed/due schedules indicator on budget table (based on category schedule templates) (#4815)

Joel Jeremy Marquez10a143a3aeb0
diff --git a/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx b/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx
index 6cdd44e38e..5eeafd570f 100644
--- a/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx
+++ b/packages/desktop-client/src/components/budget/BalanceWithCarryover.tsx
@@ -94,7 +94,7 @@ type BalanceWithCarryoverProps = Omit<
budgeted: Binding<'envelope-budget' | 'tracking-budget', 'budget'>;
longGoal: Binding<'envelope-budget' | 'tracking-budget', 'long-goal'>;
isDisabled?: boolean;
- isMobileEnvelopeModal?: boolean;
+ shouldInlineGoalStatus?: boolean;
CarryoverIndicator?: ComponentType<CarryoverIndicatorProps>;
};
@@ -105,7 +105,7 @@ export function BalanceWithCarryover({
budgeted,
longGoal,
isDisabled,
- isMobileEnvelopeModal,
+ shouldInlineGoalStatus,
CarryoverIndicator: CarryoverIndicatorComponent = CarryoverIndicator,
children,
...props
@@ -282,7 +282,7 @@ export function BalanceWithCarryover({
style={getBalanceAmountStyle(balanceValue)}
/>
)}
- {isMobileEnvelopeModal &&
+ {shouldInlineGoalStatus &&
isGoalTemplatesEnabled &&
goalValue !== null && (
<>
diff --git a/packages/desktop-client/src/components/budget/BudgetTable.tsx b/packages/desktop-client/src/components/budget/BudgetTable.tsx
index dd74a7e7e5..46c13acdc8 100644
--- a/packages/desktop-client/src/components/budget/BudgetTable.tsx
+++ b/packages/desktop-client/src/components/budget/BudgetTable.tsx
@@ -1,6 +1,7 @@
import React, {
type ComponentPropsWithoutRef,
type KeyboardEvent,
+ useMemo,
useState,
} from 'react';
@@ -8,6 +9,8 @@ import { styles } from '@actual-app/components/styles';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
+import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
+import { q } from 'loot-core/shared/query';
import {
type CategoryEntity,
type CategoryGroupEntity,
@@ -227,6 +230,8 @@ export function BudgetTable(props: BudgetTableProps) {
onCollapse(categoryGroups.map(g => g.id));
};
+ const schedulesQuery = useMemo(() => q('schedules').select('*'), []);
+
return (
<View
data-testid="budget-table"
@@ -291,23 +296,25 @@ export function BudgetTable(props: BudgetTableProps) {
}}
onKeyDown={onKeyDown}
>
- <BudgetCategories
- // @ts-expect-error Fix when migrating BudgetCategories to ts
- categoryGroups={categoryGroups}
- editingCell={editing}
- dataComponents={dataComponents}
- onEditMonth={onEditMonth}
- onEditName={onEditName}
- onSaveCategory={onSaveCategory}
- onSaveGroup={onSaveGroup}
- onDeleteCategory={onDeleteCategory}
- onDeleteGroup={onDeleteGroup}
- onReorderCategory={_onReorderCategory}
- onReorderGroup={_onReorderGroup}
- onBudgetAction={onBudgetAction}
- onShowActivity={onShowActivity}
- onApplyBudgetTemplatesInGroup={onApplyBudgetTemplatesInGroup}
- />
+ <SchedulesProvider query={schedulesQuery}>
+ <BudgetCategories
+ // @ts-expect-error Fix when migrating BudgetCategories to ts
+ categoryGroups={categoryGroups}
+ editingCell={editing}
+ dataComponents={dataComponents}
+ onEditMonth={onEditMonth}
+ onEditName={onEditName}
+ onSaveCategory={onSaveCategory}
+ onSaveGroup={onSaveGroup}
+ onDeleteCategory={onDeleteCategory}
+ onDeleteGroup={onDeleteGroup}
+ onReorderCategory={_onReorderCategory}
+ onReorderGroup={_onReorderGroup}
+ onBudgetAction={onBudgetAction}
+ onShowActivity={onShowActivity}
+ onApplyBudgetTemplatesInGroup={onApplyBudgetTemplatesInGroup}
+ />
+ </SchedulesProvider>
</View>
</View>
</MonthsProvider>
diff --git a/packages/desktop-client/src/components/budget/SidebarCategory.tsx b/packages/desktop-client/src/components/budget/SidebarCategory.tsx
index 332f28c93e..e4022a516c 100644
--- a/packages/desktop-client/src/components/budget/SidebarCategory.tsx
+++ b/packages/desktop-client/src/components/budget/SidebarCategory.tsx
@@ -6,6 +6,7 @@ import { Button } from '@actual-app/components/button';
import { SvgCheveronDown } from '@actual-app/components/icons/v1';
import { Menu } from '@actual-app/components/menu';
import { Popover } from '@actual-app/components/popover';
+import { TextOneLine } from '@actual-app/components/text-one-line';
import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
@@ -56,7 +57,7 @@ export function SidebarCategory({
onHideNewCategory,
}: SidebarCategoryProps) {
const { t } = useTranslation();
- const goalTemplatesUIEnabled = useFeatureFlag('goalTemplatesUIEnabled');
+ const isGoalTemplatesUIEnabled = useFeatureFlag('goalTemplatesUIEnabled');
const [categoryExpandedStatePref] = useGlobalPref('categoryExpandedState');
const categoryExpandedState = categoryExpandedStatePref ?? 0;
@@ -79,17 +80,7 @@ export function SidebarCategory({
ref={triggerRef}
onContextMenu={handleContextMenu}
>
- <div
- data-testid="category-name"
- style={{
- textOverflow: 'ellipsis',
- whiteSpace: 'nowrap',
- overflow: 'hidden',
- minWidth: 0,
- }}
- >
- {category.name}
- </div>
+ <TextOneLine data-testid="category-name">{category.name}</TextOneLine>
<View style={{ flexShrink: 0, marginLeft: 5 }}>
<Button
variant="bare"
@@ -139,7 +130,7 @@ export function SidebarCategory({
</Popover>
</View>
<View style={{ flex: 1 }} />
- {!goalsShown && goalTemplatesUIEnabled && (
+ {!goalsShown && isGoalTemplatesUIEnabled && (
<View style={{ flexShrink: 0 }}>
<CategoryAutomationButton
style={dragging && { color: 'currentColor' }}
diff --git a/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx b/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
index 61e5ba6629..0997f40704 100644
--- a/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
+++ b/packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
@@ -8,6 +8,10 @@ import { useTranslation, Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { SvgCheveronDown } from '@actual-app/components/icons/v1';
+import {
+ SvgArrowsSynchronize,
+ SvgCalendar3,
+} from '@actual-app/components/icons/v2';
import { Popover } from '@actual-app/components/popover';
import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
@@ -35,7 +39,9 @@ import { makeAmountGrey } from '../util';
import { BalanceMovementMenu } from './BalanceMovementMenu';
import { BudgetMenu } from './BudgetMenu';
+import { useCategoryScheduleGoalTemplateIndicator } from '@desktop-client/hooks/useCategoryScheduleGoalTemplateIndicator';
import { useContextMenu } from '@desktop-client/hooks/useContextMenu';
+import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useUndo } from '@desktop-client/hooks/useUndo';
export function useEnvelopeSheetName<
@@ -234,6 +240,16 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
const { showUndoNotification } = useUndo();
+ const navigate = useNavigate();
+
+ const { schedule, scheduleStatus, isScheduleRecurring, description } =
+ useCategoryScheduleGoalTemplateIndicator({
+ category,
+ month,
+ });
+
+ const showScheduleIndicator = schedule && scheduleStatus;
+
return (
<View
style={{
@@ -388,10 +404,44 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
/>
</View>
<Field name="spent" width="flex" style={{ textAlign: 'right' }}>
- <span
+ <View
data-testid="category-month-spent"
onClick={() => onShowActivity(category.id, month)}
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: showScheduleIndicator
+ ? 'space-between'
+ : 'flex-end',
+ gap: 2,
+ }}
>
+ {showScheduleIndicator && (
+ <View title={description}>
+ <Button
+ variant="bare"
+ style={{
+ color:
+ scheduleStatus === 'missed'
+ ? theme.errorText
+ : scheduleStatus === 'due'
+ ? theme.warningText
+ : theme.upcomingText,
+ }}
+ onPress={() =>
+ schedule._account
+ ? navigate(`/accounts/${schedule._account}`)
+ : navigate('/accounts')
+ }
+ >
+ {isScheduleRecurring ? (
+ <SvgArrowsSynchronize style={{ width: 12, height: 12 }} />
+ ) : (
+ <SvgCalendar3 style={{ width: 12, height: 12 }} />
+ )}
+ </Button>
+ </View>
+ )}
<EnvelopeCellValue
binding={envelopeBudget.catSumAmount(category.id)}
type="financial"
@@ -407,7 +457,7 @@ export const ExpenseCategoryMonth = memo(function ExpenseCategoryMonth({
/>
)}
</EnvelopeCellValue>
- </span>
+ </View>
</Field>
<Field
ref={balanceMenuTriggerRef}
diff --git a/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx b/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
index 9b29e9dec9..cba45be67c 100644
--- a/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
+++ b/packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
@@ -10,6 +10,10 @@ import { Trans } from 'react-i18next';
import { Button } from '@actual-app/components/button';
import { SvgCheveronDown } from '@actual-app/components/icons/v1';
+import {
+ SvgArrowsSynchronize,
+ SvgCalendar3,
+} from '@actual-app/components/icons/v2';
import { Popover } from '@actual-app/components/popover';
import { styles } from '@actual-app/components/styles';
import { Text } from '@actual-app/components/text';
@@ -36,6 +40,8 @@ import { makeAmountGrey } from '../util';
import { BalanceMenu } from './BalanceMenu';
import { BudgetMenu } from './BudgetMenu';
+import { useCategoryScheduleGoalTemplateIndicator } from '@desktop-client/hooks/useCategoryScheduleGoalTemplateIndicator';
+import { useNavigate } from '@desktop-client/hooks/useNavigate';
import { useUndo } from '@desktop-client/hooks/useUndo';
export const useTrackingSheetValue = <
@@ -227,6 +233,16 @@ export const CategoryMonth = memo(function CategoryMonth({
const { showUndoNotification } = useUndo();
+ const navigate = useNavigate();
+
+ const { schedule, scheduleStatus, isScheduleRecurring, description } =
+ useCategoryScheduleGoalTemplateIndicator({
+ category,
+ month,
+ });
+
+ const showScheduleIndicator = schedule && scheduleStatus;
+
return (
<View
style={{
@@ -368,10 +384,44 @@ export const CategoryMonth = memo(function CategoryMonth({
/>
</View>
<Field name="spent" width="flex" style={{ textAlign: 'right' }}>
- <span
+ <View
data-testid="category-month-spent"
onClick={() => onShowActivity(category.id, month)}
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ justifyContent: showScheduleIndicator
+ ? 'space-between'
+ : 'flex-end',
+ gap: 2,
+ }}
>
+ {showScheduleIndicator && (
+ <View title={description}>
+ <Button
+ variant="bare"
+ style={{
+ color:
+ scheduleStatus === 'missed'
+ ? theme.errorText
+ : scheduleStatus === 'due'
+ ? theme.warningText
+ : theme.upcomingText,
+ }}
+ onPress={() =>
+ schedule._account
+ ? navigate(`/accounts/${schedule._account}`)
+ : navigate('/accounts')
+ }
+ >
+ {isScheduleRecurring ? (
+ <SvgArrowsSynchronize style={{ width: 12, height: 12 }} />
+ ) : (
+ <SvgCalendar3 style={{ width: 12, height: 12 }} />
+ )}
+ </Button>
+ </View>
+ )}
<TrackingCellValue
binding={trackingBudget.catSumAmount(category.id)}
type="financial"
@@ -389,7 +439,7 @@ export const CategoryMonth = memo(function CategoryMonth({
/>
)}
</TrackingCellValue>
- </span>
+ </View>
</Field>
{!category.is_income && (
diff --git a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
index 6827ed68e4..5ff4bc6894 100644
--- a/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
+++ b/packages/desktop-client/src/components/mobile/budget/BudgetTable.jsx
@@ -23,6 +23,7 @@ import { theme } from '@actual-app/components/theme';
import { View } from '@actual-app/components/view';
import { AutoTextSize } from 'auto-text-size';
+import { SchedulesProvider } from 'loot-core/client/data-hooks/schedules';
import { pushModal } from 'loot-core/client/modals/modalsSlice';
import {
envelopeBudget,
@@ -30,6 +31,7 @@ import {
uncategorizedCount,
} from 'loot-core/client/queries';
import * as monthUtils from 'loot-core/shared/months';
+import { q } from 'loot-core/shared/query';
import { groupById } from 'loot-core/shared/util';
import { useDispatch } from '../../../redux';
@@ -340,6 +342,8 @@ export function BudgetTable({
const [budgetType = 'envelope'] = useSyncedPref('budgetType');
+ const schedulesQuery = useMemo(() => q('schedules').select('*'), []);
+
return (
<Page
padding={0}
@@ -404,17 +408,19 @@ export function BudgetTable({
paddingBottom: MOBILE_NAV_HEIGHT,
}}
>
- <BudgetGroups
- type={budgetType}
- categoryGroups={categoryGroups}
- showBudgetedColumn={!showSpentColumn}
- show3Columns={show3Columns}
- showHiddenCategories={showHiddenCategories}
- month={month}
- onEditCategoryGroup={onEditCategoryGroup}
- onEditCategory={onEditCategory}
- onBudgetAction={onBudgetAction}
- />
+ <SchedulesProvider query={schedulesQuery}>
+ <BudgetGroups
+ type={budgetType}
+ categoryGroups={categoryGroups}
+ showBudgetedColumn={!showSpentColumn}
+ show3Columns={show3Columns}
+ showHiddenCategories={showHiddenCategories}
+ month={month}
+ onEditCategoryGroup={onEditCategoryGroup}
+ onEditCategory={onEditCategory}
+ onBudgetAction={onBudgetAction}
+ />
+ </SchedulesProvider>
</View>
</PullToRefresh>
</Page>
diff --git a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
index 4e25efb841..c43536faa6 100644
--- a/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/CategoryTransactions.tsx
@@ -1,4 +1,4 @@
-import React, { useCallback, useEffect, useState } from 'react';
+import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { TextOneLine } from '@actual-app/components/text-one-line';
import { View } from '@actual-app/components/view';
@@ -24,6 +24,7 @@ import { MobileBackButton } from '../MobileBackButton';
import { AddTransactionButton } from '../transactions/AddTransactionButton';
import { TransactionListWithBalances } from '../transactions/TransactionListWithBalances';
+import { useCategoryPreviewTransactions } from '@desktop-client/hooks/useCategoryPreviewTransactions';
import { useDateFormat } from '@desktop-client/hooks/useDateFormat';
import { useLocale } from '@desktop-client/hooks/useLocale';
import { useNavigate } from '@desktop-client/hooks/useNavigate';
@@ -38,6 +39,43 @@ export function CategoryTransactions({
month,
}: CategoryTransactionsProps) {
const locale = useLocale();
+
+ const schedulesQuery = useMemo(() => q('schedules').select('*'), []);
+
+ return (
+ <Page
+ header={
+ <MobilePageHeader
+ title={
+ <View>
+ <TextOneLine>{category.name}</TextOneLine>
+ <TextOneLine>
+ ({monthUtils.format(month, 'MMMM ‘yy', locale)})
+ </TextOneLine>
+ </View>
+ }
+ leftContent={<MobileBackButton />}
+ rightContent={<AddTransactionButton categoryId={category.id} />}
+ />
+ }
+ padding={0}
+ >
+ <SchedulesProvider query={schedulesQuery}>
+ <TransactionListWithPreviews category={category} month={month} />
+ </SchedulesProvider>
+ </Page>
+ );
+}
+
+type TransactionListWithPreviewsProps = {
+ category: CategoryEntity;
+ month: string;
+};
+
+function TransactionListWithPreviews({
+ category,
+ month,
+}: TransactionListWithPreviewsProps) {
const dispatch = useDispatch();
const navigate = useNavigate();
@@ -80,7 +118,7 @@ export function CategoryTransactions({
});
}, [dispatch, reloadTransactions]);
- const { search: onSearch } = useTransactionsSearch({
+ const { isSearching, search: onSearch } = useTransactionsSearch({
updateQuery: setTransactionsQuery,
resetQuery: () => setTransactionsQuery(baseTransactionsQuery()),
dateFormat,
@@ -100,41 +138,31 @@ export function CategoryTransactions({
const balanceCleared = queries.categoryBalanceCleared(category, month);
const balanceUncleared = queries.categoryBalanceUncleared(category, month);
+ const { previewTransactions } = useCategoryPreviewTransactions({
+ categoryId: category.id,
+ month,
+ });
+
+ const transactionsToDisplay = !isSearching
+ ? // Do not render child transactions in the list, unless searching
+ previewTransactions.concat(transactions.filter(t => !t.is_child))
+ : transactions;
+
return (
- <Page
- header={
- <MobilePageHeader
- title={
- <View>
- <TextOneLine>{category.name}</TextOneLine>
- <TextOneLine>
- ({monthUtils.format(month, 'MMMM ‘yy', locale)})
- </TextOneLine>
- </View>
- }
- leftContent={<MobileBackButton />}
- rightContent={<AddTransactionButton categoryId={category.id} />}
- />
- }
- padding={0}
- >
- <SchedulesProvider>
- <TransactionListWithBalances
- isLoading={isLoading}
- transactions={transactions}
- balance={balance}
- balanceCleared={balanceCleared}
- balanceUncleared={balanceUncleared}
- searchPlaceholder={`Search ${category.name}`}
- onSearch={onSearch}
- isLoadingMore={isLoadingMore}
- onLoadMore={loadMoreTransactions}
- onOpenTransaction={onOpenTransaction}
- onRefresh={undefined}
- account={undefined}
- />
- </SchedulesProvider>
- </Page>
+ <TransactionListWithBalances
+ isLoading={isLoading}
+ transactions={transactionsToDisplay}
+ balance={balance}
+ balanceCleared={balanceCleared}
+ balanceUncleared={balanceUncleared}
+ searchPlaceholder={`Search ${category.name}`}
+ onSearch={onSearch}
+ isLoadingMore={isLoadingMore}
+ onLoadMore={loadMoreTransactions}
+ onOpenTransaction={onOpenTransaction}
+ onRefresh={undefined}
+ account={undefined}
+ />
);
}
diff --git a/packages/desktop-client/src/components/mobile/budget/ExpenseCategoryListItem.tsx b/packages/desktop-client/src/components/mobile/budget/ExpenseCategoryListItem.tsx
index 1ade1af9e5..1512b11532 100644
--- a/packages/desktop-client/src/components/mobile/budget/ExpenseCategoryListItem.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/ExpenseCategoryListItem.tsx
@@ -43,6 +43,7 @@ function ExpenseCategoryName({
show3Columns,
isSidebar: true,
});
+
return (
<View
style={{
@@ -174,6 +175,7 @@ function ExpenseCategoryCells({
<SpentCell
binding={spent}
category={category}
+ month={month}
show3Columns={show3Columns}
onPress={onShowActivity}
/>
diff --git a/packages/desktop-client/src/components/mobile/budget/SpentCell.tsx b/packages/desktop-client/src/components/mobile/budget/SpentCell.tsx
index 78bd4c991d..31b0d5e0d1 100644
--- a/packages/desktop-client/src/components/mobile/budget/SpentCell.tsx
+++ b/packages/desktop-client/src/components/mobile/budget/SpentCell.tsx
@@ -1,7 +1,13 @@
import { useTranslation } from 'react-i18next';
import { Button } from '@actual-app/components/button';
+import {
+ SvgArrowsSynchronize,
+ SvgCalendar3,
+} from '@actual-app/components/icons/v2';
import { Text } from '@actual-app/components/text';
+import { theme } from '@actual-app/components/theme';
+import { View } from '@actual-app/components/view';
import { AutoTextSize } from 'auto-text-size';
import { type CategoryEntity } from 'loot-core/types/models';
@@ -13,10 +19,12 @@ import { PrivacyFilter } from '@desktop-client/components/PrivacyFilter';
import { type Binding } from '@desktop-client/components/spreadsheet';
import { CellValue } from '@desktop-client/components/spreadsheet/CellValue';
import { useFormat } from '@desktop-client/components/spreadsheet/useFormat';
+import { useCategoryScheduleGoalTemplateIndicator } from '@desktop-client/hooks/useCategoryScheduleGoalTemplateIndicator';
type SpentCellProps = {
binding: Binding<'envelope-budget' | 'tracking-budget', 'sum-amount'>;
category: CategoryEntity;
+ month: string;
show3Columns?: boolean;
onPress?: () => void;
};
@@ -24,6 +32,7 @@ type SpentCellProps = {
export function SpentCell({
binding,
category,
+ month,
show3Columns,
onPress,
}: SpentCellProps) {
@@ -32,6 +41,13 @@ export function SpentCell({
const columnWidth = getColumnWidth({
show3Columns,
});
+
+ const { schedule, scheduleStatus, isScheduleRecurring } =
+ useCategoryScheduleGoalTemplateIndicator({
+ category,
+ month,
+ });
+
return (
<CellValue<'envelope-budget' | 'tracking-budget', 'sum-amount'>
binding={binding}
@@ -41,34 +57,58 @@ export function SpentCell({
})}
>
{({ type, value }) => (
- <Button
- variant="bare"
- style={{
- ...PILL_STYLE,
- }}
- onPress={onPress}
- aria-label={t('Show transactions for {{categoryName}} category', {
- categoryName: category.name,
- })}
- >
- <PrivacyFilter>
- <AutoTextSize
- key={value}
- as={Text}
- minFontSizePx={6}
- maxFontSizePx={12}
- mode="oneline"
+ <>
+ <Button
+ variant="bare"
+ style={{
+ ...PILL_STYLE,
+ }}
+ onPress={onPress}
+ aria-label={t('Show transactions for {{categoryName}} category', {
+ categoryName: category.name,
+ })}
+ >
+ <PrivacyFilter>
+ <AutoTextSize
+ key={value}
+ as={Text}
+ minFontSizePx={6}
+ maxFontSizePx={12}
+ mode="oneline"
+ style={{
+ ...makeAmountGrey(value),
+ maxWidth: columnWidth,
+ textAlign: 'right',
+ fontSize: 12,
+ }}
+ >
+ {format(value, type)}
+ </AutoTextSize>
+ </PrivacyFilter>
+ </Button>
+ {schedule && scheduleStatus && (
+ <View
style={{
- ...makeAmountGrey(value),
- maxWidth: columnWidth,
- textAlign: 'right',
- fontSize: 12,
+ position: 'absolute',
+ right: '-3px',
+ top: '-5px',
+ borderRadius: '50%',
+ color:
+ scheduleStatus === 'missed'
+ ? theme.errorText
+ : scheduleStatus === 'due'
+ ? theme.warningText
+ : theme.upcomingText,
}}
>
- {format(value, type)}
- </AutoTextSize>
- </PrivacyFilter>
- </Button>
+ {isScheduleRecurring ? (
+ <SvgArrowsSynchronize width={11} height={11} />
+ ) : (
+ <SvgCalendar3 width={10} height={10} />
+ )}
+ </View>
+ )}
+ </>
)}
</CellValue>
);
diff --git a/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx b/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx
index b6e31e0809..2923794f7c 100644
--- a/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx
+++ b/packages/desktop-client/src/components/modals/EnvelopeBalanceMenuModal.tsx
@@ -74,7 +74,7 @@ export function EnvelopeBalanceMenuModal({
</Text>
<BalanceWithCarryover
isDisabled
- isMobileEnvelopeModal
+ shouldInlineGoalStatus
carryover={envelopeBudget.catCarryover(categoryId)}
balance={envelopeBudget.catBalance(categoryId)}
goal={envelopeBudget.catGoal(categoryId)}
diff --git a/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts b/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts
new file mode 100644
index 0000000000..d1028ddbbc
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useCategoryPreviewTransactions.ts
@@ -0,0 +1,47 @@
+import { useMemo } from 'react';
+
+import { usePreviewTransactions } from 'loot-core/client/data-hooks/transactions';
+import * as monthUtils from 'loot-core/shared/months';
+import { type CategoryEntity } from 'loot-core/types/models';
+
+import { useCategory } from './useCategory';
+import { useCategoryScheduleGoalTemplates } from './useCategoryScheduleGoalTemplates';
+
+type UseCategoryPreviewTransactionsProps = {
+ categoryId: CategoryEntity['id'];
+ month: string;
+};
+
+export function useCategoryPreviewTransactions({
+ categoryId,
+ month,
+}: UseCategoryPreviewTransactionsProps) {
+ const category = useCategory(categoryId);
+ const { schedules } = useCategoryScheduleGoalTemplates({
+ category,
+ });
+ const { data: allPreviewTransactions, isLoading } = usePreviewTransactions();
+
+ return useMemo(() => {
+ const schedulesToPreview = new Set(
+ schedules
+ .filter(schedule => monthUtils.getMonth(schedule.next_date) === month)
+ .map(schedule => schedule.id),
+ );
+
+ if (!category || !schedulesToPreview.size) {
+ return {
+ previewTransactions: [],
+ isLoading: false,
+ };
+ }
+
+ return {
+ previewTransactions: allPreviewTransactions.filter(
+ transaction =>
+ transaction.schedule && schedulesToPreview.has(transaction.schedule),
+ ),
+ isLoading,
+ };
+ }, [allPreviewTransactions, category, isLoading, month, schedules]);
+}
diff --git a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
new file mode 100644
index 0000000000..4aa4cc7a6d
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplateIndicator.ts
@@ -0,0 +1,140 @@
+import { useMemo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import { type TFunction } from 'i18next';
+
+import { type ScheduleStatusType } from 'loot-core/client/data-hooks/schedules';
+import * as monthUtils from 'loot-core/shared/months';
+import {
+ type CategoryEntity,
+ type ScheduleEntity,
+} from 'loot-core/types/models';
+
+import { useCategoryScheduleGoalTemplates } from './useCategoryScheduleGoalTemplates';
+import { useLocale } from './useLocale';
+
+type UseCategoryScheduleGoalTemplateProps = {
+ category: CategoryEntity;
+ month: string;
+};
+
+type UseCategoryScheduleGoalTemplateResult = {
+ schedule: ScheduleEntity | null;
+ scheduleStatus: ScheduleStatusType | null;
+ isScheduleRecurring: boolean;
+ description: string;
+};
+
+/**
+ * We only display an indicator for one schedule at a time, so we
+ * filter and then sort the schedules to show missed schedules first,
+ * then due schedules, then upcoming schedules. This is to ensure that
+ * the user sees the most important schedule first.
+ */
+export function useCategoryScheduleGoalTemplateIndicator({
+ category,
+ month,
+}: UseCategoryScheduleGoalTemplateProps): UseCategoryScheduleGoalTemplateResult {
+ const { t } = useTranslation();
+ const locale = useLocale();
+
+ const { schedules, statuses: scheduleStatuses } =
+ useCategoryScheduleGoalTemplates({
+ category,
+ });
+
+ return useMemo<UseCategoryScheduleGoalTemplateResult>(() => {
+ const schedulesToDisplay = schedules
+ .filter(schedule => {
+ const status = scheduleStatuses.get(schedule.id);
+ return status === 'upcoming' || status === 'due' || status === 'missed';
+ })
+ .filter(
+ schedule => monthUtils.monthFromDate(schedule.next_date) === month,
+ )
+ .sort((a, b) => {
+ // Display missed schedules first, then due, then upcoming.
+ const aStatus = scheduleStatuses.get(a.id);
+ const bStatus = scheduleStatuses.get(b.id);
+ if (aStatus === 'missed' && bStatus !== 'missed') return -1;
+ if (bStatus === 'missed' && aStatus !== 'missed') return 1;
+ if (aStatus === 'due' && bStatus !== 'due') return -1;
+ if (bStatus === 'due' && aStatus !== 'due') return 1;
+ return 0;
+ });
+
+ const description = schedulesToDisplay
+ .map(s => {
+ return getScheduleStatusDescription({
+ t,
+ schedule: s,
+ scheduleStatus: scheduleStatuses.get(s.id),
+ locale,
+ });
+ })
+ .join('\n');
+
+ const schedule = schedulesToDisplay[0] || null;
+ const scheduleStatus =
+ (schedule ? scheduleStatuses.get(schedule.id) : null) || null;
+
+ return {
+ schedule,
+ scheduleStatus,
+ isScheduleRecurring: !!schedule?._date?.frequency,
+ description,
+ };
+ }, [locale, month, scheduleStatuses, schedules, t]);
+}
+
+function getScheduleStatusDescription({
+ t,
+ schedule,
+ scheduleStatus,
+ locale,
+}: {
+ t: TFunction;
+ schedule?: ScheduleEntity;
+ scheduleStatus?: ScheduleStatusType;
+ locale?: Locale;
+}) {
+ if (!schedule || !scheduleStatus) {
+ return '';
+ }
+
+ const isToday = monthUtils.isCurrentDay(schedule.next_date);
+ const distanceFromNow = monthUtils.formatDistance(
+ schedule.next_date,
+ monthUtils.currentDay(),
+ locale,
+ {
+ addSuffix: true,
+ },
+ );
+ const formattedDate = monthUtils.format(schedule.next_date, 'MMMM d', locale);
+ switch (scheduleStatus) {
+ case 'missed':
+ return t(
+ 'Missed {{scheduleName}} due {{distanceFromNow}} ({{formattedDate}})',
+ {
+ scheduleName: schedule.name,
+ distanceFromNow,
+ formattedDate,
+ },
+ );
+ case 'due':
+ case 'upcoming':
+ return t(
+ '{{scheduleName}} is due {{distanceFromNow}} ({{formattedDate}})',
+ {
+ scheduleName: schedule.name,
+ distanceFromNow: isToday ? t('today') : distanceFromNow,
+ formattedDate,
+ },
+ );
+ default:
+ throw new Error(
+ `Unsupported schedule status for tooltip: ${scheduleStatus}`,
+ );
+ }
+}
diff --git a/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts
new file mode 100644
index 0000000000..f8fbfd14ce
--- /dev/null
+++ b/packages/desktop-client/src/hooks/useCategoryScheduleGoalTemplates.ts
@@ -0,0 +1,95 @@
+import { useMemo } from 'react';
+
+import {
+ type ScheduleStatuses,
+ type ScheduleStatusLabels,
+ useCachedSchedules,
+} from 'loot-core/client/data-hooks/schedules';
+import {
+ type ScheduleEntity,
+ type CategoryEntity,
+} from 'loot-core/types/models';
+
+import { useFeatureFlag } from './useFeatureFlag';
+
+type ScheduleGoalDefinition = {
+ type: 'schedule';
+ name: ScheduleEntity['name'];
+};
+
+type UseCategoryScheduleGoalTemplatesProps = {
+ category?: CategoryEntity | undefined;
+};
+
+type UseCategoryScheduleGoalTemplatesResult = {
+ schedules: ScheduleEntity[];
+ statuses: ScheduleStatuses;
+ statusLabels: ScheduleStatusLabels;
+};
+
+export function useCategoryScheduleGoalTemplates({
+ category,
+}: UseCategoryScheduleGoalTemplatesProps): UseCategoryScheduleGoalTemplatesResult {
+ const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');
+ const {
+ schedules: allSchedules,
+ statuses: allStatuses,
+ statusLabels: allStatusLabels,
+ } = useCachedSchedules();
+
+ return useMemo(() => {
+ if (!isGoalTemplatesEnabled || !category || !category.goal_def) {
+ return {
+ schedules: [],
+ statuses: new Map(),
+ statusLabels: new Map(),
+ };
+ }
+
+ let goalDefinitions: Record<string, unknown>[] = [];
+ try {
+ goalDefinitions = JSON.parse(category.goal_def);
+ } catch (e) {
+ console.error('Failed to parse category goal_def:', e);
+ return {
+ schedules: [],
+ statuses: new Map(),
+ statusLabels: new Map(),
+ };
+ }
+
+ const scheduleGoalDefinitions = goalDefinitions.filter(
+ g => g.type === 'schedule',
+ ) as ScheduleGoalDefinition[];
+
+ if (!scheduleGoalDefinitions.length) {
+ return {
+ schedules: [],
+ statuses: new Map(),
+ statusLabels: new Map(),
+ };
+ }
+
+ const schedules = allSchedules.filter(s =>
+ scheduleGoalDefinitions.some(g => g.name === s.name),
+ );
+ const statuses = new Map(
+ [...allStatuses].filter(([id]) => schedules.some(s => s.id === id)),
+ );
+ const statusLabels = new Map(
+ [...allStatusLabels].filter(([id]) => schedules.some(s => s.id === id)),
+ );
+
+ return {
+ schedules,
+ statuses,
+ statusLabels,
+ };
+ }, [
+ allSchedules,
+ allStatusLabels,
+ allStatuses,
+ category,
+ isGoalTemplatesEnabled,
+ ]);
+}
diff --git a/packages/loot-core/src/shared/months.ts b/packages/loot-core/src/shared/months.ts
index 9986caa216..715d5768bc 100644
--- a/packages/loot-core/src/shared/months.ts
+++ b/packages/loot-core/src/shared/months.ts
@@ -228,6 +228,10 @@ export function isCurrentMonth(month: DateLike): boolean {
return month === currentMonth();
}
+export function isCurrentDay(day: DateLike): boolean {
+ return day === currentDay();
+}
+
// TODO: This doesn't really fit in this module anymore, should
// probably live elsewhere
export function bounds(month: DateLike): { start: number; end: number } {
@@ -405,6 +409,18 @@ export function format(
return d.format(_parse(month), format, { locale });
}
+export function formatDistance(
+ date1: DateLike,
+ date2: DateLike,
+ locale?: Locale,
+ options?: { addSuffix?: boolean; includeSeconds?: boolean },
+): string {
+ return d.formatDistance(_parse(date1), _parse(date2), {
+ locale,
+ ...options,
+ });
+}
+
export const getDateFormatRegex = memoizeOne((format: string) => {
return new RegExp(
format
diff --git a/packages/loot-core/src/types/models/category.ts b/packages/loot-core/src/types/models/category.ts
index 8fb35a70b1..4e06709db7 100644
--- a/packages/loot-core/src/types/models/category.ts
+++ b/packages/loot-core/src/types/models/category.ts
@@ -5,6 +5,7 @@ export interface CategoryEntity {
name: string;
is_income?: boolean;
group: CategoryGroupEntity['id'];
+ goal_def?: string;
sort_order?: number;
tombstone?: boolean;
hidden?: boolean;
diff --git a/upcoming-release-notes/4815.md b/upcoming-release-notes/4815.md
new file mode 100644
index 0000000000..05dda7f774
--- /dev/null
+++ b/upcoming-release-notes/4815.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [joel-jeremy]
+---
+
+Add upcoming/missed/due schedules indicator on budget table (based on category schedule templates)