Skip to content

Commit c623253

Browse files
committed
refactor: prop renaming
1 parent 6422bdd commit c623253

2 files changed

Lines changed: 9 additions & 10 deletions

File tree

packages/slice-machine/src/features/customTypes/fields/ContentRelationshipFieldPicker.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ export type CustomTypeFieldMap = Record<string, FieldMap>;
1919
type CustomTypeField = { id: string; fields: string[] };
2020

2121
interface ContentRelationshipFieldPickerProps {
22-
value: CustomTypeField[] | undefined;
22+
initialValues: CustomTypeField[] | undefined;
2323
onChange: (fields: CustomTypeField[]) => void;
2424
}
2525

2626
export function ContentRelationshipFieldPicker(
2727
props: ContentRelationshipFieldPickerProps,
2828
) {
29-
const { value, onChange } = props;
29+
const { initialValues, onChange } = props;
3030
const customTypes = useCustomTypes();
3131

3232
const stableOnChange = useStableCallback(onChange);
3333
const form = useFormik<CustomTypeFieldMap>({
34-
initialValues: value ? getInitialValues(value) : {},
34+
initialValues: initialValues ? getInitialValues(initialValues) : {},
3535
onSubmit: () => undefined, // values will be updated on change
3636
});
3737

@@ -163,13 +163,13 @@ function countPickedFields(fields: CustomTypeFieldMap | FieldMap | undefined) {
163163
}
164164

165165
function getInitialValues(value: CustomTypeField[]) {
166-
return value.reduce<CustomTypeFieldMap>((cts, ct) => {
167-
cts[ct.id] = ct.fields.reduce<FieldMap>((fields, field) => {
168-
fields[field] = true;
169-
return fields;
166+
return value.reduce<CustomTypeFieldMap>((customTypes, { id, fields }) => {
167+
customTypes[id] = fields.reduce<FieldMap>((customTypeFields, field) => {
168+
customTypeFields[field] = true;
169+
return customTypeFields;
170170
}, {});
171171

172-
return cts;
172+
return customTypes;
173173
}, {});
174174
}
175175

packages/slice-machine/src/legacy/lib/models/common/widgets/ContentRelationship/Form.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ type FormProps = {
3535
const WidgetForm = ({
3636
initialValues,
3737
setFieldValue,
38-
values,
3938
fields,
4039
}: FormikProps<FormProps> & { fields: Record<string, unknown> }) => {
4140
return (
@@ -56,7 +55,7 @@ const WidgetForm = ({
5655
</FlexGrid>
5756
<Box mt={20}>
5857
<ContentRelationshipFieldPicker
59-
value={values.config.customtypes}
58+
initialValues={initialValues.config.customtypes}
6059
onChange={(fields) => {
6160
void setFieldValue("config.customtypes", fields);
6261
}}

0 commit comments

Comments
 (0)