Skip to content

Commit

Permalink
fix: custom fields values resetting in ui (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens authored Jun 8, 2022
1 parent 7fe2fec commit f2bf239
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import React from 'react';
import { Props } from './types';
import withCondition from '../../forms/withCondition';

const RenderCustomComponent: React.FC<Props> = (props) => {
const { CustomComponent, DefaultComponent, componentProps } = props;

if (CustomComponent) {
const ConditionalCustomComponent = withCondition(CustomComponent);
return (
<ConditionalCustomComponent {...componentProps} />
<CustomComponent {...componentProps} />
);
}

Expand Down
9 changes: 8 additions & 1 deletion src/fields/config/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { baseBlockFields } from '../baseFields/baseBlockFields';
import validations from '../validations';
import { baseIDField } from '../baseFields/baseIDField';
import { Field, fieldAffectsData } from './types';
import withCondition from '../../admin/components/forms/withCondition';

const sanitizeFields = (fields: Field[], validRelationships: string[]): Field[] => {
if (!fields) return [];
Expand Down Expand Up @@ -57,7 +58,13 @@ const sanitizeFields = (fields: Field[], validRelationships: string[]): Field[]
if (!field.access) field.access = {};
}

if (!field.admin) field.admin = {};
if (field.admin) {
if (field.admin.condition && field.admin.components?.Field) {
field.admin.components.Field = withCondition(field.admin.components?.Field);
}
} else {
field.admin = {};
}

if ('fields' in field && field.fields) field.fields = sanitizeFields(field.fields, validRelationships);

Expand Down

0 comments on commit f2bf239

Please sign in to comment.