Skip to content

Commit 9b0db30

Browse files
committed
Introduced isDisabled at the AttributeValueField components and its sub-ordinate ones
The `isDisabled` parameter is humble, not be forward usually. When an attribute want to be prohibited to change but just showing, this parameter is useful for its use-case.
1 parent 4ffce74 commit 9b0db30

9 files changed

+57
-4
lines changed

frontend/src/components/entry/entryForm/AttributeValueField.tsx

+28-2
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,32 @@ interface Props {
2424
setValue: UseFormSetValue<Schema>;
2525
type: number;
2626
schemaId: number;
27+
isDisabled?: boolean;
2728
}
2829

2930
export const AttributeValueField: FC<Props> = ({
3031
control,
3132
setValue,
3233
type,
3334
schemaId,
35+
isDisabled = false,
3436
}) => {
3537
switch (type) {
3638
case EntryAttributeTypeTypeEnum.STRING:
37-
return <StringAttributeValueField control={control} attrId={schemaId} />;
39+
return (
40+
<StringAttributeValueField
41+
control={control}
42+
attrId={schemaId}
43+
isDisabled={isDisabled}
44+
/>
45+
);
3846

3947
case EntryAttributeTypeTypeEnum.TEXT:
4048
return (
4149
<StringAttributeValueField
4250
control={control}
4351
attrId={schemaId}
52+
isDisabled={isDisabled}
4453
multiline
4554
/>
4655
);
@@ -51,6 +60,7 @@ export const AttributeValueField: FC<Props> = ({
5160
attrId={schemaId}
5261
control={control}
5362
setValue={setValue}
63+
isDisabled={isDisabled}
5464
/>
5565
);
5666

@@ -60,18 +70,26 @@ export const AttributeValueField: FC<Props> = ({
6070
attrId={schemaId}
6171
control={control}
6272
setValue={setValue}
73+
isDisabled={isDisabled}
6374
/>
6475
);
6576

6677
case EntryAttributeTypeTypeEnum.BOOLEAN:
67-
return <BooleanAttributeValueField attrId={schemaId} control={control} />;
78+
return (
79+
<BooleanAttributeValueField
80+
attrId={schemaId}
81+
control={control}
82+
isDisabled={isDisabled}
83+
/>
84+
);
6885

6986
case EntryAttributeTypeTypeEnum.OBJECT:
7087
return (
7188
<ObjectAttributeValueField
7289
attrId={schemaId}
7390
control={control}
7491
setValue={setValue}
92+
isDisabled={isDisabled}
7593
/>
7694
);
7795

@@ -81,6 +99,7 @@ export const AttributeValueField: FC<Props> = ({
8199
attrId={schemaId}
82100
control={control}
83101
setValue={setValue}
102+
isDisabled={isDisabled}
84103
/>
85104
);
86105

@@ -90,6 +109,7 @@ export const AttributeValueField: FC<Props> = ({
90109
attrId={schemaId}
91110
control={control}
92111
setValue={setValue}
112+
isDisabled={isDisabled}
93113
/>
94114
);
95115

@@ -99,6 +119,7 @@ export const AttributeValueField: FC<Props> = ({
99119
attrId={schemaId}
100120
control={control}
101121
setValue={setValue}
122+
isDisabled={isDisabled}
102123
/>
103124
);
104125

@@ -108,6 +129,7 @@ export const AttributeValueField: FC<Props> = ({
108129
attrId={schemaId}
109130
control={control}
110131
setValue={setValue}
132+
isDisabled={isDisabled}
111133
multiple
112134
/>
113135
);
@@ -118,6 +140,7 @@ export const AttributeValueField: FC<Props> = ({
118140
attrId={schemaId}
119141
control={control}
120142
setValue={setValue}
143+
isDisabled={isDisabled}
121144
multiple
122145
/>
123146
);
@@ -128,6 +151,7 @@ export const AttributeValueField: FC<Props> = ({
128151
attrId={schemaId}
129152
control={control}
130153
setValue={setValue}
154+
isDisabled={isDisabled}
131155
multiple
132156
/>
133157
);
@@ -143,6 +167,7 @@ export const AttributeValueField: FC<Props> = ({
143167
attrId={schemaId}
144168
control={control}
145169
setValue={setValue}
170+
isDisabled={isDisabled}
146171
/>
147172
);
148173

@@ -152,6 +177,7 @@ export const AttributeValueField: FC<Props> = ({
152177
attrId={schemaId}
153178
control={control}
154179
setValue={setValue}
180+
isDisabled={isDisabled}
155181
withBoolean
156182
/>
157183
);

frontend/src/components/entry/entryForm/BooleanAttributeValueField.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ import { Schema } from "./EntryFormSchema";
77
interface Props {
88
attrId: number;
99
control: Control<Schema>;
10+
isDisabled?: boolean;
1011
}
1112

12-
export const BooleanAttributeValueField: FC<Props> = ({ attrId, control }) => {
13+
export const BooleanAttributeValueField: FC<Props> = ({
14+
attrId,
15+
control,
16+
isDisabled = false,
17+
}) => {
1318
return (
1419
<Controller
1520
name={`attrs.${attrId}.value.asBoolean`}
@@ -19,6 +24,7 @@ export const BooleanAttributeValueField: FC<Props> = ({ attrId, control }) => {
1924
<Checkbox
2025
checked={field.value}
2126
onChange={(e) => field.onChange(e.target.checked)}
27+
disabled={isDisabled}
2228
/>
2329
)}
2430
/>

frontend/src/components/entry/entryForm/DateAttributeValueField.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ interface Props {
2323
attrId: number;
2424
control: Control<Schema>;
2525
setValue: UseFormSetValue<Schema>;
26+
isDisabled?: boolean;
2627
}
2728

2829
export const DateAttributeValueField: FC<Props> = ({
2930
attrId,
3031
control,
3132
setValue,
33+
isDisabled = false,
3234
}) => {
3335
return (
3436
<StyledBox>
@@ -63,6 +65,7 @@ export const DateAttributeValueField: FC<Props> = ({
6365
fullWidth={false}
6466
/>
6567
)}
68+
disabled={isDisabled}
6669
/>
6770
</LocalizationProvider>
6871
)}

frontend/src/components/entry/entryForm/DateTimeAttributeValueField.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ interface Props {
2323
attrId: number;
2424
control: Control<Schema>;
2525
setValue: UseFormSetValue<Schema>;
26+
isDisabled?: boolean;
2627
}
2728

2829
export const DateTimeAttributeValueField: FC<Props> = ({
2930
attrId,
3031
control,
3132
setValue,
33+
isDisabled = false,
3234
}) => {
3335
return (
3436
<StyledBox>
@@ -66,6 +68,7 @@ export const DateTimeAttributeValueField: FC<Props> = ({
6668
fullWidth={false}
6769
/>
6870
)}
71+
disabled={isDisabled}
6972
/>
7073
</LocalizationProvider>
7174
)}

frontend/src/components/entry/entryForm/GroupAttributeValueField.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ interface Props {
2323
control: Control<Schema>;
2424
setValue: UseFormSetValue<Schema>;
2525
multiple?: boolean;
26+
isDisabled?: boolean;
2627
}
2728

2829
export const GroupAttributeValueField: FC<Props> = ({
2930
multiple,
3031
attrId,
3132
control,
3233
setValue,
34+
isDisabled = false,
3335
}) => {
3436
const groups = useAsyncWithThrow(async () => {
3537
const _groups = await aironeApiClient.getGroups();
@@ -90,6 +92,7 @@ export const GroupAttributeValueField: FC<Props> = ({
9092
placeholder={multiple ? "" : "-NOT SET-"}
9193
/>
9294
)}
95+
disabled={isDisabled}
9396
/>
9497
)}
9598
/>

frontend/src/components/entry/entryForm/ObjectAttributeValueField.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ interface CommonProps {
5757
attrId: number;
5858
control: Control<Schema>;
5959
setValue: UseFormSetValue<Schema>;
60+
isDisabled?: boolean;
6061
}
6162

6263
export const ObjectAttributeValueField: FC<
6364
CommonProps & {
6465
multiple?: boolean;
6566
}
66-
> = ({ multiple, attrId, control, setValue }) => {
67+
> = ({ multiple, attrId, control, setValue, isDisabled = false }) => {
6768
const handleChange = (
6869
value: GetEntryAttrReferral | GetEntryAttrReferral[] | null
6970
) => {
@@ -116,6 +117,7 @@ export const ObjectAttributeValueField: FC<
116117
handleChange={handleChange}
117118
multiple={multiple}
118119
error={error}
120+
isDisabled={isDisabled}
119121
/>
120122
)}
121123
/>

frontend/src/components/entry/entryForm/ReferralsAutocomplete.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface Props {
1919
) => void;
2020
multiple?: boolean;
2121
error?: { message?: string };
22+
isDisabled?: boolean;
2223
}
2324

2425
export const ReferralsAutocomplete: FC<Props> = ({
@@ -27,6 +28,7 @@ export const ReferralsAutocomplete: FC<Props> = ({
2728
handleChange,
2829
multiple,
2930
error,
31+
isDisabled = false,
3032
}) => {
3133
const [inputValue, setInputValue] = useState<string>(
3234
!multiple ? (value as GetEntryAttrReferral | null)?.name ?? "" : ""
@@ -95,6 +97,7 @@ export const ReferralsAutocomplete: FC<Props> = ({
9597
helperText={error?.message}
9698
size="small"
9799
placeholder={multiple ? "" : "-NOT SET-"}
100+
disabled={isDisabled}
98101
/>
99102
)}
100103
/>

frontend/src/components/entry/entryForm/RoleAttributeValueField.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ interface Props {
2323
control: Control<Schema>;
2424
setValue: UseFormSetValue<Schema>;
2525
multiple?: boolean;
26+
isDisabled?: boolean;
2627
}
2728

2829
export const RoleAttributeValueField: FC<Props> = ({
2930
multiple,
3031
attrId,
3132
control,
3233
setValue,
34+
isDisabled = false,
3335
}) => {
3436
const roles = useAsyncWithThrow(async () => {
3537
const _roles = await aironeApiClient.getRoles();
@@ -88,8 +90,10 @@ export const RoleAttributeValueField: FC<Props> = ({
8890
helperText={error?.message}
8991
size="small"
9092
placeholder={multiple ? "" : "-NOT SET-"}
93+
disabled={isDisabled}
9194
/>
9295
)}
96+
disabled={isDisabled}
9397
/>
9498
)}
9599
/>

frontend/src/components/entry/entryForm/StringAttributeValueField.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface CommonProps {
2121
attrId: number;
2222
index?: number;
2323
control: Control<Schema>;
24+
isDisabled?: boolean;
2425
}
2526

2627
export const StringAttributeValueField: FC<
@@ -36,6 +37,7 @@ export const StringAttributeValueField: FC<
3637
handleClickDeleteListItem,
3738
handleClickAddListItem,
3839
multiline,
40+
isDisabled = false,
3941
}) => {
4042
return (
4143
<StyledBox>
@@ -56,6 +58,7 @@ export const StringAttributeValueField: FC<
5658
fullWidth
5759
multiline={multiline}
5860
minRows={multiline === true ? 5 : 1}
61+
disabled={isDisabled}
5962
/>
6063
)}
6164
/>

0 commit comments

Comments
 (0)