added default value back when not new (#20235)

fixes: #19852
This commit is contained in:
Erik Jan de Wit 2023-05-17 10:05:44 +02:00 committed by GitHub
parent 776984188f
commit 67f401b029
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 11 deletions

View file

@ -145,38 +145,32 @@ describe("Realm settings events tab tests", () => {
cy.findByTestId("option-aes-generated").click();
realmSettingsPage.enterUIDisplayName("test_aes-generated");
realmSettingsPage.toggleSwitch("active", false);
realmSettingsPage.toggleSwitch("enabled", false);
realmSettingsPage.addProvider();
realmSettingsPage.toggleAddProviderDropdown();
cy.findByTestId("option-ecdsa-generated").click();
realmSettingsPage.enterUIDisplayName("test_ecdsa-generated");
realmSettingsPage.toggleSwitch("enabled", false);
realmSettingsPage.toggleSwitch("active", false);
realmSettingsPage.addProvider();
realmSettingsPage.toggleAddProviderDropdown();
cy.findByTestId("option-hmac-generated").click();
realmSettingsPage.enterUIDisplayName("test_hmac-generated");
realmSettingsPage.toggleSwitch("active", false);
realmSettingsPage.toggleSwitch("enabled", false);
realmSettingsPage.addProvider();
realmSettingsPage.toggleAddProviderDropdown();
cy.findByTestId("option-rsa-generated").click();
realmSettingsPage.enterUIDisplayName("test_rsa-generated");
realmSettingsPage.toggleSwitch("active", false);
realmSettingsPage.toggleSwitch("enabled", false);
realmSettingsPage.addProvider();
realmSettingsPage.toggleAddProviderDropdown();
cy.findByTestId("option-rsa-enc-generated").click();
realmSettingsPage.enterUIDisplayName("test_rsa-enc-generated");
realmSettingsPage.toggleSwitch("active", false);
realmSettingsPage.toggleSwitch("enabled", false);
realmSettingsPage.addProvider();
});

View file

@ -242,7 +242,10 @@ export default function MappingDetails() {
/>
</FormGroup>
<FormProvider {...form}>
<DynamicComponents properties={mapping?.properties || []} />
<DynamicComponents
properties={mapping?.properties || []}
isNew={!isUpdating}
/>
</FormProvider>
<ActionGroup>
<Button variant="primary" type="submit">

View file

@ -11,6 +11,8 @@ export const BooleanComponent = ({
label,
helpText,
isDisabled = false,
defaultValue,
isNew = true,
}: ComponentProps) => {
const { t } = useTranslation("dynamic");
const { control } = useFormContext();
@ -27,7 +29,7 @@ export const BooleanComponent = ({
<Controller
name={convertToName(name!)}
data-testid={name}
defaultValue={false}
defaultValue={isNew ? defaultValue : false}
control={control}
render={({ field }) => (
<Switch
@ -38,7 +40,7 @@ export const BooleanComponent = ({
isChecked={
field.value === "true" ||
field.value === true ||
field.value[0] === "true"
field.value?.[0] === "true"
}
onChange={(value) => field.onChange("" + value)}
data-testid={name}

View file

@ -6,6 +6,7 @@ import { convertAttributeNameToForm } from "../../util";
type DynamicComponentProps = {
properties: ConfigPropertyRepresentation[];
stringify?: boolean;
isNew?: boolean;
};
export const DynamicComponents = ({

View file

@ -16,6 +16,7 @@ import { TextComponent } from "./TextComponent";
export type ComponentProps = Omit<ConfigPropertyRepresentation, "type"> & {
isDisabled?: boolean;
isNew?: boolean;
stringify?: boolean;
};