A local-first personal finance app
Custom Reports typescript updates and small functional changes (#2046)
Neil4ada92071eb5
diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsxindex ad71b87a1e..0c8825046c 100644--- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx+++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx@@ -26,7 +26,8 @@ type ChooseGraphProps = {setScrollWidth: (value: number) => void;months: Month[];};-export function ChooseGraph({++function ChooseGraph({data,mode,graphType,@@ -37,6 +38,8 @@ export function ChooseGraph({setScrollWidth,months,}: ChooseGraphProps) {+ const balanceTypeOp = ReportOptions.balanceTypeMap.get(balanceType);+const saveScrollWidth = value => {setScrollWidth(!value ? 0 : value);};@@ -55,7 +58,7 @@ export function ChooseGraph({<AreaGraphstyle={{ flexGrow: 1 }}data={data}- balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}+ balanceTypeOp={balanceTypeOp}/>);}@@ -65,7 +68,7 @@ export function ChooseGraph({style={{ flexGrow: 1 }}data={data}groupBy={groupBy}- balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}+ balanceTypeOp={balanceTypeOp}/>);}@@ -78,7 +81,7 @@ export function ChooseGraph({style={{ flexGrow: 1 }}data={data}groupBy={groupBy}- balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}+ balanceTypeOp={balanceTypeOp}/>);}@@ -106,7 +109,7 @@ export function ChooseGraph({data={data}empty={showEmpty}monthsCount={months.length}- balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}+ balanceTypeOp={balanceTypeOp}mode={mode}groupBy={groupBy}/>@@ -117,10 +120,12 @@ export function ChooseGraph({scrollWidth={scrollWidth}data={data}mode={mode}- balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}+ balanceTypeOp={balanceTypeOp}monthsCount={months.length}/></View>);}}++export default ChooseGraph;diff --git a/packages/desktop-client/src/components/reports/ModeButton.tsx b/packages/desktop-client/src/components/reports/ModeButton.tsxnew file mode 100644index 0000000000..e0f216d84f--- /dev/null+++ b/packages/desktop-client/src/components/reports/ModeButton.tsx@@ -0,0 +1,39 @@+import React, { type MouseEventHandler, type ReactNode } from 'react';++import { type CSSProperties, theme } from '../../style';+import Button from '../common/Button';++type ModeButtonProps = {+ selected: boolean;+ children: ReactNode;+ style: CSSProperties;+ onSelect: MouseEventHandler<HTMLButtonElement>;+};++function ModeButton({ selected, children, style, onSelect }: ModeButtonProps) {+ return (+ <Button+ type="bare"+ style={{+ padding: '5px 10px',+ backgroundColor: theme.menuBackground,+ marginRight: 5,+ fontSize: 'inherit',+ ...(selected && {+ backgroundColor: theme.buttonPrimaryBackground,+ color: theme.buttonPrimaryText,+ ':hover': {+ backgroundColor: theme.buttonPrimaryBackgroundHover,+ color: theme.buttonPrimaryTextHover,+ },+ }),+ ...style,+ }}+ onClick={onSelect}+ >+ {children}+ </Button>+ );+}++export default ModeButton;diff --git a/packages/desktop-client/src/components/reports/ReportLegend.tsx b/packages/desktop-client/src/components/reports/ReportLegend.tsxnew file mode 100644index 0000000000..5f17f119de--- /dev/null+++ b/packages/desktop-client/src/components/reports/ReportLegend.tsx@@ -0,0 +1,70 @@+import React from 'react';++import { theme, styles } from '../../style';+import Text from '../common/Text';+import View from '../common/View';++type ReportLegendProps = {+ legend: Array<{ name: string; color: string }>;+ groupBy: string;+};++function ReportLegend({ legend, groupBy }: ReportLegendProps) {+ return (+ <View+ style={{+ backgroundColor: theme.pageBackground,+ alignItems: 'center',+ flex: 1,+ overflowY: 'auto',+ }}+ >+ <Text+ style={{+ ...styles.largeText,+ alignItems: 'center',+ marginBottom: 2,+ fontWeight: 400,+ paddingTop: 10,+ }}+ >+ {groupBy}+ </Text>+ <View>+ {legend.map(item => {+ return (+ <View+ 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>+ );+ })}+ </View>+ </View>+ );+}++export default ReportLegend;diff --git a/packages/desktop-client/src/components/reports/ReportSidebar.js b/packages/desktop-client/src/components/reports/ReportSidebar.jsindex c95c79ad59..2c182b1abb 100644--- a/packages/desktop-client/src/components/reports/ReportSidebar.js+++ b/packages/desktop-client/src/components/reports/ReportSidebar.js@@ -3,7 +3,6 @@ import React from 'react';import * as monthUtils from 'loot-core/src/shared/months';import { theme } from '../../style';-import Button from '../common/Button';import Select from '../common/Select';import Text from '../common/Text';import View from '../common/View';@@ -17,34 +16,9 @@ import {getFullRange,validateRange,} from './Header';+import ModeButton from './ModeButton';import { ReportOptions } from './ReportOptions';-function ModeButton({ selected, children, style, onSelect }) {- return (- <Button- type="bare"- style={{- padding: '5px 10px',- backgroundColor: theme.menuBackground,- marginRight: 5,- fontSize: 'inherit',- ...(selected && {- backgroundColor: theme.buttonPrimaryBackground,- color: theme.buttonPrimaryText,- ':hover': {- backgroundColor: theme.buttonPrimaryBackgroundHover,- color: theme.buttonPrimaryTextHover,- },- }),- ...style,- }}- onClick={onSelect}- >- {children}- </Button>- );-}-export function ReportSidebar({startDate,endDate,diff --git a/packages/desktop-client/src/components/reports/ReportSummary.js b/packages/desktop-client/src/components/reports/ReportSummary.tsxsimilarity index 53%rename from packages/desktop-client/src/components/reports/ReportSummary.jsrename to packages/desktop-client/src/components/reports/ReportSummary.tsxindex 892bab6f79..2a32dfc747 100644--- a/packages/desktop-client/src/components/reports/ReportSummary.js+++ b/packages/desktop-client/src/components/reports/ReportSummary.tsx@@ -12,13 +12,23 @@ import Text from '../common/Text';import View from '../common/View';import PrivacyFilter from '../PrivacyFilter';-export function ReportSummary({+import { type DataEntity } from './entities';++type ReportSummaryProps = {+ startDate: string;+ endDate: string;+ data: DataEntity;+ balanceTypeOp: string;+ monthsCount: number;+};++function ReportSummary({startDate,endDate,data,balanceTypeOp,monthsCount,-}) {+}: ReportSummaryProps) {const net =Math.abs(data.totalDebts) > Math.abs(data.totalAssets)? 'PAYMENT'@@ -40,14 +50,12 @@ export function ReportSummary({}}><Text- style={[- styles.largeText,- {- alignItems: 'center',- marginBottom: 2,- fontWeight: 600,- },- ]}+ style={{+ ...styles.largeText,+ alignItems: 'center',+ marginBottom: 2,+ fontWeight: 600,+ }}>{monthUtils.format(startDate, 'MMM yyyy')} -{' '}{monthUtils.format(endDate, 'MMM yyyy')}@@ -63,14 +71,12 @@ export function ReportSummary({}}><Text- style={[- styles.mediumText,- {- alignItems: 'center',- marginBottom: 2,- fontWeight: 400,- },- ]}+ style={{+ ...styles.mediumText,+ alignItems: 'center',+ marginBottom: 2,+ fontWeight: 400,+ }}>{balanceTypeOp === 'totalDebts'? 'TOTAL SPENDING'@@ -79,14 +85,12 @@ export function ReportSummary({: 'NET ' + net}</Text><Text- style={[- styles.veryLargeText,- {- alignItems: 'center',- marginBottom: 2,- fontWeight: 800,- },- ]}+ style={{+ ...styles.veryLargeText,+ alignItems: 'center',+ marginBottom: 2,+ fontWeight: 800,+ }}><PrivacyFilter blurIntensity={7}>{amountToCurrency(data[balanceTypeOp])}@@ -104,14 +108,12 @@ export function ReportSummary({}}><Text- style={[- styles.mediumText,- {- alignItems: 'center',- marginBottom: 2,- fontWeight: 400,- },- ]}+ style={{+ ...styles.mediumText,+ alignItems: 'center',+ marginBottom: 2,+ fontWeight: 400,+ }}>{balanceTypeOp === 'totalDebts'? 'AVERAGE SPENDING'@@ -120,14 +122,12 @@ export function ReportSummary({: 'AVERAGE NET'}</Text><Text- style={[- styles.veryLargeText,- {- alignItems: 'center',- marginBottom: 2,- fontWeight: 800,- },- ]}+ style={{+ ...styles.veryLargeText,+ alignItems: 'center',+ marginBottom: 2,+ fontWeight: 800,+ }}><PrivacyFilter blurIntensity={7}>{integerToCurrency(Math.round(average))}@@ -139,62 +139,4 @@ export function ReportSummary({);}-export function ReportLegend({ data, legend, groupBy }) {- return (- <View- style={{- backgroundColor: theme.pageBackground,- alignItems: 'center',- flex: 1,- overflowY: 'auto',- }}- >- <Text- style={[- styles.largeText,- {- alignItems: 'center',- marginBottom: 2,- fontWeight: 400,- paddingTop: 10,- },- ]}- >- {groupBy}- </Text>- <View>- {legend.map(item => {- return (- <View- 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>- );- })}- </View>- </View>- );-}+export default ReportSummary;diff --git a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsxindex f46ecfda65..ca7c4d0426 100644--- a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx+++ b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx@@ -132,7 +132,7 @@ type BarGraphProps = {style?: CSSProperties;data: DataEntity;groupBy: string;- balanceTypeOp;+ balanceTypeOp: string;compact?: boolean;};diff --git a/packages/desktop-client/src/components/reports/reports/CustomReport.js b/packages/desktop-client/src/components/reports/reports/CustomReport.jsindex 55347a8e54..12b7f07052 100644--- a/packages/desktop-client/src/components/reports/reports/CustomReport.js+++ b/packages/desktop-client/src/components/reports/reports/CustomReport.js@@ -17,12 +17,13 @@ import Text from '../../common/Text';import View from '../../common/View';import { AppliedFilters } from '../../filters/FiltersMenu';import PrivacyFilter from '../../PrivacyFilter';-import { ChooseGraph } from '../ChooseGraph';+import ChooseGraph from '../ChooseGraph';import Header from '../Header';import LoadingIndicator from '../LoadingIndicator';+import ReportLegend from '../ReportLegend';import { ReportOptions } from '../ReportOptions';import { ReportSidebar } from '../ReportSidebar';-import { ReportLegend, ReportSummary } from '../ReportSummary';+import ReportSummary from '../ReportSummary';import { ReportTopbar } from '../ReportTopbar';import defaultSpreadsheet from '../spreadsheets/default-spreadsheet';import groupedSpreadsheet from '../spreadsheets/grouped-spreadsheet';@@ -111,7 +112,7 @@ export default function CustomReport() {endDate,categories,selectedCategories,- filters,+ conditions: filters,conditionsOp,showEmpty,showOffBudgetHidden,@@ -136,7 +137,7 @@ export default function CustomReport() {endDate,categories,selectedCategories,- filters,+ conditions: filters,conditionsOp,showEmpty,showOffBudgetHidden,@@ -308,8 +309,6 @@ export default function CustomReport() {{dataCheck ? (<ChooseGraph- startDate={startDate}- endDate={endDate}data={data}mode={mode}graphType={graphType}@@ -345,11 +344,7 @@ export default function CustomReport() {/>)}{viewLegend && (- <ReportLegend- data={data}- legend={legend}- groupBy={groupBy}- />+ <ReportLegend legend={legend} groupBy={groupBy} />)}</View>)}diff --git a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsxindex 20ae05ef9c..5d874cb821 100644--- a/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx+++ b/packages/desktop-client/src/components/reports/spreadsheets/cash-flow-spreadsheet.tsx@@ -60,7 +60,7 @@ export function cashFlowByDate(function makeQuery(where) {const query = q('transactions').filter({- [conditionsOpKey]: [...filters],+ [conditionsOpKey]: filters,}).filter({$and: [diff --git a/packages/desktop-client/src/components/reports/spreadsheets/makeQuery.ts b/packages/desktop-client/src/components/reports/spreadsheets/makeQuery.tsindex 2e61c3eb92..6d6ee2ca34 100644--- a/packages/desktop-client/src/components/reports/spreadsheets/makeQuery.ts+++ b/packages/desktop-client/src/components/reports/spreadsheets/makeQuery.ts@@ -49,7 +49,7 @@ function makeQuery()//Apply filters and split by "Group By".filter({- [conditionsOpKey]: [...filters],+ [conditionsOpKey]: filters,})//Apply month range filters.filter({diff --git a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.tsx b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.tsxindex 4bc90d0412..328f8354f0 100644--- a/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.tsx+++ b/packages/desktop-client/src/components/reports/spreadsheets/net-worth-spreadsheet.tsx@@ -44,7 +44,7 @@ export default function createSpreadsheet(runQuery(q('transactions').filter({- [conditionsOpKey]: [...filters],+ [conditionsOpKey]: filters,}).filter({account: acct.id,diff --git a/upcoming-release-notes/2046.md b/upcoming-release-notes/2046.mdnew file mode 100644index 0000000000..8ac334a1ee--- /dev/null+++ b/upcoming-release-notes/2046.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [carkom]+---++Adding typescript to custom report files and small functional changes.\ No newline at end of file