Skip to content

Commit

Permalink
Issue: Media used as fieldGroup inside a fieldGroup not working #590
Browse files Browse the repository at this point in the history
  • Loading branch information
estruyf committed Jun 30, 2023
1 parent 313d2ef commit a041d82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/helpers/ContentType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,6 @@ export class ContentType {

if (newParents.length > 0) {
found = true;
return newParents;
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions src/listeners/panel/DataListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,14 @@ export class DataListener extends BaseListener {
let parentObj = data;
let allParents = Object.assign([], parents);
const contentType = ArticleHelper.getContentType(article.data);
const selectedIndexes =
typeof blockData?.selectedIndex === 'string'
? blockData?.selectedIndex.split('.').map((v) => parseInt(v))
: [blockData?.selectedIndex];
let selectedIndexes: number[] = [];
if (blockData?.selectedIndex) {
if (typeof blockData.selectedIndex === 'string') {
selectedIndexes = blockData.selectedIndex.split('.').map((v) => parseInt(v));
} else {
selectedIndexes = [blockData.selectedIndex];
}
}
let lastSelectedIndex: number | undefined;

// Add support for block fields
Expand All @@ -291,7 +295,7 @@ export class DataListener extends BaseListener {
// Loop through the parents of the block field
for (const parent of blockData?.parentFields) {
if (!parentObj[parent]) {
parentObj[parent] = {};
parentObj[parent] = [];
}

if (allParents[0] && allParents[0] === parent) {
Expand Down
6 changes: 4 additions & 2 deletions src/panelWebView/components/Fields/PreviewImageField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const PreviewImageField: React.FunctionComponent<IPreviewImageFieldProps>
blockData,
type: 'media'
});
}, [filePath, fieldName, value, multiple, parents]);
}, [filePath, fieldName, multiple, parents, value]);

const onImageRemove = useCallback((imageToRemove: string) => {
const newValue =
Expand Down Expand Up @@ -84,10 +84,12 @@ export const PreviewImageField: React.FunctionComponent<IPreviewImageFieldProps>
).then((data) => {
setImageData(data);
});
} else if (!value) {
setImageData(multiple ? [] : null);
} else {
setImageData(value);
}
}, [value]);
}, [value, multiple]);

return (
<div className={`metadata_field`}>
Expand Down

0 comments on commit a041d82

Please sign in to comment.