Skip to content

Commit

Permalink
reportChange and savedStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Feb 1, 2024
1 parent 14a4a54 commit a83440c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function ReportSidebar({
}) {
const [menuOpen, setMenuOpen] = useState(false);
const onSelectRange = cond => {
onReportChange(null, 'modify');
setDateRange(cond);
switch (cond) {
case 'All time':
Expand Down Expand Up @@ -77,6 +78,7 @@ export function ReportSidebar({
};

const onChangeMode = cond => {
onReportChange(null, 'modify');
setMode(cond);
if (cond === 'time') {
if (customReportItems.graphType === 'TableGraph') {
Expand Down Expand Up @@ -107,6 +109,7 @@ export function ReportSidebar({
};

const onChangeSplit = cond => {
onReportChange(null, 'modify');
setGroupBy(cond);
if (customReportItems.mode === 'total') {
if (customReportItems.graphType !== 'TableGraph') {
Expand All @@ -124,7 +127,7 @@ export function ReportSidebar({
};

const onChangeBalanceType = cond => {
onReportChange('modify');
onReportChange(null, 'modify');
setBalanceType(cond);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { SaveReportMenuButton } from './SaveReport';

export function ReportTopbar({
customReportItems,
savedStatus,
setGraphType,
setTypeDisabled,
setBalanceType,
Expand Down Expand Up @@ -169,7 +170,7 @@ export function ReportTopbar({
}}
/>
<View style={{ flex: 1 }} />
<SaveReportMenuButton />
<SaveReportMenuButton savedStatus={savedStatus} />
</View>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function SaveReportMenu({ setMenuOpen }) {
);
}

export function SaveReportMenuButton() {
export function SaveReportMenuButton(savedStatus: string) {
const [menuOpen, setMenuOpen] = useState(false);

return (
Expand All @@ -65,6 +65,7 @@ export function SaveReportMenuButton() {
>
Unsaved Report&nbsp;
</Text>
{savedStatus === 'modified' && <Text>(modified)&nbsp;</Text>}
<SvgExpandArrow width={8} height={8} style={{ marginRight: 5 }} />
</Button>
{menuOpen && <SaveReportMenu setMenuOpen={setMenuOpen} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export function CustomReport() {
const dateRangeLine = ReportOptions.dateRange.length - 3;

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

useEffect(() => {
Expand Down Expand Up @@ -221,6 +224,7 @@ export function CustomReport() {
const onChangeDates = (startDate, endDate) => {
setStartDate(startDate);
setEndDate(endDate);
setSavedStatus('modified');
};

const onChangeViews = (viewType, status) => {
Expand All @@ -236,26 +240,26 @@ export function CustomReport() {
};

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

const onReportChange = type => {
const onReportChange = (savedReport, type) => {
switch (type) {
case 'add-update':
setSavedStatus('saved');
setReport(savedReport);
break;
case 'rename':
setReport({ ...report, name: savedReport.name });
break;
case 'modify':
if (report.name) {
if (report.name.substr(report.name.length - 10) !== '(modified)') {
setReport({ ...report, name: report.name + ' (modified)' });
}
setSavedStatus('modified');
}
break;
case 'reload':
if (report.name.substr(report.name.length - 10) === '(modified)') {
setReport({
...report,
name: report.name.substr(0, report.name.length - 11),
});
}
setSavedStatus('saved');

setStartDate(report.startDate);
setEndDate(report.endDate);
Expand Down Expand Up @@ -317,6 +321,7 @@ export function CustomReport() {
>
<ReportTopbar
customReportItems={customReportItems}
savedStatus={savedStatus}
setGraphType={setGraphType}
setTypeDisabled={setTypeDisabled}
setBalanceType={setBalanceType}
Expand Down

0 comments on commit a83440c

Please sign in to comment.