Skip to content

Commit 2688537

Browse files
authored
Merge pull request #359 from TheauW/twartel-use-local-storage
feat: save and load in/from local storage
2 parents 57cdd36 + 725a952 commit 2688537

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

packages/diracx-web-components/src/components/DashboardLayout/ExportButton.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020

2121
import OutputIcon from "@mui/icons-material/Output";
2222
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
23+
import SaveIcon from "@mui/icons-material/Save";
2324

2425
import { DashboardGroup } from "../../types/DashboardGroup";
2526

@@ -33,11 +34,17 @@ interface ExportDialogProps {
3334

3435
function ExportDialog({ open, onClose, state }: ExportDialogProps) {
3536
const theme = useTheme();
37+
3638
const handleCopy = () => {
3739
navigator.clipboard.writeText(state);
3840
onClose();
3941
};
4042

43+
const handleSave = () => {
44+
localStorage.setItem("diracx-saved-states", state);
45+
onClose();
46+
};
47+
4148
return (
4249
<Dialog open={open} onClose={onClose} maxWidth="md" fullWidth>
4350
<DialogTitle>Application State</DialogTitle>
@@ -60,6 +67,13 @@ function ExportDialog({ open, onClose, state }: ExportDialogProps) {
6067
<Button onClick={onClose} data-testid="cancel-export-button">
6168
Cancel
6269
</Button>
70+
<Button
71+
onClick={handleSave}
72+
variant="contained"
73+
startIcon={<SaveIcon />}
74+
>
75+
Save in the browser
76+
</Button>
6377
<Button
6478
onClick={handleCopy}
6579
startIcon={<ContentCopyIcon />}

packages/diracx-web-components/src/components/DashboardLayout/ImportButton.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ function ImportDialog({ open, onClose, onImport }: ImportDialogProps) {
7777
<Button onClick={onClose} data-testid="cancel-import-button">
7878
Cancel
7979
</Button>
80+
<Button
81+
onClick={() =>
82+
setStateText(localStorage.getItem("diracx-saved-states") || "")
83+
}
84+
variant="contained"
85+
disabled={localStorage.getItem("diracx-saved-states") === null}
86+
>
87+
Load from browser
88+
</Button>
8089
<Button
8190
onClick={handleImport}
8291
variant="contained"

packages/diracx-web-components/src/hooks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from "./oidcConfiguration";
33
export * from "./searchParamsUtils";
44
export * from "./theme";
55
export * from "./utils";
6+
export * from "./application";

0 commit comments

Comments
 (0)