Skip to content

Commit

Permalink
Show Dialog in case there are no diagnostic files to be downloaded #106
Browse files Browse the repository at this point in the history
  • Loading branch information
stylesuxx committed Aug 23, 2022
1 parent ff31105 commit a54e361
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 11 deletions.
59 changes: 50 additions & 9 deletions src/features/packages/Packages.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { useTranslation } from "react-i18next";

import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Dialog from '@mui/material/Dialog';
import DialogActions from '@mui/material/DialogActions';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogTitle from '@mui/material/DialogTitle';
import FormControl from "@mui/material/FormControl";
import InputLabel from "@mui/material/InputLabel";
import Menu from "@mui/material/Menu";
Expand Down Expand Up @@ -62,6 +67,8 @@ export default function Packages({ adb }) {
const scrollListenerId = useRef();
const [anchorEl, setAnchorEl] = React.useState(null);

const [showNoDiagnosticsDialog, setShowNoDiagnosticsDialog] = React.useState(false);

const dispatch = useDispatch();

const fetched = useSelector(selectFetched);
Expand Down Expand Up @@ -158,15 +165,19 @@ export default function Packages({ adb }) {
adb,
name,
callback: ((data) => {
const fileName = `${name}.tar.gz`;
const url = window.URL.createObjectURL(new Blob([data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", fileName);

document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
if(data.length > 0) {
const fileName = `${name}.tar.gz`;
const url = window.URL.createObjectURL(new Blob([data]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", fileName);

document.body.appendChild(link);
link.click();
link.parentNode.removeChild(link);
} else {
setShowNoDiagnosticsDialog(true);
}
}),
}));
}, [adb, dispatch]);
Expand All @@ -175,6 +186,10 @@ export default function Packages({ adb }) {
setMenuOpen(null);
}, [setMenuOpen]);

const closeDiagnosticDialogHandler = useCallback((event) => {
setShowNoDiagnosticsDialog(false);
}, [setShowNoDiagnosticsDialog]);

const moreHandler = useCallback((event) => {
setAnchorEl(event.currentTarget);
const name = event.target.dataset["key"];
Expand Down Expand Up @@ -298,6 +313,32 @@ export default function Packages({ adb }) {
{!fetched && hasOpkgBinary &&
<Spinner text={t("fetching")} />}

<Dialog
aria-describedby="alert-dialog-description"
aria-labelledby="alert-dialog-title"
onClose={closeDiagnosticDialogHandler}
open={showNoDiagnosticsDialog}
>
<DialogTitle id="alert-dialog-title">
{t("titleNoDiagnosticData")}
</DialogTitle>

<DialogContent>
<DialogContentText id="alert-dialog-description">
{t("textNoDiagnosticData")}
</DialogContentText>
</DialogContent>

<DialogActions>
<Button
autoFocus
onClick={closeDiagnosticDialogHandler}
>
{t("ok")}
</Button>
</DialogActions>
</Dialog>

{fetched && hasOpkgBinary &&
<Stack
spacing={2}
Expand Down
1 change: 0 additions & 1 deletion src/features/packages/packagesSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ export const downloadDiagnostics = createAsyncThunk(
name,
callback,
}) => {
console.log("Download diagnostics for", name);
await adb.downloadDiagnostics(name, callback);
}
);
Expand Down
5 changes: 4 additions & 1 deletion src/translations/en/packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"description": "Description",
"matchCount": "Found {{count}} packages",
"more": "More",
"downloadDiagnostics": "Download Diagnostics"
"downloadDiagnostics": "Download Diagnostics",
"titleNoDiagnosticData": "No diagnostic data",
"textNoDiagnosticData": "No diagnostic data could be fetched for this package.",
"ok": "OK"
}

0 comments on commit a54e361

Please sign in to comment.