Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced isDisabled at the AttributeValueField components and its sub-ordinate ones #1323

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions frontend/src/components/entry/entryForm/AttributeValueField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,32 @@ interface Props {
setValue: UseFormSetValue<Schema>;
type: number;
schemaId: number;
isDisabled?: boolean;
}

export const AttributeValueField: FC<Props> = ({
control,
setValue,
type,
schemaId,
isDisabled = false,
}) => {
switch (type) {
case EntryAttributeTypeTypeEnum.STRING:
return <StringAttributeValueField control={control} attrId={schemaId} />;
return (
<StringAttributeValueField
control={control}
attrId={schemaId}
isDisabled={isDisabled}
/>
);

case EntryAttributeTypeTypeEnum.TEXT:
return (
<StringAttributeValueField
control={control}
attrId={schemaId}
isDisabled={isDisabled}
multiline
/>
);
Expand All @@ -51,6 +60,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

Expand All @@ -60,18 +70,26 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

case EntryAttributeTypeTypeEnum.BOOLEAN:
return <BooleanAttributeValueField attrId={schemaId} control={control} />;
return (
<BooleanAttributeValueField
attrId={schemaId}
control={control}
isDisabled={isDisabled}
/>
);

case EntryAttributeTypeTypeEnum.OBJECT:
return (
<ObjectAttributeValueField
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

Expand All @@ -81,6 +99,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

Expand All @@ -90,6 +109,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

Expand All @@ -99,6 +119,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

Expand All @@ -108,6 +129,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
multiple
/>
);
Expand All @@ -118,6 +140,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
multiple
/>
);
Expand All @@ -128,6 +151,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
multiple
/>
);
Expand All @@ -143,6 +167,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
/>
);

Expand All @@ -152,6 +177,7 @@ export const AttributeValueField: FC<Props> = ({
attrId={schemaId}
control={control}
setValue={setValue}
isDisabled={isDisabled}
withBoolean
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ import { Schema } from "./EntryFormSchema";
interface Props {
attrId: number;
control: Control<Schema>;
isDisabled?: boolean;
}

export const BooleanAttributeValueField: FC<Props> = ({ attrId, control }) => {
export const BooleanAttributeValueField: FC<Props> = ({
attrId,
control,
isDisabled = false,
}) => {
return (
<Controller
name={`attrs.${attrId}.value.asBoolean`}
Expand All @@ -19,6 +24,7 @@ export const BooleanAttributeValueField: FC<Props> = ({ attrId, control }) => {
<Checkbox
checked={field.value}
onChange={(e) => field.onChange(e.target.checked)}
disabled={isDisabled}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ interface Props {
attrId: number;
control: Control<Schema>;
setValue: UseFormSetValue<Schema>;
isDisabled?: boolean;
}

export const DateAttributeValueField: FC<Props> = ({
attrId,
control,
setValue,
isDisabled = false,
}) => {
return (
<StyledBox>
Expand Down Expand Up @@ -63,6 +65,7 @@ export const DateAttributeValueField: FC<Props> = ({
fullWidth={false}
/>
)}
disabled={isDisabled}
/>
</LocalizationProvider>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ interface Props {
attrId: number;
control: Control<Schema>;
setValue: UseFormSetValue<Schema>;
isDisabled?: boolean;
}

export const DateTimeAttributeValueField: FC<Props> = ({
attrId,
control,
setValue,
isDisabled = false,
}) => {
return (
<StyledBox>
Expand Down Expand Up @@ -66,6 +68,7 @@ export const DateTimeAttributeValueField: FC<Props> = ({
fullWidth={false}
/>
)}
disabled={isDisabled}
/>
</LocalizationProvider>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ interface Props {
control: Control<Schema>;
setValue: UseFormSetValue<Schema>;
multiple?: boolean;
isDisabled?: boolean;
}

export const GroupAttributeValueField: FC<Props> = ({
multiple,
attrId,
control,
setValue,
isDisabled = false,
}) => {
const groups = useAsyncWithThrow(async () => {
const _groups = await aironeApiClient.getGroups();
Expand Down Expand Up @@ -90,6 +92,7 @@ export const GroupAttributeValueField: FC<Props> = ({
placeholder={multiple ? "" : "-NOT SET-"}
/>
)}
disabled={isDisabled}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ interface CommonProps {
attrId: number;
control: Control<Schema>;
setValue: UseFormSetValue<Schema>;
isDisabled?: boolean;
}

export const ObjectAttributeValueField: FC<
CommonProps & {
multiple?: boolean;
}
> = ({ multiple, attrId, control, setValue }) => {
> = ({ multiple, attrId, control, setValue, isDisabled = false }) => {
const handleChange = (
value: GetEntryAttrReferral | GetEntryAttrReferral[] | null
) => {
Expand Down Expand Up @@ -116,6 +117,7 @@ export const ObjectAttributeValueField: FC<
handleChange={handleChange}
multiple={multiple}
error={error}
isDisabled={isDisabled}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ interface Props {
) => void;
multiple?: boolean;
error?: { message?: string };
isDisabled?: boolean;
}

export const ReferralsAutocomplete: FC<Props> = ({
Expand All @@ -27,6 +28,7 @@ export const ReferralsAutocomplete: FC<Props> = ({
handleChange,
multiple,
error,
isDisabled = false,
}) => {
const [inputValue, setInputValue] = useState<string>(
!multiple ? (value as GetEntryAttrReferral | null)?.name ?? "" : ""
Expand Down Expand Up @@ -95,6 +97,7 @@ export const ReferralsAutocomplete: FC<Props> = ({
helperText={error?.message}
size="small"
placeholder={multiple ? "" : "-NOT SET-"}
disabled={isDisabled}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ interface Props {
control: Control<Schema>;
setValue: UseFormSetValue<Schema>;
multiple?: boolean;
isDisabled?: boolean;
}

export const RoleAttributeValueField: FC<Props> = ({
multiple,
attrId,
control,
setValue,
isDisabled = false,
}) => {
const roles = useAsyncWithThrow(async () => {
const _roles = await aironeApiClient.getRoles();
Expand Down Expand Up @@ -88,8 +90,10 @@ export const RoleAttributeValueField: FC<Props> = ({
helperText={error?.message}
size="small"
placeholder={multiple ? "" : "-NOT SET-"}
disabled={isDisabled}
/>
)}
disabled={isDisabled}
/>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface CommonProps {
attrId: number;
index?: number;
control: Control<Schema>;
isDisabled?: boolean;
}

export const StringAttributeValueField: FC<
Expand All @@ -36,6 +37,7 @@ export const StringAttributeValueField: FC<
handleClickDeleteListItem,
handleClickAddListItem,
multiline,
isDisabled = false,
}) => {
return (
<StyledBox>
Expand All @@ -56,6 +58,7 @@ export const StringAttributeValueField: FC<
fullWidth
multiline={multiline}
minRows={multiline === true ? 5 : 1}
disabled={isDisabled}
/>
)}
/>
Expand Down
Loading