Skip to content

A local-first personal finance app

SpendingReport: Fixing some display issues (#3451)

Neil80a7a9873afc
diff --git a/packages/desktop-client/src/components/reports/LegendItem.tsx b/packages/desktop-client/src/components/reports/LegendItem.tsx
new file mode 100644
index 0000000000..8d17d9dfc6
--- /dev/null
+++ b/packages/desktop-client/src/components/reports/LegendItem.tsx
@@ -0,0 +1,45 @@
+import React from 'react';
+
+import { type CSSProperties } from '../../style/types';
+import { Text } from '../common/Text';
+import { View } from '../common/View';
+
+export function LegendItem({
+ color,
+ label,
+ style,
+}: {
+ color: string;
+ label: string;
+ style?: CSSProperties;
+}) {
+ return (
+ <View
+ style={{
+ padding: 10,
+ flexDirection: 'row',
+ alignItems: 'center',
+ ...style,
+ }}
+ >
+ <View
+ style={{
+ marginRight: 5,
+ borderRadius: 1000,
+ width: 14,
+ height: 14,
+ backgroundColor: color,
+ }}
+ />
+ <Text
+ style={{
+ whiteSpace: 'nowrap',
+ textOverflow: 'ellipsis',
+ flexShrink: 0,
+ }}
+ >
+ {label}
+ </Text>
+ </View>
+ );
+}
diff --git a/packages/desktop-client/src/components/reports/ReportLegend.tsx b/packages/desktop-client/src/components/reports/ReportLegend.tsx
index 91ea3f86c9..3e9d473a02 100644
--- a/packages/desktop-client/src/components/reports/ReportLegend.tsx
+++ b/packages/desktop-client/src/components/reports/ReportLegend.tsx
@@ -4,6 +4,7 @@ import { theme, styles } from '../../style';
import { Text } from '../common/Text';
import { View } from '../common/View';
+import { LegendItem } from './LegendItem';
import { ReportOptions } from './ReportOptions';
type ReportLegendProps = {
@@ -39,33 +40,11 @@ export function ReportLegend({ legend, groupBy, interval }: ReportLegendProps) {
{legend &&
legend.map(item => {
return (
- <View
+ <LegendItem
key={item.name}
- style={{
- padding: 10,
- flexDirection: 'row',
- alignItems: 'center',
- }}
- >
- <View
- style={{
- marginRight: 5,
- borderRadius: 1000,
- width: 14,
- height: 14,
- backgroundColor: item.color,
- }}
- />
- <Text
- style={{
- whiteSpace: 'nowrap',
- textOverflow: 'ellipsis',
- flexShrink: 0,
- }}
- >
- {item.name}
- </Text>
- </View>
+ color={item.color}
+ label={item.name}
+ />
);
})}
</View>
diff --git a/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx b/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
index b8c0352914..d648e7ee96 100644
--- a/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/SpendingGraph.tsx
@@ -299,10 +299,10 @@ export function SpendingGraph({
activeDot={false}
animationDuration={0}
dataKey={val => getVal(val, selection)}
- stroke="gray"
+ stroke={theme.reportsGray}
strokeDasharray="10 10"
strokeWidth={3}
- fill="gray"
+ fill={theme.reportsGray}
fillOpacity={0.2}
/>
</AreaChart>
diff --git a/packages/desktop-client/src/components/reports/reports/Spending.tsx b/packages/desktop-client/src/components/reports/reports/Spending.tsx
index 4f5407a4a1..f8d44b93d3 100644
--- a/packages/desktop-client/src/components/reports/reports/Spending.tsx
+++ b/packages/desktop-client/src/components/reports/reports/Spending.tsx
@@ -32,6 +32,7 @@ import { MobileBackButton } from '../../mobile/MobileBackButton';
import { MobilePageHeader, Page, PageHeader } from '../../Page';
import { PrivacyFilter } from '../../PrivacyFilter';
import { SpendingGraph } from '../graphs/SpendingGraph';
+import { LegendItem } from '../LegendItem';
import { LoadingIndicator } from '../LoadingIndicator';
import { ModeButton } from '../ModeButton';
import { calculateSpendingReportTimeRange } from '../reportRanges';
@@ -169,7 +170,12 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
? 27
: monthUtils.getDay(monthUtils.currentDay()) - 1;
- const showCompareTo = Math.abs(data.intervalData[27].compareTo) > 0;
+ const showCompareTo =
+ compareTo === monthUtils.currentMonth() ||
+ Math.abs(data.intervalData[27].compareTo) > 0;
+ const showCompare =
+ compare === monthUtils.currentMonth() ||
+ Math.abs(data.intervalData[27].compare) > 0;
const title = widget?.meta?.name ?? t('Monthly Spending');
@@ -431,6 +437,24 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
flexDirection: 'row',
}}
>
+ <View>
+ <LegendItem
+ color={theme.reportsGreen}
+ label={monthUtils.format(compare, 'MMM, yyyy')}
+ style={{ padding: 0, paddingBottom: 10 }}
+ />
+ <LegendItem
+ color={theme.reportsGray}
+ label={
+ reportMode === 'single-month'
+ ? monthUtils.format(compareTo, 'MMM, yyyy')
+ : reportMode === 'budget'
+ ? 'Budgeted'
+ : 'Average'
+ }
+ style={{ padding: 0, paddingBottom: 10 }}
+ />
+ </View>
<View style={{ flex: 1 }} />
<View
style={{
@@ -439,7 +463,7 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
}}
>
<View>
- {showCompareTo && (
+ {showCompare && (
<AlignedText
style={{ marginBottom: 5, minWidth: 210 }}
left={
@@ -459,12 +483,13 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
}
/>
)}
- {reportMode === 'single-month' && (
+ {reportMode === 'single-month' && showCompareTo && (
<AlignedText
style={{ marginBottom: 5, minWidth: 210 }}
left={
<Block>
- Spent {monthUtils.format(compareTo, 'MMM, yyyy')}:
+ Spent {monthUtils.format(compareTo, 'MMM, yyyy')}
+ {compare === monthUtils.currentMonth() && ' MTD'}:
</Block>
}
right={
@@ -479,24 +504,26 @@ function SpendingInternal({ widget }: SpendingInternalProps) {
/>
)}
</View>
- <AlignedText
- style={{ marginBottom: 5, minWidth: 210 }}
- left={
- <Block>
- Budgeted
- {compare === monthUtils.currentMonth() && ' MTD'}:
- </Block>
- }
- right={
- <Text style={{ fontWeight: 600 }}>
- <PrivacyFilter blurIntensity={5}>
- {amountToCurrency(
- Math.abs(data.intervalData[todayDay].budget),
- )}
- </PrivacyFilter>
- </Text>
- }
- />
+ {Math.abs(data.intervalData[todayDay].budget) > 0 && (
+ <AlignedText
+ style={{ marginBottom: 5, minWidth: 210 }}
+ left={
+ <Block>
+ Budgeted
+ {compare === monthUtils.currentMonth() && ' MTD'}:
+ </Block>
+ }
+ right={
+ <Text style={{ fontWeight: 600 }}>
+ <PrivacyFilter blurIntensity={5}>
+ {amountToCurrency(
+ Math.abs(data.intervalData[todayDay].budget),
+ )}
+ </PrivacyFilter>
+ </Text>
+ }
+ />
+ )}
{showAverage && (
<AlignedText
style={{ marginBottom: 5, minWidth: 210 }}
diff --git a/packages/desktop-client/src/style/themes/dark.ts b/packages/desktop-client/src/style/themes/dark.ts
index 38aa2a88cb..76d3b4b819 100644
--- a/packages/desktop-client/src/style/themes/dark.ts
+++ b/packages/desktop-client/src/style/themes/dark.ts
@@ -191,6 +191,7 @@ export const pillTextSubdued = colorPalette.navy500;
export const reportsRed = colorPalette.red300;
export const reportsBlue = colorPalette.blue400;
export const reportsGreen = colorPalette.green400;
+export const reportsGray = colorPalette.gray400;
export const reportsLabel = pageText;
export const reportsInnerLabel = colorPalette.navy800;
diff --git a/packages/desktop-client/src/style/themes/development.ts b/packages/desktop-client/src/style/themes/development.ts
index b379c2172e..4cd6163878 100644
--- a/packages/desktop-client/src/style/themes/development.ts
+++ b/packages/desktop-client/src/style/themes/development.ts
@@ -190,6 +190,7 @@ export const pillTextSubdued = colorPalette.navy200;
export const reportsRed = colorPalette.red300;
export const reportsBlue = colorPalette.blue400;
export const reportsGreen = colorPalette.green400;
+export const reportsGray = colorPalette.gray400;
export const reportsLabel = colorPalette.navy900;
export const reportsInnerLabel = colorPalette.navy800;
diff --git a/packages/desktop-client/src/style/themes/light.ts b/packages/desktop-client/src/style/themes/light.ts
index ca1b2a6f4a..1781758064 100644
--- a/packages/desktop-client/src/style/themes/light.ts
+++ b/packages/desktop-client/src/style/themes/light.ts
@@ -193,6 +193,7 @@ export const pillTextSubdued = colorPalette.navy200;
export const reportsRed = colorPalette.red300;
export const reportsBlue = colorPalette.blue400;
export const reportsGreen = colorPalette.green400;
+export const reportsGray = colorPalette.gray400;
export const reportsLabel = colorPalette.navy900;
export const reportsInnerLabel = colorPalette.navy800;
diff --git a/packages/desktop-client/src/style/themes/midnight.ts b/packages/desktop-client/src/style/themes/midnight.ts
index f851e7163c..0b4e0bbb88 100644
--- a/packages/desktop-client/src/style/themes/midnight.ts
+++ b/packages/desktop-client/src/style/themes/midnight.ts
@@ -193,6 +193,7 @@ export const pillTextSubdued = colorPalette.gray500;
export const reportsRed = colorPalette.red300;
export const reportsBlue = colorPalette.blue400;
export const reportsGreen = colorPalette.green400;
+export const reportsGray = colorPalette.gray400;
export const reportsLabel = pageText;
export const reportsInnerLabel = colorPalette.navy800;
diff --git a/upcoming-release-notes/3451.md b/upcoming-release-notes/3451.md
new file mode 100644
index 0000000000..9539cc6d7c
--- /dev/null
+++ b/upcoming-release-notes/3451.md
@@ -0,0 +1,6 @@
+---
+category: Enhancements
+authors: [carkom]
+---
+
+Fixing display issues in spending report and adding a legend.