Added text component for ProviderConfigProperty.TEXT_TYPE (#3269)

This commit is contained in:
Erik Jan de Wit 2022-09-12 17:53:41 +02:00 committed by GitHub
parent 76ce0e5315
commit 985c8dc90a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,38 @@
import { useTranslation } from "react-i18next";
import { useFormContext } from "react-hook-form";
import { FormGroup } from "@patternfly/react-core";
import { HelpItem } from "../help-enabler/HelpItem";
import { KeycloakTextArea } from "../keycloak-text-area/KeycloakTextArea";
import type { ComponentProps } from "./components";
import { convertToName } from "./DynamicComponents";
export const TextComponent = ({
name,
label,
helpText,
defaultValue,
isDisabled = false,
}: ComponentProps) => {
const { t } = useTranslation("dynamic");
const { register } = useFormContext();
return (
<FormGroup
label={t(label!)}
labelIcon={
<HelpItem helpText={t(helpText!)} fieldLabelId={`dynamic:${label}`} />
}
fieldId={name!}
>
<KeycloakTextArea
id={name!}
data-testid={name}
isDisabled={isDisabled}
ref={register()}
name={convertToName(name!)}
defaultValue={defaultValue?.toString()}
/>
</FormGroup>
);
};

View file

@ -2,6 +2,7 @@ import type { FunctionComponent } from "react";
import type { ConfigPropertyRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation"; import type { ConfigPropertyRepresentation } from "@keycloak/keycloak-admin-client/lib/defs/authenticatorConfigInfoRepresentation";
import { StringComponent } from "./StringComponent"; import { StringComponent } from "./StringComponent";
import { TextComponent } from "./TextComponent";
import { BooleanComponent } from "./BooleanComponent"; import { BooleanComponent } from "./BooleanComponent";
import { ListComponent } from "./ListComponent"; import { ListComponent } from "./ListComponent";
import { RoleComponent } from "./RoleComponent"; import { RoleComponent } from "./RoleComponent";
@ -20,6 +21,7 @@ export type ComponentProps = Omit<ConfigPropertyRepresentation, "type"> & {
const ComponentTypes = [ const ComponentTypes = [
"String", "String",
"Text",
"boolean", "boolean",
"List", "List",
"Role", "Role",
@ -39,6 +41,7 @@ export const COMPONENTS: {
[index in Components]: FunctionComponent<ComponentProps>; [index in Components]: FunctionComponent<ComponentProps>;
} = { } = {
String: StringComponent, String: StringComponent,
Text: TextComponent,
boolean: BooleanComponent, boolean: BooleanComponent,
List: ListComponent, List: ListComponent,
Role: RoleComponent, Role: RoleComponent,