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

Custom Reports optimization #1988

Merged
merged 50 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
465fa51
Range fix and payee fix
carkom Nov 18, 2023
1074e06
bug fixes and UI tweaks
carkom Nov 19, 2023
2a3b3ab
range options, hover UI
carkom Nov 20, 2023
92cbddd
Select - UnSelect All Buttons
carkom Nov 20, 2023
aa0a12e
fix hidden group bug
carkom Nov 20, 2023
0784d2d
YAxis PrivacyFilter
carkom Nov 20, 2023
68c3f96
notes
carkom Nov 20, 2023
71ca78d
more privacyFilter graphs
carkom Nov 20, 2023
3a679f8
Merge branch 'master' into reportBugs
carkom Nov 21, 2023
ae8f247
overflowY fix
carkom Nov 21, 2023
29b1465
Loading Indicator
carkom Nov 21, 2023
888df2c
Merge branch 'master' into reportBugs
carkom Nov 23, 2023
38d008b
Fix Filter button hover
carkom Nov 23, 2023
2e16bb6
data revamp
carkom Nov 24, 2023
97d10f0
review fixes
carkom Nov 24, 2023
6957cab
Merge branch 'master' into reportBugs
carkom Nov 24, 2023
150d681
LoadingIndicator fixes
carkom Nov 24, 2023
7dc35fa
remove a loop
carkom Nov 25, 2023
da39b8b
filterbuttontype
carkom Nov 25, 2023
22f7ebc
Merge remote-tracking branch 'origin/reportBugs' into reportsOptimize
carkom Nov 25, 2023
4f72c5a
lint fixes
carkom Nov 25, 2023
5196136
review fixes
carkom Nov 26, 2023
80d507a
Merge branch 'master' into reportBugs
carkom Nov 26, 2023
5a0fb6e
filtersbutton
carkom Nov 26, 2023
4eadfeb
updates
carkom Nov 26, 2023
e0a7f13
Merge branch 'master' into reportBugs
carkom Nov 26, 2023
a808656
Merge remote-tracking branch 'origin/reportBugs' into reportsOptimize
carkom Nov 27, 2023
e88ba97
Merge branch 'reportsOptimize' of https://github.com/carkom/actual in…
carkom Nov 27, 2023
b5d3710
Split out functions to separate files
carkom Nov 27, 2023
0b256a1
uncategorized optimization
carkom Nov 28, 2023
ba4e253
rename ambiguous variables
carkom Nov 28, 2023
d991007
Merge remote-tracking branch 'upstream/master' into reportsOptimize
carkom Nov 28, 2023
2c92765
notes
carkom Nov 28, 2023
48f8b46
remove indexStack
carkom Nov 28, 2023
3af434b
renaming variables
carkom Nov 28, 2023
7b63338
Improve scrolling of tableGraph
carkom Nov 28, 2023
1688a87
revert renaming variables
carkom Nov 30, 2023
4bf44e9
Merge branch 'master' into reportsOptimize
carkom Nov 30, 2023
1906314
code fixes
carkom Nov 30, 2023
d7fcaa3
lint fixes
carkom Nov 30, 2023
e5644d0
review fixes
carkom Dec 3, 2023
32700e5
Merge branch 'master' into reportsOptimize
carkom Dec 3, 2023
5e11bf2
fix
carkom Dec 3, 2023
6f45763
review fixes
carkom Dec 5, 2023
2d47e98
Merge branch 'master' into reportsOptimize
carkom Dec 5, 2023
ccc13f4
variable name changes
carkom Dec 5, 2023
1efd5e2
Merge remote-tracking branch 'upstream/master' into reportsOptimize
carkom Dec 5, 2023
c844907
const eslint fixes
carkom Dec 5, 2023
ab40197
Merge remote-tracking branch 'upstream/master' into reportsOptimize
carkom Dec 6, 2023
e6dde2a
remove indexStack
carkom Dec 6, 2023
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useRef } from 'react';

import View from '../common/View';

Expand All @@ -15,8 +15,6 @@ import ReportTableList from './ReportTableList';
import ReportTableTotals from './ReportTableTotals';

export function ChooseGraph({
start,
end,
data,
mode,
graphType,
Expand All @@ -27,18 +25,23 @@ export function ChooseGraph({
setScrollWidth,
months,
}) {
function saveScrollWidth(parent, child) {
const width = parent > 0 && child > 0 && parent - child;
const saveScrollWidth = value => {
setScrollWidth(!value ? 0 : value);
};

setScrollWidth(!width ? 0 : width);
}
const headerScrollRef = useRef<HTMLDivElement>(null);
const listScrollRef = useRef<HTMLDivElement>(null);
const totalScrollRef = useRef<HTMLDivElement>(null);

const handleScrollTotals = scroll => {
headerScrollRef.current.scrollLeft = scroll.target.scrollLeft;
listScrollRef.current.scrollLeft = scroll.target.scrollLeft;
};

carkom marked this conversation as resolved.
Show resolved Hide resolved
if (graphType === 'AreaGraph') {
return (
<AreaGraph
style={{ flexGrow: 1 }}
start={start}
end={end}
data={data}
balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}
/>
Expand All @@ -48,8 +51,6 @@ export function ChooseGraph({
return (
<BarGraph
style={{ flexGrow: 1 }}
start={start}
end={end}
data={data}
groupBy={groupBy}
empty={empty}
Expand All @@ -58,21 +59,12 @@ export function ChooseGraph({
);
}
if (graphType === 'BarLineGraph') {
return (
<BarLineGraph
style={{ flexGrow: 1 }}
start={start}
end={end}
graphData={data.graphData}
/>
);
return <BarLineGraph style={{ flexGrow: 1 }} graphData={data.graphData} />;
}
if (graphType === 'DonutGraph') {
return (
<DonutGraph
style={{ flexGrow: 1 }}
start={start}
end={end}
data={data}
groupBy={groupBy}
empty={empty}
Expand All @@ -81,40 +73,25 @@ export function ChooseGraph({
);
}
if (graphType === 'LineGraph') {
return (
<LineGraph
style={{ flexGrow: 1 }}
start={start}
end={end}
graphData={data.graphData}
/>
);
return <LineGraph style={{ flexGrow: 1 }} graphData={data.graphData} />;
}
if (graphType === 'StackedBarGraph') {
return (
<StackedBarGraph
style={{ flexGrow: 1 }}
start={start}
end={end}
data={data}
balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}
/>
);
return <StackedBarGraph style={{ flexGrow: 1 }} data={data} />;
}
if (graphType === 'TableGraph') {
return (
<View
style={{
overflow: 'auto',
}}
>
<View>
<ReportTableHeader
headerScrollRef={headerScrollRef}
interval={mode === 'time' && months}
scrollWidth={scrollWidth}
groupBy={groupBy}
balanceType={balanceType}
/>
<ReportTable saveScrollWidth={saveScrollWidth}>
<ReportTable
saveScrollWidth={saveScrollWidth}
listScrollRef={listScrollRef}
>
<ReportTableList
data={data}
empty={empty}
Expand All @@ -123,15 +100,16 @@ export function ChooseGraph({
mode={mode}
groupBy={groupBy}
/>
<ReportTableTotals
scrollWidth={scrollWidth}
data={data}
mode={mode}
balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}
monthsCount={months.length}
balanceType={balanceType}
/>
</ReportTable>
<ReportTableTotals
totalScrollRef={totalScrollRef}
handleScrollTotals={handleScrollTotals}
scrollWidth={scrollWidth}
data={data}
mode={mode}
balanceTypeOp={ReportOptions.balanceTypeMap.get(balanceType)}
monthsCount={months.length}
/>
</View>
);
}
Expand Down
132 changes: 132 additions & 0 deletions packages/desktop-client/src/components/reports/ReportOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {
type AccountEntity,
type CategoryEntity,
type CategoryGroupEntity,
type PayeeEntity,
} from 'loot-core/src/types/models';

const balanceTypeOptions = [
{ description: 'Expense', format: 'totalDebts' },
{ description: 'Income', format: 'totalAssets' },
Expand Down Expand Up @@ -44,3 +51,128 @@ const intervalOptions = [
{ value: 5, description: 'Yearly', name: 5,
];
*/
export type QueryDataEntity = {
date: string;
category: string;
categoryGroup: string;
account: string;
accountOffBudget: boolean;
payee: string;
transferAccount: string;
amount: number;
};

carkom marked this conversation as resolved.
Show resolved Hide resolved
export type UncategorizedEntity = CategoryEntity & {
/*
When looking at uncategorized and hidden transactions we
need a way to group them. To do this we give them a unique
uncategorized_id. We also need a way to filter the
transctions from our query. For this we use the 3 variables
below.
*/
uncategorized_id: string;
is_off_budget: boolean;
is_transfer: boolean;
has_category: boolean;
};

const uncategorizedCategory: UncategorizedEntity = {
name: 'Uncategorized',
id: null,
uncategorized_id: '1',
hidden: false,
is_off_budget: false,
is_transfer: false,
has_category: false,
};
const transferCategory: UncategorizedEntity = {
name: 'Transfers',
id: null,
uncategorized_id: '2',
hidden: false,
is_off_budget: false,
is_transfer: true,
has_category: false,
};
const offBudgetCategory: UncategorizedEntity = {
name: 'Off Budget',
id: null,
uncategorized_id: '3',
hidden: false,
is_off_budget: true,
is_transfer: false,
has_category: true,
};

type UncategorizedGroupEntity = CategoryGroupEntity & {
categories?: UncategorizedEntity[];
};

const uncategouncatGrouprizedGroup: UncategorizedGroupEntity = {
name: 'Uncategorized & Off Budget',
id: null,
hidden: false,
categories: [uncategorizedCategory, transferCategory, offBudgetCategory],
};

export const categoryLists = (
showOffBudgetHidden: boolean,
showUncategorized: boolean,
categories: { list: CategoryEntity[]; grouped: CategoryGroupEntity[] },
) => {
const categoryList = showUncategorized
? [
...categories.list,
uncategorizedCategory,
transferCategory,
offBudgetCategory,
]
: categories.list;
const categoryGroup = showUncategorized
? [
...categories.grouped.filter(f => showOffBudgetHidden || !f.hidden),
uncategouncatGrouprizedGroup,
]
: categories.grouped;
return [categoryList, categoryGroup] as const;
};

export const groupBySelections = (
groupBy: string,
categoryList: CategoryEntity[],
categoryGroup: CategoryGroupEntity[],
payees: PayeeEntity[],
accounts: AccountEntity[],
) => {
let groupByList;
let groupByLabel;
switch (groupBy) {
case 'Category':
groupByList = categoryList;
groupByLabel = 'category';
break;
case 'Group':
groupByList = categoryGroup;
groupByLabel = 'categoryGroup';
break;
case 'Payee':
groupByList = payees;
groupByLabel = 'payee';
break;
case 'Account':
groupByList = accounts;
groupByLabel = 'account';
break;
case 'Month':
groupByList = categoryList;
groupByLabel = 'category';
break;
case 'Year':
groupByList = categoryList;
groupByLabel = 'category';
break;
default:
carkom marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Error loading data into the spreadsheet.');
}
return [groupByList, groupByLabel];
};
31 changes: 22 additions & 9 deletions packages/desktop-client/src/components/reports/ReportTable.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
import React, { useLayoutEffect, useRef } from 'react';
import React, { useLayoutEffect, useRef, type ReactNode } from 'react';
import { type RefProp } from 'react-spring';

import { type CSSProperties } from '../../style';
import View from '../common/View';

export default function ReportTable({ saveScrollWidth, style, children }) {
const contentRef = useRef<HTMLDivElement>();
type ReportTableProps = {
saveScrollWidth?: (value: number) => void;
listScrollRef?: RefProp<HTMLDivElement>;
style?: CSSProperties;
children?: ReactNode;
};

export default function ReportTable({
saveScrollWidth,
listScrollRef,
style,
children,
}: ReportTableProps) {
const contentRef = useRef<HTMLDivElement>(null);

useLayoutEffect(() => {
if (contentRef.current && saveScrollWidth) {
saveScrollWidth(
contentRef.current.offsetParent
? contentRef.current.parentElement.offsetWidth
: 0,
contentRef.current ? contentRef.current.offsetWidth : 0,
);
saveScrollWidth(contentRef.current ? contentRef.current.offsetWidth : 0);
}
});

return (
<View
innerRef={listScrollRef}
style={{
overflowY: 'auto',
scrollbarWidth: 'none',
'::-webkit-scrollbar': { display: 'none' },
flex: 1,
outline: 'none',
'& .animated .animated-row': { transition: '.25s transform' },
Expand Down
Loading