Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Jan 20, 2024
1 parent 71b987d commit 4f60551
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
const startDate = monthUtils.subMonths(monthUtils.currentMonth(), 5);
const endDate = monthUtils.currentMonth();

export const defaultState: CustomReportEntity = {
export const defaultReport: CustomReportEntity = {
id: undefined,
mode: 'total',
groupBy: 'Category',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { View } from '../common/View';
import { FilterButton } from '../filters/FiltersMenu';

import { GraphButton } from './GraphButton';
import { SaveReport, SaveReportMenuButton } from './SaveReport';
import { SaveReport } from './SaveReport';

export function ReportTopbar({
customReportItems,
Expand All @@ -30,6 +30,8 @@ export function ReportTopbar({
viewLabels,
onApplyFilter,
onChangeViews,
onReportChange,
onResetReports,
}) {
return (
<View
Expand Down
81 changes: 40 additions & 41 deletions packages/desktop-client/src/components/reports/SaveReportMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React from 'react';

import { type CustomReportEntity } from 'loot-core/src/types/models';
Expand Down Expand Up @@ -38,46 +37,46 @@ export function SaveReportMenu({
},
]
: savedStatus === 'saved'
? [
{ name: 'rename-report', text: 'Rename', disabled: true },
{ name: 'delete-report', text: 'Delete', disabled: true },
Menu.line,
{
name: 'save-report',
text: 'Save new report',
disabled: true,
},
{
name: 'reset-report',
text: 'Reset to default',
disabled: true,
},
]
: [
{ name: 'rename-report', text: 'Rename', disabled: true },
{
name: 'update-report',
text: 'Update report',
disabled: true,
},
{
name: 'reload-report',
text: 'Revert changes',
disabled: true,
},
{ name: 'delete-report', text: 'Delete', disabled: true },
Menu.line,
{
name: 'save-report',
text: 'Save new report',
disabled: true,
},
{
name: 'reset-report',
text: 'Reset to default',
disabled: true,
},
]
? [
{ name: 'rename-report', text: 'Rename', disabled: true },
{ name: 'delete-report', text: 'Delete', disabled: true },
Menu.line,
{
name: 'save-report',
text: 'Save new report',
disabled: true,
},
{
name: 'reset-report',
text: 'Reset to default',
disabled: true,
},
]
: [
{ name: 'rename-report', text: 'Rename', disabled: true },
{
name: 'update-report',
text: 'Update report',
disabled: true,
},
{
name: 'reload-report',
text: 'Revert changes',
disabled: true,
},
{ name: 'delete-report', text: 'Delete', disabled: true },
Menu.line,
{
name: 'save-report',
text: 'Save new report',
disabled: true,
},
{
name: 'reset-report',
text: 'Reset to default',
disabled: true,
},
]
}
/>
</MenuTooltip>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { useEffect } from 'react';

import { theme } from '../../style';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ import { ChooseGraph } from '../ChooseGraph';
import { Header } from '../Header';
import { LoadingIndicator } from '../LoadingIndicator';
import { ReportLegend } from '../ReportLegend';
import { ReportOptions, defaultState } from '../ReportOptions';
import { ReportOptions, defaultReport } from '../ReportOptions';
import { ReportSidebar } from '../ReportSidebar';
import { ReportSummary } from '../ReportSummary';
import { ReportTopbar } from '../ReportTopbar';
import { createCustomSpreadsheet } from '../spreadsheets/custom-spreadsheet';
import { createGroupedSpreadsheet } from '../spreadsheets/grouped-spreadsheet';
import { useReport } from '../useReport';
import { fromDateRepr } from '../util';
import { useLocation } from 'react-router-dom';

export function CustomReport() {
const categories = useCategories();
Expand All @@ -55,7 +54,7 @@ export function CustomReport() {
} = useFilters();

const location = useLocation();
const loadReport = location.state.report ?? defaultState;
const loadReport = location.state.report ?? defaultReport;

const [allMonths, setAllMonths] = useState(null);
const [typeDisabled, setTypeDisabled] = useState(['Net']);
Expand Down Expand Up @@ -83,7 +82,9 @@ export function CustomReport() {
const dateRangeLine = ReportOptions.dateRange.length - 3;

const [report, setReport] = useState(location.state.report ?? []);
const [savedStatus, setSavedStatus] = useState(location.state.report ? 'saved' : 'new');
const [savedStatus, setSavedStatus] = useState(
location.state.report ? 'saved' : 'new',
);
const months = monthUtils.rangeInclusive(startDate, endDate);

useEffect(() => {
Expand Down Expand Up @@ -237,26 +238,27 @@ export function CustomReport() {
};

const onResetReports = () => {
setMode(stateDefault.mode);
setGroupBy(stateDefault.groupBy);
setBalanceType(stateDefault.balanceType);
setShowEmpty(stateDefault.empty);
setShowOffBudgetHidden(stateDefault.hidden);
setShowUncategorized(stateDefault.uncat);
setGraphType(stateDefault.graphType);
setMode(defaultReport.mode);
setGroupBy(defaultReport.groupBy);
setBalanceType(defaultReport.balanceType);
setShowEmpty(defaultReport.empty);
setShowOffBudgetHidden(defaultReport.hidden);
setShowUncategorized(defaultReport.uncat);
setGraphType(defaultReport.graphType);
onApplyFilter(null);
onCondOpChange(stateDefault.conditionsOp);
onCondOpChange(defaultReport.conditionsOp);
setReport([]);
setStartDate(stateDefault.start);
setEndDate(stateDefault.end);
setStartDate(defaultReport.start);
setEndDate(defaultReport.end);
setSavedStatus('new');
};

const onReportChange = (savedReport, type) => {
if (type === 'add-update') { //status = saved
if (type === 'add-update') {
//status = saved
setReport(savedReport);
}

if (type === 'reload') {
setMode(report.mode);
setGroupBy(report.groupBy);
Expand Down

0 comments on commit 4f60551

Please sign in to comment.