Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] POC Budget Bar Graph #3424

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions packages/desktop-client/src/components/budget/BudgetTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export function BudgetTable(props) {
'budget.showHiddenCategories',
);
const [editing, setEditing] = useState(null);
const [showProgress = false, setShowProgress] = useLocalPref(
'budget.showProgress',
);

const onEditMonth = (id, month) => {
setEditing(id ? { id, cell: month } : null);
Expand Down Expand Up @@ -141,14 +144,6 @@ export function BudgetTable(props) {
setCollapsedGroupIdsPref(collapsedIds);
};

const onToggleHiddenCategories = () => {
setShowHiddenCategoriesPef(!showHiddenCategories);
};

const toggleHiddenCategories = () => {
onToggleHiddenCategories();
};

const expandAllCategories = () => {
onCollapse([]);
};
Expand Down Expand Up @@ -202,7 +197,10 @@ export function BudgetTable(props) {
>
<BudgetTotals
MonthComponent={dataComponents.BudgetTotalsComponent}
toggleHiddenCategories={toggleHiddenCategories}
setShowHiddenCategoriesPef={setShowHiddenCategoriesPef}
showHiddenCategories={showHiddenCategories}
setShowProgress={setShowProgress}
showProgress={showProgress}
expandAllCategories={expandAllCategories}
collapseAllCategories={collapseAllCategories}
/>
Expand Down
92 changes: 84 additions & 8 deletions packages/desktop-client/src/components/budget/BudgetTotals.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
import React, { type ComponentProps, memo, useRef, useState } from 'react';
import { useTranslation, Trans } from 'react-i18next';

Check warning on line 2 in packages/desktop-client/src/components/budget/BudgetTotals.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import { useSyncedPref } from '../../hooks/useSyncedPref';

Check warning on line 3 in packages/desktop-client/src/components/budget/BudgetTotals.tsx

View workflow job for this annotation

GitHub Actions / lint

There should be no empty line within import group

import { SvgDotsHorizontalTriple } from '../../icons/v1';
import { theme, styles } from '../../style';
import { Button } from '../common/Button2';
import { Menu } from '../common/Menu';
import { Popover } from '../common/Popover';
import { Text } from '../common/Text';
import { View } from '../common/View';

import { RenderMonths } from './RenderMonths';
import { getScrollbarWidth } from './util';

function Legend({ title, color }: { title: string; color: string }) {
return (
<View
style={{
paddingBottom: 10,
flexDirection: 'row',
alignItems: 'center',
}}
>
<View
style={{
marginRight: 5,
borderRadius: 1000,
width: 14,
height: 14,
backgroundColor: color,
}}
/>
<Text
style={{
whiteSpace: 'nowrap',
flexShrink: 0,
}}
>
{title}
</Text>
</View>
);
}

type BudgetTotalsProps = {
MonthComponent: ComponentProps<typeof RenderMonths>['component'];
toggleHiddenCategories: () => void;
setShowHiddenCategoriesPef: (value: boolean) => void;
showHiddenCategories: boolean;
setShowProgress: (value: boolean) => void;
showProgress: boolean;
carkom marked this conversation as resolved.
Show resolved Hide resolved
expandAllCategories: () => void;
collapseAllCategories: () => void;
};

export const BudgetTotals = memo(function BudgetTotals({
MonthComponent,
toggleHiddenCategories,
setShowHiddenCategoriesPef,
showHiddenCategories,
setShowProgress,
showProgress,
carkom marked this conversation as resolved.
Show resolved Hide resolved
expandAllCategories,
collapseAllCategories,
}: BudgetTotalsProps) {
const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const { t } = useTranslation();
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
Expand Down Expand Up @@ -77,23 +116,60 @@
triggerRef={triggerRef}
isOpen={menuOpen}
onOpenChange={() => setMenuOpen(false)}
style={{ width: 200 }}
style={{ width: 210 }}
>
<Menu
onMenuSelect={type => {
if (type === 'toggle-visibility') {
toggleHiddenCategories();
if (type === 'showHiddenCategories') {
setShowHiddenCategoriesPef(!showHiddenCategories);
} else if (type === 'showProgress') {
setShowProgress(!showProgress);
} else if (type === 'expandAllCategories') {
expandAllCategories();
setMenuOpen(false);
} else if (type === 'collapseAllCategories') {
collapseAllCategories();
setMenuOpen(false);
}
setMenuOpen(false);
}}
items={[
{
name: 'toggle-visibility',
text: t('Toggle hidden categories'),
name: 'showHiddenCategories',
text: t('Show hidden categories'),
toggle: showHiddenCategories,
},
{
name: 'showProgress',
text: t('Show progress bars'),
toggle: showProgress,
customTooltip: (
<View
style={{
padding: 10,
paddingBottom: 0,
}}
>

Check warning on line 151 in packages/desktop-client/src/components/budget/BudgetTotals.tsx

View workflow job for this annotation

GitHub Actions / lint

Delete `··`
{budgetType === 'rollover' && (
<>
<Legend
title="Rollover added"
color={theme.reportsLightPurple}
/>
<Legend
title="Rollover spent"
color={theme.reportsLightGreen}
/>
<Legend
title="Rollover overspent"
color={theme.reportsLightRed}
/>
</>
)}
<Legend title="Budgeted" color={theme.reportsPurple} />
<Legend title="Spent" color={theme.reportsGreen} />
<Legend title="Overspent" color={theme.reportsRed} />
</View>
),
},
{
name: 'expandAllCategories',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
type CategoryEntity,
} from 'loot-core/src/types/models';

import { useLocalPref } from '../../hooks/useLocalPref';
import { theme } from '../../style';
import { View } from '../common/View';
import {
Expand Down Expand Up @@ -52,6 +53,7 @@ export function ExpenseCategory({
onDragChange,
onReorder,
}: ExpenseCategoryProps) {
const [showProgress] = useLocalPref('budget.showProgress');
let dragging = dragState && dragState.item === cat;

if (dragState && dragState.item.id === cat.cat_group) {
Expand All @@ -75,6 +77,7 @@ export function ExpenseCategory({
<Row
innerRef={dropRef}
collapsed={true}
height={showProgress && 44}
style={{
backgroundColor: theme.tableBackground,
opacity: cat.hidden || categoryGroup?.hidden ? 0.5 : undefined,
Expand Down
Loading
Loading