import { Alert, AlertVariant, Button, ButtonVariant, Form, FormGroup, Modal, ModalVariant, Switch, Text, TextContent, } from "@patternfly/react-core"; import FileSaver from "file-saver"; import React, { useState } from "react"; import { useTranslation } from "react-i18next"; import { useAlerts } from "../components/alert/Alerts"; import { useAdminClient } from "../context/auth/AdminClient"; import { useRealm } from "../context/realm-context/RealmContext"; import { prettyPrintJSON } from "../util"; import "./partial-export.css"; export type PartialExportDialogProps = { isOpen: boolean; onClose: () => void; }; export const PartialExportDialog = ({ isOpen, onClose, }: PartialExportDialogProps) => { const { t } = useTranslation("realm-settings"); const { realm } = useRealm(); const adminClient = useAdminClient(); const { addAlert, addError } = useAlerts(); const [exportGroupsAndRoles, setExportGroupsAndRoles] = useState(false); const [exportClients, setExportClients] = useState(false); const [isExporting, setIsExporting] = useState(false); const showWarning = exportGroupsAndRoles || exportClients; async function exportRealm() { setIsExporting(true); try { const realmExport = await adminClient.realms.export({ realm, exportClients, exportGroupsAndRoles, }); FileSaver.saveAs( new Blob([prettyPrintJSON(realmExport)], { type: "application/json", }), "realm-export.json" ); addAlert(t("exportSuccess"), AlertVariant.success); onClose(); } catch (error) { addError("exportFail", error); } setIsExporting(false); } return ( {t("common:export")} , , ]} > {t("partialExportHeaderText")}
{showWarning && ( {t("exportWarningDescription")} )}
); };