Changed key provider form to use ui shared (#27704)

* replaced KeycloakTextInput with TextControl

Signed-off-by: Agnieszka Gancarczyk <agancarc@redhat.com>

* replaced KeycloakTextInput with TextControl and fixed helpText

Signed-off-by: Agnieszka Gancarczyk <agancarc@redhat.com>

* small test fix

Signed-off-by: Agnieszka Gancarczyk <agancarc@redhat.com>

---------

Signed-off-by: Agnieszka Gancarczyk <agancarc@redhat.com>
Co-authored-by: Agnieszka Gancarczyk <agancarc@redhat.com>
This commit is contained in:
agagancarczyk 2024-03-08 10:26:49 +00:00 committed by GitHub
parent 7d104dbe9d
commit 84cf306833
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 74 deletions

View file

@ -83,7 +83,7 @@ export default class RealmSettingsPage extends CommonPage {
activeSwitch = "active"; activeSwitch = "active";
enabledSwitch = "enabled"; enabledSwitch = "enabled";
addProviderButton = "add-provider-button"; addProviderButton = "add-provider-button";
displayName = "name-input"; displayName = "name";
enableEvents = "eventsEnabled"; enableEvents = "eventsEnabled";
eventsUserSave = "save-user"; eventsUserSave = "save-user";
enableAdminEvents = "adminEventsEnabled"; enableAdminEvents = "adminEventsEnabled";

View file

@ -750,6 +750,7 @@ eventTypes.EXECUTE_ACTIONS_ERROR.name=Execute actions error
path=Path path=Path
overwritten=Overwritten overwritten=Overwritten
mapperNameHelp=Name of the mapper mapperNameHelp=Name of the mapper
providerIdHelp=Provider ID
deleteProviderError=Error deleting the provider deleteProviderError=Error deleting the provider
supportedLocalesHelp=The locales to support for this realm. The user chooses one of these locales on the login screen. supportedLocalesHelp=The locales to support for this realm. The user chooses one of these locales on the login screen.
comparisonHelp=Specifies the comparison method used to evaluate the requested context classes or statements. The default is "Exact". comparisonHelp=Specifies the comparison method used to evaluate the requested context classes or statements. The default is "Exact".

View file

@ -3,21 +3,16 @@ import {
ActionGroup, ActionGroup,
AlertVariant, AlertVariant,
Button, Button,
FormGroup,
PageSection, PageSection,
TextInput,
ValidatedOptions,
} from "@patternfly/react-core"; } from "@patternfly/react-core";
import { Controller, FormProvider, useForm } from "react-hook-form"; import { FormProvider, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { HelpItem } from "ui-shared"; import { TextControl } from "ui-shared";
import { adminClient } from "../../../admin-client"; import { adminClient } from "../../../admin-client";
import { useAlerts } from "../../../components/alert/Alerts"; import { useAlerts } from "../../../components/alert/Alerts";
import { DynamicComponents } from "../../../components/dynamic/DynamicComponents"; import { DynamicComponents } from "../../../components/dynamic/DynamicComponents";
import { FormAccess } from "../../../components/form/FormAccess"; import { FormAccess } from "../../../components/form/FormAccess";
import { KeycloakTextInput } from "../../../components/keycloak-text-input/KeycloakTextInput";
import { ViewHeader } from "../../../components/view-header/ViewHeader"; import { ViewHeader } from "../../../components/view-header/ViewHeader";
import { useServerInfo } from "../../../context/server-info/ServerInfoProvider"; import { useServerInfo } from "../../../context/server-info/ServerInfoProvider";
import { KEY_PROVIDER_TYPE } from "../../../util"; import { KEY_PROVIDER_TYPE } from "../../../util";
@ -47,13 +42,7 @@ export const KeyProviderForm = ({
const form = useForm<ComponentRepresentation>({ const form = useForm<ComponentRepresentation>({
mode: "onChange", mode: "onChange",
}); });
const { const { handleSubmit, reset } = form;
register,
control,
handleSubmit,
formState: { errors },
reset,
} = form;
const save = async (component: ComponentRepresentation) => { const save = async (component: ComponentRepresentation) => {
if (component.config) if (component.config)
@ -99,73 +88,46 @@ export const KeyProviderForm = ({
return ( return (
<FormAccess isHorizontal role="manage-realm" onSubmit={handleSubmit(save)}> <FormAccess isHorizontal role="manage-realm" onSubmit={handleSubmit(save)}>
{id && (
<FormGroup
label={t("providerId")}
labelIcon={
<HelpItem
helpText={t("mapperNameHelp")}
fieldLabelId="providerId"
/>
}
fieldId="providerId"
isRequired
>
<KeycloakTextInput
id="providerId"
data-testid="providerId-input"
isReadOnly
{...register("id")}
/>
</FormGroup>
)}
<FormGroup
label={t("name")}
labelIcon={
<HelpItem helpText={t("mapperNameHelp")} fieldLabelId="name" />
}
fieldId="name"
isRequired
validated={
errors.name ? ValidatedOptions.error : ValidatedOptions.default
}
helperTextInvalid={t("required")}
>
<Controller
name="name"
control={control}
rules={{ required: true }}
defaultValue={providerType}
render={({ field }) => (
<TextInput
id="name"
value={field.value}
onChange={field.onChange}
data-testid="name-input"
/>
)}
/>
</FormGroup>
<FormProvider {...form}> <FormProvider {...form}>
{id && (
<TextControl
name="id"
label={t("providerId")}
labelIcon={t("providerIdHelp")}
rules={{
required: t("required"),
}}
readOnly
/>
)}
<TextControl
name="name"
defaultValue={providerType}
label={t("name")}
labelIcon={t("mapperNameHelp")}
rules={{
required: t("required"),
}}
/>
<DynamicComponents <DynamicComponents
properties={ properties={
allComponentTypes.find((type) => type.id === providerType) allComponentTypes.find((type) => type.id === providerType)
?.properties || [] ?.properties || []
} }
/> />
<ActionGroup>
<Button
data-testid="add-provider-button"
variant="primary"
type="submit"
>
{t("save")}
</Button>
<Button onClick={() => onClose?.()} variant="link">
{t("cancel")}
</Button>
</ActionGroup>
</FormProvider> </FormProvider>
<ActionGroup>
<Button
data-testid="add-provider-button"
variant="primary"
type="submit"
>
{t("save")}
</Button>
<Button onClick={() => onClose?.()} variant="link">
{t("cancel")}
</Button>
</ActionGroup>
</FormAccess> </FormAccess>
); );
}; };