Skip to content

Commit

Permalink
saveReport strict Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Feb 3, 2024
1 parent da0f587 commit c75d118
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
22 changes: 7 additions & 15 deletions packages/desktop-client/src/components/reports/ReportTopbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from '../../icons/v1';
import { theme } from '../../style';
import { View } from '../common/View';
import { FilterButton } from '../filters/FilterButton';
import { FilterButton } from '../filters/FiltersMenu';

import { GraphButton } from './GraphButton';
import { SaveReport } from './SaveReport';
Expand Down Expand Up @@ -45,7 +45,7 @@ export function ReportTopbar({
selected={customReportItems.graphType === 'TableGraph'}
title="Data Table"
onSelect={() => {
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
setGraphType('TableGraph');
onChangeViews('viewLegend', false);
setTypeDisabled([]);
Expand All @@ -63,7 +63,7 @@ export function ReportTopbar({
customReportItems.graphType === 'StackedBarGraph'
}
onSelect={() => {
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
if (customReportItems.mode === 'total') {
setGraphType('BarGraph');
if (['Net'].includes(customReportItems.balanceType)) {
Expand All @@ -88,7 +88,7 @@ export function ReportTopbar({
title="Area Graph"
selected={customReportItems.graphType === 'AreaGraph'}
onSelect={() => {
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
setGraphType('AreaGraph');
setGroupBy('Month');
onChangeViews('viewLegend', false);
Expand All @@ -103,7 +103,7 @@ export function ReportTopbar({
title="Donut Graph"
selected={customReportItems.graphType === 'DonutGraph'}
onSelect={() => {
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
setGraphType('DonutGraph');
setTypeDisabled(['Net']);
setBalanceType('Payment');
Expand All @@ -125,7 +125,7 @@ export function ReportTopbar({
<GraphButton
selected={viewLegend}
onSelect={() => {
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
onChangeViews('viewLegend');
}}
style={{ marginRight: 15 }}
Expand Down Expand Up @@ -173,15 +173,7 @@ export function ReportTopbar({
hover
onApply={e => {
onApplyFilter(e);
onReportChange(null, 'modify');
}}
/>
<FilterButton
compact
hover
onApply={e => {
onApplyFilter(e);
onReportChange(null, 'modify');
onReportChange({ type: 'modify' });
}}
/>
<View style={{ flex: 1 }} />
Expand Down
38 changes: 22 additions & 16 deletions packages/desktop-client/src/components/reports/SaveReport.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import React, { createRef, useState } from 'react';

import { v4 as uuidv4 } from 'uuid';
Expand All @@ -18,7 +17,13 @@ type SaveReportProps<T extends CustomReportEntity = CustomReportEntity> = {
customReportItems: T;
report: CustomReportEntity;
savedStatus: string;
onReportChange: (savedReport: T, type: string) => void;
onReportChange: ({
savedReport,
type,
}: {
savedReport?: T;
type: string;
}) => void;
onResetReports: () => void;
};

Expand All @@ -31,21 +36,22 @@ export function SaveReport({
}: SaveReportProps) {
const [nameMenuOpen, setNameMenuOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const [menuItem, setMenuItem] = useState(null);
const [err, setErr] = useState(null);
const [menuItem, setMenuItem] = useState('');
const [err, setErr] = useState('');
const [res, setRes] = useState('');
const [name, setName] = useState(report.name);
const inputRef = createRef<HTMLInputElement>();

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

if (menuItem === 'save-report') {
setRes('');
//create new flow
/*
res = await sendCatch('report/create', {
Expand Down Expand Up @@ -79,27 +85,27 @@ export function SaveReport({
});
*/
}
if (res) {
setErr(res.error.message);
if (res !== '') {
setErr(res);
setNameMenuOpen(true);
} else {
setNameMenuOpen(false);
onReportChange(
onReportChange({
savedReport,
menuItem === 'rename-report' ? 'rename' : 'add-update',
);
type: menuItem === 'rename-report' ? 'rename' : 'add-update',
});
}
};

const onNameChange = cond => {
const onNameChange = (cond: string) => {
setName(cond);
};

const onMenuSelect = async item => {
const onMenuSelect = async (item: string) => {
setMenuItem(item);
switch (item) {
case 'rename-report':
setErr(null);
setErr('');
setMenuOpen(false);
setNameMenuOpen(true);
break;
Expand All @@ -109,18 +115,18 @@ export function SaveReport({
onResetReports();
break;
case 'update-report':
setErr(null);
setErr('');
setMenuOpen(false);
onAddUpdate();
break;
case 'save-report':
setErr(null);
setErr('');
setMenuOpen(false);
setNameMenuOpen(true);
break;
case 'reload-report':
setMenuOpen(false);
onReportChange(null, 'reload');
onReportChange({ type: 'reload' });
break;
case 'reset-report':
setMenuOpen(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ export function SaveReportName({
</Stack>
</form>
)}
{err && (
{err !== '' ? (
<Stack direction="row" align="center" style={{ padding: 10 }}>
<Text style={{ color: theme.errorText }}>{err}</Text>
</Stack>
) : (
<Text />
)}
</MenuTooltip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function CustomReport() {
return changedElement(filter);
};

const onReportChange = (savedReport, type) => {
const onReportChange = ({ savedReport, type }) => {
switch (type) {
case 'add-update':
setSavedStatus('saved');
Expand Down

0 comments on commit c75d118

Please sign in to comment.