Skip to content
Snippets Groups Projects
Unverified Commit d6f610a3 authored by Matiss Janis Aboltins's avatar Matiss Janis Aboltins Committed by GitHub
Browse files

:sparkles: added 'show/hide balance' button to cash flow report (#2322)

parent 8a8113a6
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -76,6 +76,7 @@ export function Header({ ...@@ -76,6 +76,7 @@ export function Header({
onDeleteFilter, onDeleteFilter,
onCondOpChange, onCondOpChange,
headerPrefixItems, headerPrefixItems,
children,
}) { }) {
const location = useLocation(); const location = useLocation();
const path = location.pathname; const path = location.pathname;
...@@ -167,7 +168,8 @@ export function Header({ ...@@ -167,7 +168,8 @@ export function Header({
> >
All Time All Time
</Button> </Button>
<View style={{ flex: 1 }} />
{children || <View style={{ flex: 1 }} />}
</View> </View>
)} )}
{filters && filters.length > 0 && ( {filters && filters.length > 0 && (
......
...@@ -89,8 +89,13 @@ type CashFlowGraphProps = { ...@@ -89,8 +89,13 @@ type CashFlowGraphProps = {
transfers: { x: Date; y: number }[]; transfers: { x: Date; y: number }[];
}; };
isConcise: boolean; isConcise: boolean;
showBalance?: boolean;
}; };
export function CashFlowGraph({ graphData, isConcise }: CashFlowGraphProps) { export function CashFlowGraph({
graphData,
isConcise,
showBalance = true,
}: CashFlowGraphProps) {
const privacyMode = usePrivacyMode(); const privacyMode = usePrivacyMode();
const [yAxisIsHovered, setYAxisIsHovered] = useState(false); const [yAxisIsHovered, setYAxisIsHovered] = useState(false);
...@@ -154,6 +159,7 @@ export function CashFlowGraph({ graphData, isConcise }: CashFlowGraphProps) { ...@@ -154,6 +159,7 @@ export function CashFlowGraph({ graphData, isConcise }: CashFlowGraphProps) {
type="monotone" type="monotone"
dataKey="balance" dataKey="balance"
dot={false} dot={false}
hide={!showBalance}
stroke={theme.pageTextLight} stroke={theme.pageTextLight}
strokeWidth={2} strokeWidth={2}
animationDuration={ANIMATION_DURATION} animationDuration={ANIMATION_DURATION}
......
// @ts-strict-ignore
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import * as d from 'date-fns'; import * as d from 'date-fns';
...@@ -6,11 +5,13 @@ import * as d from 'date-fns'; ...@@ -6,11 +5,13 @@ import * as d from 'date-fns';
import { send } from 'loot-core/src/platform/client/fetch'; import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months'; import * as monthUtils from 'loot-core/src/shared/months';
import { integerToCurrency } from 'loot-core/src/shared/util'; import { integerToCurrency } from 'loot-core/src/shared/util';
import { type RuleConditionEntity } from 'loot-core/types/models';
import { useFilters } from '../../../hooks/useFilters'; import { useFilters } from '../../../hooks/useFilters';
import { theme, styles } from '../../../style'; import { theme, styles } from '../../../style';
import { AlignedText } from '../../common/AlignedText'; import { AlignedText } from '../../common/AlignedText';
import { Block } from '../../common/Block'; import { Block } from '../../common/Block';
import { Button } from '../../common/Button';
import { Paragraph } from '../../common/Paragraph'; import { Paragraph } from '../../common/Paragraph';
import { Text } from '../../common/Text'; import { Text } from '../../common/Text';
import { View } from '../../common/View'; import { View } from '../../common/View';
...@@ -21,7 +22,7 @@ import { Header } from '../Header'; ...@@ -21,7 +22,7 @@ import { Header } from '../Header';
import { cashFlowByDate } from '../spreadsheets/cash-flow-spreadsheet'; import { cashFlowByDate } from '../spreadsheets/cash-flow-spreadsheet';
import { useReport } from '../useReport'; import { useReport } from '../useReport';
export function CashFlow(): JSX.Element { export function CashFlow() {
const { const {
filters, filters,
conditionsOp, conditionsOp,
...@@ -29,13 +30,17 @@ export function CashFlow(): JSX.Element { ...@@ -29,13 +30,17 @@ export function CashFlow(): JSX.Element {
onDelete: onDeleteFilter, onDelete: onDeleteFilter,
onUpdate: onUpdateFilter, onUpdate: onUpdateFilter,
onCondOpChange, onCondOpChange,
} = useFilters(); } = useFilters<RuleConditionEntity>();
const [allMonths, setAllMonths] = useState(null); const [allMonths, setAllMonths] = useState<null | Array<{
name: string;
pretty: string;
}>>(null);
const [start, setStart] = useState( const [start, setStart] = useState(
monthUtils.subMonths(monthUtils.currentMonth(), 5), monthUtils.subMonths(monthUtils.currentMonth(), 5),
); );
const [end, setEnd] = useState(monthUtils.currentDay()); const [end, setEnd] = useState(monthUtils.currentDay());
const [showBalance, setShowBalance] = useState(true);
const [isConcise, setIsConcise] = useState(() => { const [isConcise, setIsConcise] = useState(() => {
const numDays = d.differenceInCalendarDays( const numDays = d.differenceInCalendarDays(
...@@ -71,7 +76,7 @@ export function CashFlow(): JSX.Element { ...@@ -71,7 +76,7 @@ export function CashFlow(): JSX.Element {
run(); run();
}, []); }, []);
function onChangeDates(start, end) { function onChangeDates(start: string, end: string) {
const numDays = d.differenceInCalendarDays( const numDays = d.differenceInCalendarDays(
d.parseISO(end), d.parseISO(end),
d.parseISO(start), d.parseISO(start),
...@@ -110,7 +115,19 @@ export function CashFlow(): JSX.Element { ...@@ -110,7 +115,19 @@ export function CashFlow(): JSX.Element {
conditionsOp={conditionsOp} conditionsOp={conditionsOp}
onCondOpChange={onCondOpChange} onCondOpChange={onCondOpChange}
headerPrefixItems={undefined} headerPrefixItems={undefined}
/> >
<View
style={{
flex: 1,
flexDirection: 'row',
justifyContent: 'flex-end',
}}
>
<Button onClick={() => setShowBalance(state => !state)}>
{showBalance ? 'Hide balance' : 'Show balance'}
</Button>
</View>
</Header>
<View <View
style={{ style={{
backgroundColor: theme.tableBackground, backgroundColor: theme.tableBackground,
...@@ -168,7 +185,11 @@ export function CashFlow(): JSX.Element { ...@@ -168,7 +185,11 @@ export function CashFlow(): JSX.Element {
</Text> </Text>
</View> </View>
<CashFlowGraph graphData={graphData} isConcise={isConcise} /> <CashFlowGraph
graphData={graphData}
isConcise={isConcise}
showBalance={showBalance}
/>
<View style={{ marginTop: 30 }}> <View style={{ marginTop: 30 }}>
<Paragraph> <Paragraph>
......
...@@ -7,6 +7,7 @@ import { send } from 'loot-core/src/platform/client/fetch'; ...@@ -7,6 +7,7 @@ import { send } from 'loot-core/src/platform/client/fetch';
import * as monthUtils from 'loot-core/src/shared/months'; import * as monthUtils from 'loot-core/src/shared/months';
import { q } from 'loot-core/src/shared/query'; import { q } from 'loot-core/src/shared/query';
import { integerToCurrency, integerToAmount } from 'loot-core/src/shared/util'; import { integerToCurrency, integerToAmount } from 'loot-core/src/shared/util';
import { type RuleConditionEntity } from 'loot-core/types/models';
import { AlignedText } from '../../common/AlignedText'; import { AlignedText } from '../../common/AlignedText';
import { runAll, indexCashFlow } from '../util'; import { runAll, indexCashFlow } from '../util';
...@@ -46,11 +47,11 @@ export function simpleCashFlow(start, end) { ...@@ -46,11 +47,11 @@ export function simpleCashFlow(start, end) {
} }
export function cashFlowByDate( export function cashFlowByDate(
start, start: string,
end, end: string,
isConcise, isConcise: boolean,
conditions = [], conditions: RuleConditionEntity[] = [],
conditionsOp, conditionsOp: 'and' | 'or',
) { ) {
return async (spreadsheet, setData) => { return async (spreadsheet, setData) => {
const { filters } = await send('make-filters-from-conditions', { const { filters } = await send('make-filters-from-conditions', {
......
...@@ -3,7 +3,7 @@ import { useCallback, useMemo, useState } from 'react'; ...@@ -3,7 +3,7 @@ import { useCallback, useMemo, useState } from 'react';
export function useFilters<T>(initialFilters: T[] = []) { export function useFilters<T>(initialFilters: T[] = []) {
const [filters, setFilters] = useState<T[]>(initialFilters); const [filters, setFilters] = useState<T[]>(initialFilters);
const [conditionsOp, setConditionsOp] = useState('and'); const [conditionsOp, setConditionsOp] = useState<'and' | 'or'>('and');
const [saved, setSaved] = useState<T[]>(null); const [saved, setSaved] = useState<T[]>(null);
const onApply = useCallback( const onApply = useCallback(
......
---
category: Enhancements
authors: [MatissJanis]
---
Added `show/hide balance` button to the cash flow report
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment