Skip to content

Commit

Permalink
fix: don't show field loader if no resolver defined
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Oct 7, 2024
1 parent 61e1653 commit 8c706cd
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions packages/core/components/Puck/components/Fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ const useResolvedFields = (): [FieldsType, boolean] => {
? selectedItem
: { props: rootProps, readOnly: data.root.readOnly };

const hasComponentResolver = selectedItem && componentConfig?.resolveFields;
const hasRootResolver = !selectedItem && config.root?.resolveFields;
const hasResolver = hasComponentResolver || hasRootResolver;

const resolveFields = useCallback(
async (fields: FieldsType = {}) => {
const lastData =
Expand All @@ -84,8 +88,8 @@ const useResolvedFields = (): [FieldsType, boolean] => {

setLastSelectedData(componentData);

if (selectedItem && componentConfig?.resolveFields) {
return await componentConfig?.resolveFields(
if (hasComponentResolver) {
return await componentConfig!.resolveFields!(
componentData as ComponentData,
{
changed,
Expand All @@ -97,8 +101,8 @@ const useResolvedFields = (): [FieldsType, boolean] => {
);
}

if (!selectedItem && config.root?.resolveFields) {
return await config.root?.resolveFields(componentData, {
if (hasRootResolver) {
return await config.root!.resolveFields!(componentData, {
changed,
fields,
lastFields: resolvedFields,
Expand All @@ -118,14 +122,18 @@ const useResolvedFields = (): [FieldsType, boolean] => {
);

useEffect(() => {
setFieldsLoading(true);
if (hasResolver) {
setFieldsLoading(true);

resolveFields(defaultFields).then((fields) => {
setResolvedFields(fields || {});
resolveFields(defaultFields).then((fields) => {
setResolvedFields(fields || {});

setFieldsLoading(false);
});
}, [data, defaultFields, state.ui.itemSelector]);
setFieldsLoading(false);
});
} else {
setResolvedFields(defaultFields);
}
}, [data, defaultFields, state.ui.itemSelector, hasResolver]);

return [resolvedFields, fieldsLoading];
};
Expand Down

0 comments on commit 8c706cd

Please sign in to comment.