From bc8ffed934355d07cb6ee200a83216007aa6e0fb Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 1 Dec 2021 12:05:24 +0100 Subject: [PATCH] added import dialog for authorization resources (#1604) --- src/clients/authorization/ImportDialog.tsx | 156 ++++++++++++++++++ src/clients/authorization/Settings.tsx | 18 +- src/clients/messages.ts | 4 + .../json-file-upload/FileUploadForm.tsx | 21 ++- src/realm-settings/PartialImport.tsx | 1 + 5 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 src/clients/authorization/ImportDialog.tsx diff --git a/src/clients/authorization/ImportDialog.tsx b/src/clients/authorization/ImportDialog.tsx new file mode 100644 index 0000000000..0344e79374 --- /dev/null +++ b/src/clients/authorization/ImportDialog.tsx @@ -0,0 +1,156 @@ +import React, { Fragment, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { + Alert, + Button, + ButtonVariant, + Divider, + Form, + FormGroup, + Modal, + Radio, + Switch, +} from "@patternfly/react-core"; + +import type ResourceServerRepresentation from "@keycloak/keycloak-admin-client/lib/defs/resourceServerRepresentation"; +import { JsonFileUpload } from "../../components/json-file-upload/JsonFileUpload"; +import { HelpItem } from "../../components/help-enabler/HelpItem"; + +type ImportDialogProps = { + onConfirm: (value: ResourceServerRepresentation) => void; + closeDialog: () => void; +}; + +export const ImportDialog = ({ onConfirm, closeDialog }: ImportDialogProps) => { + const { t } = useTranslation("clients"); + const [imported, setImported] = useState({}); + return ( + { + onConfirm(imported); + closeDialog(); + }} + data-testid="confirm" + > + {t("confirm")} + , + , + ]} + > +
+ + + {Object.keys(imported).length !== 0 && ( + <> + +

{t("importResources")}

+
+ + } + fieldId="policyEnforcementMode" + hasNoPaddingTop + > + + + + } + fieldId="decisionStrategy" + hasNoPaddingTop + > + + + + } + > + + +
+
+ {Object.entries(imported) + .filter(([, value]) => Array.isArray(value)) + .map(([key, value]) => ( + + +

+ + {value.length} {t(key)} + +

+
+ ))} +
+ + + + )} +
+ ); +}; diff --git a/src/clients/authorization/Settings.tsx b/src/clients/authorization/Settings.tsx index 6b56529c7a..14322c2ed4 100644 --- a/src/clients/authorization/Settings.tsx +++ b/src/clients/authorization/Settings.tsx @@ -16,6 +16,8 @@ import { useAdminClient, useFetch } from "../../context/auth/AdminClient"; import { FormAccess } from "../../components/form-access/FormAccess"; import { HelpItem } from "../../components/help-enabler/HelpItem"; import { SaveReset } from "../advanced/SaveReset"; +import { ImportDialog } from "./ImportDialog"; +import useToggle from "../../utils/useToggle"; const POLICY_ENFORCEMENT_MODES = [ "ENFORCING", @@ -27,6 +29,8 @@ const DECISION_STRATEGY = ["UNANIMOUS", "AFFIRMATIVE"] as const; export const AuthorizationSettings = ({ clientId }: { clientId: string }) => { const { t } = useTranslation("clients"); const [resource, setResource] = useState(); + const [importDialog, toggleImportDialog] = useToggle(); + const { control, reset } = useForm({ shouldUnregister: false, }); @@ -42,12 +46,22 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => { [] ); + const importResource = () => { + //different PR + }; + if (!resource) { return ; } return ( + {importDialog && ( + + )} { /> } > - + - - handleChange(value, fileUpload.filename, event as any) - } - /> + {!rest.hideDefaultPreview && ( + + handleChange(value || "", fileUpload.filename, event as any) + } + isReadOnly={!rest.allowEditingUploadedText} + /> + )} )} diff --git a/src/realm-settings/PartialImport.tsx b/src/realm-settings/PartialImport.tsx index fbec4d06ce..12aa6b5996 100644 --- a/src/realm-settings/PartialImport.tsx +++ b/src/realm-settings/PartialImport.tsx @@ -318,6 +318,7 @@ export const PartialImportDialog = (props: PartialImportProps) => {