Skip to content

Commit

Permalink
#872 - set default values in fields field type
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Oct 23, 2024
1 parent ea9f8a2 commit c40fcba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/panelWebView/components/Fields/FieldCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export interface IFieldCollectionProps {
parentFields: string[],
blockData?: BlockFieldData,
onFieldUpdate?: (field: string | undefined, value: any, parents: string[]) => void,
parentBlock?: string | null
parentBlock?: string | null,
triggerUpdateOnDefault?: boolean
) => (JSX.Element | null)[] | undefined;
onChange: (field: string | undefined, value: any, parents: string[]) => void;
}
Expand Down
17 changes: 12 additions & 5 deletions src/panelWebView/components/Fields/WrapperField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ export interface IWrapperFieldProps {
parentFields: string[],
blockData?: BlockFieldData,
onFieldUpdate?: (field: string | undefined, value: any, parents: string[]) => void,
parentBlock?: string | null
parentBlock?: string | null,
triggerUpdateOnDefault?: boolean
) => (JSX.Element | null)[] | undefined;
triggerUpdateOnDefault?: boolean;
}

export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
Expand All @@ -72,7 +74,8 @@ export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
parentBlock,
onSendUpdate,
unsetFocus,
renderFields
renderFields,
triggerUpdateOnDefault
}: React.PropsWithChildren<IWrapperFieldProps>) => {
const [fieldValue, setFieldValue] = useState<any | undefined>(undefined);
const [customFields, setCustomFields] = useState<{
Expand Down Expand Up @@ -110,7 +113,9 @@ export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
value = getDate(value) || null;
}

//onSendUpdate(field.name, value, parentFields);
if (triggerUpdateOnDefault) {
onSendUpdate(field.name, value, parentFields);
}
}

// Check if the field value contains a placeholder
Expand Down Expand Up @@ -140,7 +145,7 @@ export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
}
}
}
}, [field, parent]);
}, [field, parent, triggerUpdateOnDefault]);

useEffect(() => {
if (window.fmExternal && window.fmExternal.getCustomFields) {
Expand Down Expand Up @@ -437,7 +442,9 @@ export const WrapperField: React.FunctionComponent<IWrapperFieldProps> = ({
subMetadata,
[...parentFields, field.name],
blockData,
onSendUpdate
onSendUpdate,
null,
true
)}
</div>
</FieldBoundary>
Expand Down
4 changes: 3 additions & 1 deletion src/panelWebView/components/Metadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const Metadata: React.FunctionComponent<IMetadataProps> = ({
blockData?: BlockFieldData,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onFieldUpdate?: (field: string | undefined, value: any, parents: string[]) => void,
parentBlock?: string | null
parentBlock?: string | null,
triggerUpdateOnDefault?: boolean
): (JSX.Element | null)[] | undefined => {
if (!ctFields || !settings) {
return;
Expand All @@ -83,6 +84,7 @@ const Metadata: React.FunctionComponent<IMetadataProps> = ({
onSendUpdate={onFieldUpdate || onSendUpdate}
unsetFocus={unsetFocus}
renderFields={renderFields}
triggerUpdateOnDefault={triggerUpdateOnDefault}
/>
));
};
Expand Down

0 comments on commit c40fcba

Please sign in to comment.