made buttons disabled when all fields are readonly (#31436)
also renamed `isActive` to `isDisabled` to be more inline with PF fixes: #31304 Signed-off-by: Erik Jan de Wit <erikjan.dewit@gmail.com>
This commit is contained in:
parent
fc80cc75fe
commit
d9555e4c9f
8 changed files with 16 additions and 13 deletions
|
@ -42,7 +42,7 @@ export const AccessSettings = ({
|
|||
name="settings"
|
||||
save={save}
|
||||
reset={reset}
|
||||
isActive={!isManager}
|
||||
isDisabled={isManager}
|
||||
/>
|
||||
)}
|
||||
</FormAccess>
|
||||
|
|
|
@ -157,7 +157,7 @@ export const LogoutPanel = ({
|
|||
name="settings"
|
||||
save={save}
|
||||
reset={reset}
|
||||
isActive={isManager}
|
||||
isDisabled={!isManager}
|
||||
/>
|
||||
</FormAccess>
|
||||
);
|
||||
|
|
|
@ -155,7 +155,6 @@ export const AuthorizationSettings = ({ clientId }: { clientId: string }) => {
|
|||
<FixedButtonsGroup
|
||||
name="authenticationSettings"
|
||||
reset={() => reset(resource)}
|
||||
isActive
|
||||
isSubmit
|
||||
/>
|
||||
</FormAccess>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { useTranslation } from "react-i18next";
|
||||
import { ActionGroup, ActionGroupProps, Button } from "@patternfly/react-core";
|
||||
import { PropsWithChildren } from "react";
|
||||
|
||||
import style from "./fixed-buttons.module.css";
|
||||
|
||||
|
@ -11,7 +10,7 @@ type FixedButtonGroupProps = ActionGroupProps & {
|
|||
reset?: () => void;
|
||||
resetText?: string;
|
||||
isSubmit?: boolean;
|
||||
isActive?: boolean;
|
||||
isDisabled?: boolean;
|
||||
};
|
||||
|
||||
export const FixedButtonsGroup = ({
|
||||
|
@ -21,16 +20,16 @@ export const FixedButtonsGroup = ({
|
|||
reset,
|
||||
resetText,
|
||||
isSubmit = false,
|
||||
isActive = true,
|
||||
isDisabled = false,
|
||||
children,
|
||||
...rest
|
||||
}: PropsWithChildren<FixedButtonGroupProps>) => {
|
||||
}: FixedButtonGroupProps) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<ActionGroup className={style.buttonGroup} {...rest}>
|
||||
{(save || isSubmit) && (
|
||||
<Button
|
||||
isDisabled={!isActive}
|
||||
isDisabled={isDisabled}
|
||||
data-testid={`${name}-save`}
|
||||
onClick={() => save?.()}
|
||||
type={isSubmit ? "submit" : "button"}
|
||||
|
@ -40,7 +39,7 @@ export const FixedButtonsGroup = ({
|
|||
)}
|
||||
{reset && (
|
||||
<Button
|
||||
isDisabled={!isActive}
|
||||
isDisabled={isDisabled}
|
||||
data-testid={`${name}-revert`}
|
||||
variant="link"
|
||||
onClick={() => reset()}
|
||||
|
|
|
@ -40,7 +40,7 @@ export const AttributesForm = ({
|
|||
<KeyValueInput name={name} isDisabled={isDisabled} />
|
||||
</FormProvider>
|
||||
{!noSaveCancelButtons && (
|
||||
<FixedButtonsGroup name="attributes" reset={reset} isActive isSubmit />
|
||||
<FixedButtonsGroup name="attributes" reset={reset} isSubmit />
|
||||
)}
|
||||
</FormAccess>
|
||||
);
|
||||
|
|
|
@ -268,7 +268,6 @@ function RealmSettingsGeneralTabForm({
|
|||
<FixedButtonsGroup
|
||||
name="realmSettingsGeneralTab"
|
||||
reset={setupForm}
|
||||
isActive
|
||||
isSubmit
|
||||
/>
|
||||
</FormAccess>
|
||||
|
|
|
@ -75,7 +75,7 @@ export const UserFederationLdapForm = ({
|
|||
<Form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<FixedButtonsGroup
|
||||
name="ldap"
|
||||
isActive={form.formState.isDirty}
|
||||
isDisabled={!form.formState.isDirty}
|
||||
isSubmit
|
||||
>
|
||||
<Button
|
||||
|
|
|
@ -144,6 +144,12 @@ export const UserForm = ({
|
|||
}
|
||||
};
|
||||
|
||||
const allFieldsReadOnly = () =>
|
||||
user?.userProfileMetadata?.attributes &&
|
||||
!user?.userProfileMetadata?.attributes
|
||||
?.map((a) => a.readOnly)
|
||||
.reduce((p, c) => p && c, true);
|
||||
|
||||
return (
|
||||
<FormAccess
|
||||
isHorizontal
|
||||
|
@ -342,7 +348,7 @@ export const UserForm = ({
|
|||
saveText={user?.id ? t("save") : t("create")}
|
||||
reset={onFormReset}
|
||||
resetText={user?.id ? t("revert") : t("cancel")}
|
||||
isActive
|
||||
isDisabled={allFieldsReadOnly()}
|
||||
isSubmit
|
||||
/>
|
||||
</FormAccess>
|
||||
|
|
Loading…
Reference in a new issue