Add button to download ctl config (#743)

* Move saveJson to util file

* Add button to download ctl config

* Add icon and tooltip to describe what the button does

---------

Co-authored-by: Danielv123 <danielv@danielv.no>
This commit is contained in:
Cooldude2606andDanielv123 authored and GitHub committed 2025-04-08 20:34:50 +01:00
1 parent 42cd099eea
commit 0e6d33aa82
3 files changed
+43 -17

No files matched your search

+1 -16
View File
@@ -10,6 +10,7 @@ import { useAccount } from "../model/account";
import ControlContext from "./ControlContext";
import { notifyErrorHandler } from "../util/notify";
import { formatDuration } from "../util/time_format";
import { saveJson } from "../util/save_file";
import PageHeader from "./PageHeader";
import PageLayout from "./PageLayout";
import PluginExtra from "./PluginExtra";
@@ -58,22 +59,6 @@ function CreateUserButton() {
</>;
}
// This is the most common and best supported method
// For full support we should consider using npm:file-saver
function saveFile(name: string, blob: Blob) {
const a = document.createElement("a");
a.href = URL.createObjectURL(blob);
a.download = name;
a.addEventListener("click", (e) => {
setTimeout(() => URL.revokeObjectURL(a.href), 30 * 1000);
});
a.click();
};
function saveJson(name: string, json: object) {
return saveFile(name, new Blob([JSON.stringify(json, null, 2)], { type: "application/json" }));
}
type UserBulkActionProps = {
setApplyAction(func: () => Promise<void>): void,
form: FormInstance,