Skip to content
Snippets Groups Projects
Unverified Commit 83fd85f0 authored by Neil's avatar Neil Committed by GitHub
Browse files

Custom Reports: Confirm delete report (#2521)

* confirm delete report

* notes

* card confirm
parent 308f8339
No related branches found
No related tags found
No related merge requests found
...@@ -10,6 +10,7 @@ import { Text } from '../common/Text'; ...@@ -10,6 +10,7 @@ import { Text } from '../common/Text';
import { View } from '../common/View'; import { View } from '../common/View';
import { SaveReportChoose } from './SaveReportChoose'; import { SaveReportChoose } from './SaveReportChoose';
import { SaveReportDelete } from './SaveReportDelete';
import { SaveReportMenu } from './SaveReportMenu'; import { SaveReportMenu } from './SaveReportMenu';
import { SaveReportName } from './SaveReportName'; import { SaveReportName } from './SaveReportName';
...@@ -33,6 +34,7 @@ export function SaveReport({ ...@@ -33,6 +34,7 @@ export function SaveReport({
onReportChange, onReportChange,
}: SaveReportProps) { }: SaveReportProps) {
const listReports = useReports(); const listReports = useReports();
const [deleteMenuOpen, setDeleteMenuOpen] = useState(false);
const [nameMenuOpen, setNameMenuOpen] = useState(false); const [nameMenuOpen, setNameMenuOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false); const [menuOpen, setMenuOpen] = useState(false);
const [chooseMenuOpen, setChooseMenuOpen] = useState(false); const [chooseMenuOpen, setChooseMenuOpen] = useState(false);
...@@ -97,6 +99,13 @@ export function SaveReport({ ...@@ -97,6 +99,13 @@ export function SaveReport({
}); });
}; };
const onDelete = async () => {
setName('');
await send('report/delete', report.id);
onReportChange({ type: 'reset' });
setDeleteMenuOpen(false);
};
const onMenuSelect = async (item: string) => { const onMenuSelect = async (item: string) => {
setMenuItem(item); setMenuItem(item);
switch (item) { switch (item) {
...@@ -107,9 +116,7 @@ export function SaveReport({ ...@@ -107,9 +116,7 @@ export function SaveReport({
break; break;
case 'delete-report': case 'delete-report':
setMenuOpen(false); setMenuOpen(false);
setName(''); setDeleteMenuOpen(true);
await send('report/delete', report.id);
onReportChange({ type: 'reset' });
break; break;
case 'update-report': case 'update-report':
setErr(''); setErr('');
...@@ -191,6 +198,13 @@ export function SaveReport({ ...@@ -191,6 +198,13 @@ export function SaveReport({
onClose={() => setChooseMenuOpen(false)} onClose={() => setChooseMenuOpen(false)}
/> />
)} )}
{deleteMenuOpen && (
<SaveReportDelete
onDelete={onDelete}
onClose={() => setDeleteMenuOpen(false)}
name={report.name}
/>
)}
</View> </View>
); );
} }
import React from 'react';
import { theme } from '../../style/theme';
import { Button } from '../common/Button';
import { Stack } from '../common/Stack';
import { Text } from '../common/Text';
import { View } from '../common/View';
import { Tooltip } from '../tooltips';
type SaveReportDeleteProps = {
onDelete: () => void;
onClose: () => void;
name: string;
};
export function SaveReportDelete({
onDelete,
onClose,
name,
}: SaveReportDeleteProps) {
return (
<Tooltip
position="bottom-right"
style={{ padding: 15, color: theme.menuItemText }}
width={275}
onClose={onClose}
>
<View style={{ align: 'center' }}>
<Text style={{ color: theme.errorText, marginBottom: 5 }}>
Do you want to delete report:
</Text>
<View>{name}</View>
</View>
<Stack
direction="row"
justify="flex-end"
align="center"
style={{ marginTop: 15 }}
>
<View style={{ flex: 1 }} />
<Button type="primary" onClick={onDelete}>
Yes
</Button>
<Button type="primary" onClick={onClose}>
No
</Button>
</Stack>
</Tooltip>
);
}
...@@ -16,6 +16,7 @@ import { Text } from '../../common/Text'; ...@@ -16,6 +16,7 @@ import { Text } from '../../common/Text';
import { View } from '../../common/View'; import { View } from '../../common/View';
import { DateRange } from '../DateRange'; import { DateRange } from '../DateRange';
import { ReportCard } from '../ReportCard'; import { ReportCard } from '../ReportCard';
import { SaveReportDelete } from '../SaveReportDelete';
import { SaveReportName } from '../SaveReportName'; import { SaveReportName } from '../SaveReportName';
import { GetCardData } from './GetCardData'; import { GetCardData } from './GetCardData';
...@@ -66,6 +67,7 @@ export function CustomReportListCards({ ...@@ -66,6 +67,7 @@ export function CustomReportListCards({
}) { }) {
const result: { [key: string]: boolean }[] = index(reports); const result: { [key: string]: boolean }[] = index(reports);
const [reportMenu, setReportMenu] = useState(result); const [reportMenu, setReportMenu] = useState(result);
const [deleteMenuOpen, setDeleteMenuOpen] = useState(result);
const [nameMenuOpen, setNameMenuOpen] = useState(result); const [nameMenuOpen, setNameMenuOpen] = useState(result);
const [err, setErr] = useState(''); const [err, setErr] = useState('');
const [name, setName] = useState(''); const [name, setName] = useState('');
...@@ -77,6 +79,12 @@ export function CustomReportListCards({ ...@@ -77,6 +79,12 @@ export function CustomReportListCards({
const [isCardHovered, setIsCardHovered] = useState(''); const [isCardHovered, setIsCardHovered] = useState('');
const onDelete = async (reportData: string) => {
setName('');
await send('report/delete', reportData);
onDeleteMenuOpen(reportData === undefined ? '' : reportData, false);
};
const onAddUpdate = async ({ const onAddUpdate = async ({
reportData, reportData,
}: { }: {
...@@ -105,7 +113,8 @@ export function CustomReportListCards({ ...@@ -105,7 +113,8 @@ export function CustomReportListCards({
const onMenuSelect = async (item: string, report: CustomReportEntity) => { const onMenuSelect = async (item: string, report: CustomReportEntity) => {
if (item === 'delete') { if (item === 'delete') {
onMenuOpen(report.id, false); onMenuOpen(report.id, false);
await send('report/delete', report.id); onDeleteMenuOpen(report.id, true);
setErr('');
} }
if (item === 'rename') { if (item === 'rename') {
onMenuOpen(report.id, false); onMenuOpen(report.id, false);
...@@ -119,6 +128,10 @@ export function CustomReportListCards({ ...@@ -119,6 +128,10 @@ export function CustomReportListCards({
setReportMenu({ ...reportMenu, [item]: state }); setReportMenu({ ...reportMenu, [item]: state });
}; };
const onDeleteMenuOpen = (item: string, state: boolean) => {
setDeleteMenuOpen({ ...deleteMenuOpen, [item]: state });
};
const onNameMenuOpen = (item: string, state: boolean) => { const onNameMenuOpen = (item: string, state: boolean) => {
setNameMenuOpen({ ...nameMenuOpen, [item]: state }); setNameMenuOpen({ ...nameMenuOpen, [item]: state });
}; };
...@@ -257,6 +270,22 @@ export function CustomReportListCards({ ...@@ -257,6 +270,22 @@ export function CustomReportListCards({
report={report} report={report}
/> />
)} )}
{report.id === undefined
? null
: deleteMenuOpen[
report.id as keyof typeof deleteMenuOpen
] && (
<SaveReportDelete
onDelete={() => onDelete(report.id)}
onClose={() =>
onDeleteMenuOpen(
report.id === undefined ? '' : report.id,
false,
)
}
name={report.name}
/>
)}
</View> </View>
</View> </View>
))} ))}
......
---
category: Enhancements
authors: [carkom]
---
A simple delete confirmation for custom reports.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment