Skip to content

Commit

Permalink
Fix selected item not found issues on internal link (#2695)
Browse files Browse the repository at this point in the history
  • Loading branch information
agalin920 authored Apr 29, 2024
1 parent cb5cb67 commit 42f57a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
5 changes: 4 additions & 1 deletion src/apps/content-editor/src/app/components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ export default memo(function Editor({
});
}

if (field?.settings?.defaultValue !== null) {
if (
field?.settings?.defaultValue !== null &&
field?.settings?.defaultValue !== undefined
) {
dispatch({
type: "SET_ITEM_DATA",
itemZUID: itemZUID,
Expand Down
25 changes: 12 additions & 13 deletions src/apps/content-editor/src/app/components/Editor/Field/Field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ export const Field = ({
case "internal_link":
let internalLinkRelatedItem = allItems[value];
let internalLinkOptions = useMemo(() => {
return Object.keys(allItems)
const options = Object.keys(allItems)
.filter(
(itemZUID) =>
!itemZUID.includes("new") && // exclude new items
Expand Down Expand Up @@ -656,19 +656,18 @@ export const Field = ({
};
})
.sort(sortHTML);
}, [internalLinkRelatedItem, Object.keys(allItems).length]);

if (
!internalLinkRelatedItem ||
!internalLinkRelatedItem.meta ||
!internalLinkRelatedItem.meta.ZUID
) {
// insert placeholder
internalLinkOptions.unshift({
value: value as string,
html: `Selected item not found: ${value}`,
});
}
// if the selected item is not found, insert a placeholder
if (internalLinkRelatedItem && !internalLinkRelatedItem?.meta?.ZUID) {
// insert placeholder
options.unshift({
value: value as string,
html: `Selected item not found: ${value}`,
});
}

return options;
}, [internalLinkRelatedItem, Object.keys(allItems).length]);

const onInternalLinkSearch = useCallback(
(term) => dispatch(searchItems(term)),
Expand Down

0 comments on commit 42f57a3

Please sign in to comment.