Skip to content

Commit

Permalink
Add Category Selector
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Oct 28, 2023
1 parent 47058b1 commit 80d08c6
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
29 changes: 29 additions & 0 deletions packages/desktop-client/src/components/reports/Custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { FilterButton, AppliedFilters } from '../filters/FiltersMenu';
import { Checkbox } from '../forms';
import PrivacyFilter from '../PrivacyFilter';

import CategorySelector from './CategorySelector';
import AreaGraph from './graphs/AreaGraph';
import BarGraph from './graphs/BarGraph';
import BarLineGraph from './graphs/BarLineGraph';
Expand Down Expand Up @@ -117,6 +118,7 @@ export default function Custom() {
{ value: 3, description: 'All', format: 'totalTotals' },
];

const [selectedCategories, setSelectedCategories] = useState(null);
const [allMonths, setAllMonths] = useState(null);
const [start, setStart] = useState(
monthUtils.subMonths(monthUtils.currentMonth(), 5),
Expand All @@ -143,6 +145,7 @@ export default function Custom() {
split,
typeOptions.find(opt => opt.value === type).format,
categories,
selectedCategories,
payees,
accounts,
filters,
Expand All @@ -155,6 +158,7 @@ export default function Custom() {
split,
type,
categories,
selectedCategories,
payees,
accounts,
filters,
Expand All @@ -163,6 +167,12 @@ export default function Custom() {
]);
const data = useReport('default', getGraphData);

useEffect(() => {
if (selectedCategories === null && categories.list.length !== 0) {
setSelectedCategories(categories.list);
}
}, [categories, selectedCategories]);

useEffect(() => {
async function run() {
const trans = await send('get-earliest-transaction');
Expand Down Expand Up @@ -666,6 +676,25 @@ export default function Custom() {
options={allMonths.map(({ name, pretty }) => [name, pretty])}
/>
</View>
<View
style={{
height: 1,
backgroundColor: theme.altPillBorder,
marginTop: 10,
flexShrink: 0,
}}
/>
<View
style={{
marginTop: 10,
}}
>
<CategorySelector
categoryGroups={categories.grouped}
selectedCategories={selectedCategories}
setSelectedCategories={setSelectedCategories}
/>
</View>
</View>
<View
style={{
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/reports/Overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ function CustomReportsCard() {
const split = 1;

const getGraphData = useMemo(() => {
return defaultSpreadsheet(start, end, split, categories);
return defaultSpreadsheet(start, end, split, 'totalDebts', categories);
}, [start, end, categories]);
const data = useReport('default', getGraphData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,22 @@ export default function createSpreadsheet(
split,
typeItem,
categories,
selectedCategories,
payees,
accounts,
conditions = [],
conditionsOp,
hidden,
) {
let categoryFilter = (categories.list || []).filter(
category =>
!category.hidden &&
selectedCategories &&
selectedCategories.some(
selectedCategory => selectedCategory.id === category.id,
),
);

let splitItem;
let splitList;
let splitLabel;
Expand Down Expand Up @@ -87,6 +97,13 @@ export default function createSpreadsheet(
],
},
)
.filter(
selectedCategories && {
$or: categoryFilter.map(category => ({
category: category.id,
})),
},
)
.filter({
[splitLabel]: splt.id,
$and: [
Expand Down Expand Up @@ -115,6 +132,13 @@ export default function createSpreadsheet(
],
},
)
.filter(
selectedCategories && {
$or: categoryFilter.map(category => ({
category: category.id,
})),
},
)
.filter({
[splitLabel]: splt.id,
$and: [
Expand Down

0 comments on commit 80d08c6

Please sign in to comment.