fixing the remainder of issue 428 (#621)

* fixing the remainder of issue 428

fixing: #428

* fix undefined

* add leave dialog
This commit is contained in:
Erik Jan de Wit 2021-05-24 06:21:49 +02:00 committed by GitHub
parent 0f6ce35687
commit 29323cb12c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 31 deletions

View file

@ -35,7 +35,7 @@ export const SignedJWT = () => {
>
<Controller
name="attributes.token-endpoint-auth-signing-alg"
defaultValue={providers[0]}
defaultValue=""
control={control}
render={({ onChange, value }) => (
<Select
@ -46,18 +46,23 @@ export const SignedJWT = () => {
onChange(value as string);
isOpen(false);
}}
selections={value}
selections={value || t("anyAlgorithm")}
variant={SelectVariant.single}
aria-label={t("signatureAlgorithm")}
isOpen={open}
>
{providers.map((option) => (
<SelectOption
selected={option === value}
key={option}
value={option}
/>
))}
<SelectOption selected={value === ""} key="any" value="">
{t("anyAlgorithm")}
</SelectOption>
<>
{providers.map((option) => (
<SelectOption
selected={option === value}
key={option}
value={option}
/>
))}
</>
</Select>
)}
/>

View file

@ -1,12 +1,12 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { useFormContext } from "react-hook-form";
import { FormGroup, TextInput } from "@patternfly/react-core";
import { FormGroup, TextInput, ValidatedOptions } from "@patternfly/react-core";
import { HelpItem } from "../../components/help-enabler/HelpItem";
export const X509 = () => {
const { t } = useTranslation("clients");
const { register } = useFormContext();
const { register, errors } = useFormContext();
return (
<FormGroup
label={t("subject")}
@ -18,12 +18,24 @@ export const X509 = () => {
forID="kc-subject"
/>
}
helperTextInvalid={t("common:required")}
validated={
errors.attributes && errors.attributes["x509-subjectdn"]
? ValidatedOptions.error
: ValidatedOptions.default
}
isRequired
>
<TextInput
ref={register()}
ref={register({ required: true })}
type="text"
id="kc-subject"
name="attributes.x509-subjectdn"
validated={
errors.attributes && errors.attributes["x509-subjectdn"]
? ValidatedOptions.error
: ValidatedOptions.default
}
/>
</FormGroup>
);

View file

@ -128,6 +128,7 @@
"changeAuthenticatorConfirmTitle": "Change to {{clientAuthenticatorType}}",
"changeAuthenticatorConfirm": "If you change authenticator to {{clientAuthenticatorType}}, the keycloak database will be updated and you may need to download a new adapter configuration for this client",
"signedJWTConfirm": "You should configure JWKS URL or keys in the \"Keys\" tab to change the parameters of Signed JWT authenticator.",
"anyAlgorithm": "Any algorithm",
"clientSecret": "Client secret",
"regenerate": "Regenerate",
"confirmClientSecretTitle": "Regenerate secret for this client?",

View file

@ -127,6 +127,10 @@
"emptyMappers": "No mappers",
"emptyMappersInstructions": "If you want to add mappers, please click the button below to add some predefined mappers or to configure a new mapper.",
"emptyPrimaryAction": "Add predefined mapper"
"emptyPrimaryAction": "Add predefined mapper",
"leaveDirtyTitle": "Leave without saving?",
"leaveDirtyConfirm": "Do you want to leave this page without saving? Any unsaved changes will be lost.",
"leave": "Leave"
}
}

View file

@ -1,6 +1,8 @@
import React, { Children, isValidElement } from "react";
import React, { Children, isValidElement, useState } from "react";
import { useHistory, useRouteMatch } from "react-router-dom";
import { TabProps, Tabs, TabsProps } from "@patternfly/react-core";
import { useFormContext } from "react-hook-form";
import { useConfirmDialog } from "../confirm-dialog/ConfirmDialog";
type KeycloakTabsProps = Omit<TabsProps, "ref" | "activeKey" | "onSelect"> & {
paramName?: string;
@ -28,6 +30,8 @@ export const KeycloakTabs = ({
const match = useRouteMatch();
const params = match.params as { [index: string]: string };
const history = useHistory();
const form = useFormContext();
const [key, setKey] = useState("");
const firstTab = Children.toArray(children)[0];
const tab =
@ -37,21 +41,42 @@ export const KeycloakTabs = ({
const pathIndex = match.path.indexOf(paramName) + paramName.length;
const path = match.path.substr(0, pathIndex);
const [toggleChangeTabDialog, ChangeTabConfirm] = useConfirmDialog({
titleKey: "common:leaveDirtyTitle",
messageKey: "common:leaveDirtyConfirm",
continueButtonLabel: "common:leave",
onConfirm: () => {
form.reset();
history.push(createUrl(path, { ...params, [paramName]: key as string }));
},
});
return (
<Tabs
inset={{
default: "insetNone",
md: "insetSm",
xl: "inset2xl",
"2xl": "insetLg",
}}
activeKey={tab}
onSelect={(_, key) =>
history.push(createUrl(path, { ...params, [paramName]: key as string }))
}
{...rest}
>
{children}
</Tabs>
<>
<ChangeTabConfirm />
<Tabs
inset={{
default: "insetNone",
md: "insetSm",
xl: "inset2xl",
"2xl": "insetLg",
}}
activeKey={tab}
onSelect={(_, key) => {
if (form?.formState.isDirty) {
setKey(key as string);
toggleChangeTabDialog();
} else {
history.push(
createUrl(path, { ...params, [paramName]: key as string })
);
}
}}
{...rest}
>
{children}
</Tabs>
</>
);
};

View file

@ -21,7 +21,7 @@ export function convertToMultiline(fields: string[]): MultiLine[] {
}
export function toValue(formValue: MultiLine[]): string[] {
return formValue.map((field) => field.value);
return formValue?.map((field) => field.value);
}
export type MultiLineInputProps = Omit<TextInputProps, "form"> & {

View file

@ -45,7 +45,11 @@ export const ScrollForm = ({
</ScrollPanel>
)}
{borders && (
<FormPanel scrollId={spacesToHyphens(cat)} title={cat}>
<FormPanel
scrollId={spacesToHyphens(cat)}
title={cat}
className="kc-form-panel__panel"
>
{nodes[index]}
</FormPanel>
)}