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:
parent
7d104dbe9d
commit
84cf306833
3 changed files with 37 additions and 74 deletions
|
@ -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";
|
||||||
|
|
|
@ -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".
|
||||||
|
|
|
@ -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,61 +88,33 @@ 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 || []
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</FormProvider>
|
|
||||||
<ActionGroup>
|
<ActionGroup>
|
||||||
<Button
|
<Button
|
||||||
data-testid="add-provider-button"
|
data-testid="add-provider-button"
|
||||||
|
@ -166,6 +127,7 @@ export const KeyProviderForm = ({
|
||||||
{t("cancel")}
|
{t("cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
</ActionGroup>
|
</ActionGroup>
|
||||||
|
</FormProvider>
|
||||||
</FormAccess>
|
</FormAccess>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue