Skip to content

Commit

Permalink
fixing functionality plus clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Feb 5, 2024
1 parent aa9d11e commit d469aa4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const startDate = monthUtils.subMonths(monthUtils.currentMonth(), 5);
const endDate = monthUtils.currentMonth();

export const defaultReport: CustomReportEntity = {
id: undefined,
name: undefined,
startDate,
endDate,
isDateStatic: false,
Expand All @@ -24,7 +22,6 @@ export const defaultReport: CustomReportEntity = {
showOffBudget: false,
showHiddenCategories: false,
showUncategorized: false,
selectedCategories: [],
graphType: 'BarGraph',
conditions: [],
conditionsOp: 'and',
Expand Down
40 changes: 19 additions & 21 deletions packages/desktop-client/src/components/reports/ReportSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ export function ReportSidebar({
customReportItems.startDate,
customReportItems.endDate,
);
onReportChange({ type: 'modify' });
}}
>
Static
Expand Down Expand Up @@ -411,7 +410,6 @@ export function ReportSidebar({
customReportItems.endDate,
),
);
onReportChange({ type: 'modify' });
}}
value={customReportItems.startDate}
defaultLabel={monthUtils.format(
Expand Down Expand Up @@ -440,7 +438,6 @@ export function ReportSidebar({
newValue,
),
);
onReportChange({ type: 'modify' });
}}
value={customReportItems.endDate}
options={allMonths.map(({ name, pretty }) => [name, pretty])}
Expand All @@ -457,25 +454,26 @@ export function ReportSidebar({
}}
/>
</View>
{['Category', 'Group'].includes(customReportItems.groupBy) && (
<View
style={{
marginTop: 10,
minHeight: 200,
<View
style={{
marginTop: 10,
minHeight: 200,
}}
>
<CategorySelector
categoryGroups={categories.grouped.filter(f => {
return customReportItems.showHiddenCategories || !f.hidden
? true
: false;
})}
selectedCategories={customReportItems.selectedCategories}
setSelectedCategories={e => {
setSelectedCategories(e);
onReportChange({ type: 'modify' });
}}
>
<CategorySelector
categoryGroups={categories.grouped.filter(f => {
return customReportItems.showHiddenCategories || !f.hidden
? true
: false;
})}
selectedCategories={customReportItems.selectedCategories}
setSelectedCategories={setSelectedCategories}
showHiddenCategories={customReportItems.showHiddenCategories}
/>
</View>
)}
showHiddenCategories={customReportItems.showHiddenCategories}
/>
</View>
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export function ReportTopbar({
<GraphButton
selected={viewLegend}
onSelect={() => {
onReportChange({ type: 'modify' });
onChangeViews('viewLegend');
}}
style={{ marginRight: 15 }}
Expand Down
18 changes: 7 additions & 11 deletions packages/desktop-client/src/components/reports/SaveReport.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export function SaveReport({
const [name, setName] = useState(report.name);
const inputRef = createRef<HTMLInputElement>();

const onAddUpdate = async () => {
const onAddUpdate = async (menuChoice: string) => {
let savedReport: CustomReportEntity;
//save existing states
savedReport = {
...report,
...customReportItems,
};

if (menuItem === 'save-report') {
if (menuChoice === 'save-report') {
setRes('');
//create new flow
/*
Expand All @@ -65,19 +65,15 @@ export function SaveReport({
};
}

if (menuItem === 'rename-report') {
if (menuChoice === 'rename-report') {
//rename
savedReport = {
...report,
...savedReport,
name,
};
}

if (menuItem === 'update-report') {
savedReport = {
...savedReport,
name: report.name,
};
if (menuChoice === 'update-report') {
//send update and rename to DB
/*
res = await sendCatch('report/update', {
Expand All @@ -92,7 +88,7 @@ export function SaveReport({
setNameMenuOpen(false);
onReportChange({
savedReport,
type: menuItem === 'rename-report' ? 'rename' : 'add-update',
type: menuChoice === 'rename-report' ? 'rename' : 'add-update',
});
}
};
Expand All @@ -117,7 +113,7 @@ export function SaveReport({
case 'update-report':
setErr('');
setMenuOpen(false);
onAddUpdate();
onAddUpdate(item);
break;
case 'save-report':
setErr('');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type SaveReportNameProps = {
menuItem: string;
onNameChange: (name: string) => void;
inputRef: RefObject<HTMLInputElement>;
onAddUpdate: () => void;
onAddUpdate: (menuItem: string) => void;
err: string;
};

Expand Down Expand Up @@ -54,7 +54,7 @@ export function SaveReportName({
style={{ marginTop: 18 }}
onClick={e => {
e.preventDefault();
onAddUpdate();
onAddUpdate(menuItem);
}}
>
{menuItem === 'save-report' ? 'Add' : 'Update'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function CustomReport() {
const months = monthUtils.rangeInclusive(startDate, endDate);

useEffect(() => {
if (selectedCategories.length === 0 && categories.list.length !== 0) {
if (selectedCategories === undefined && categories.list.length !== 0) {
setSelectedCategories(categories.list);
}
}, [categories, selectedCategories]);
Expand Down Expand Up @@ -203,8 +203,6 @@ export function CustomReport() {

const data = { ...graphData, groupedData };
const customReportItems = {
id: undefined,
name: undefined,
startDate,
endDate,
isDateStatic,
Expand Down Expand Up @@ -232,7 +230,7 @@ export function CustomReport() {
const onChangeDates = (startDate, endDate) => {
setStartDate(startDate);
setEndDate(endDate);
setSavedStatus('modified');
onReportChange({ type: 'modify' });
};

const onChangeViews = (viewType, status) => {
Expand Down Expand Up @@ -262,6 +260,7 @@ export function CustomReport() {
setBalanceType(defaultReport.balanceType);
setShowEmpty(defaultReport.showEmpty);
setShowOffBudget(defaultReport.showOffBudget);
setShowHiddenCategories(defaultReport.showHiddenCategories);
setShowUncategorized(defaultReport.showUncategorized);
setSelectedCategories(selectAll);
setGraphType(defaultReport.graphType);
Expand All @@ -272,7 +271,7 @@ export function CustomReport() {
};

const onChangeAppliedFilter = (filter, changedElement) => {
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
return changedElement(filter);
};

Expand Down Expand Up @@ -302,6 +301,7 @@ export function CustomReport() {
setBalanceType(report.balanceType);
setShowEmpty(report.showEmpty);
setShowOffBudget(report.showOffBudget);
setShowHiddenCategories(report.showHiddenCategories);
setShowUncategorized(report.showUncategorized);
setSelectedCategories(report.selectedCategories);
setGraphType(report.graphType);
Expand Down
6 changes: 3 additions & 3 deletions packages/loot-core/src/types/models/reports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { CategoryEntity } from './category';
import { type RuleConditionEntity } from './rule';

export interface CustomReportEntity {
id: string | undefined;
name: string | undefined;
id?: string;
name?: string;
startDate: string;
endDate: string;
isDateStatic: boolean;
Expand All @@ -15,7 +15,7 @@ export interface CustomReportEntity {
showOffBudget: boolean;
showHiddenCategories: boolean;
showUncategorized: boolean;
selectedCategories: CategoryEntity[];
selectedCategories?: CategoryEntity[];
graphType: string;
conditions?: RuleConditionEntity[];
conditionsOp: string;
Expand Down

0 comments on commit d469aa4

Please sign in to comment.