diff --git a/packages/core/admin/admin/src/content-manager/components/RelationInput/RelationInput.js b/packages/core/admin/admin/src/content-manager/components/RelationInput/RelationInput.js index d3287ac42f..0aa18d5014 100644 --- a/packages/core/admin/admin/src/content-manager/components/RelationInput/RelationInput.js +++ b/packages/core/admin/admin/src/content-manager/components/RelationInput/RelationInput.js @@ -98,11 +98,15 @@ const RelationInput = ({ const options = useMemo( () => - data.flat().map((result) => ({ - ...result, - value: result.id, - label: result.mainField, - })), + data.flat().map((result) => + result + ? { + ...result, + value: result.id, + label: result.mainField, + } + : result + ), [data] ); diff --git a/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js b/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js index 3b9a17b0fd..04d12592b6 100644 --- a/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js +++ b/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/RelationInputDataManager.js @@ -18,6 +18,7 @@ import { connect, select, normalizeSearchResults, diffRelations, normalizeRelati export const RelationInputDataManager = ({ error, componentId, + isComponentRelation, editable, description, intlLabel, @@ -64,7 +65,8 @@ export const RelationInputDataManager = ({ endpoint: endpoints.search, pageParams: { ...defaultParams, - entityId: isCreatingEntry ? undefined : componentId ?? initialData.id, + // eslint-disable-next-line no-nested-ternary + entityId: isCreatingEntry ? undefined : isComponentRelation ? componentId : initialData.id, pageSize: SEARCH_RESULTS_TO_DISPLAY, }, }, @@ -212,6 +214,7 @@ RelationInputDataManager.defaultProps = { error: undefined, description: '', labelAction: null, + isComponentRelation: false, isFieldAllowed: true, placeholder: null, required: false, @@ -229,6 +232,7 @@ RelationInputDataManager.propTypes = { }).isRequired, labelAction: PropTypes.element, isCreatingEntry: PropTypes.bool.isRequired, + isComponentRelation: PropTypes.bool, isFieldAllowed: PropTypes.bool, isFieldReadable: PropTypes.bool.isRequired, mainField: PropTypes.shape({ diff --git a/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/utils/select.js b/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/utils/select.js index c5d1b07d19..3948361968 100644 --- a/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/utils/select.js +++ b/packages/core/admin/admin/src/content-manager/components/RelationInputDataManager/utils/select.js @@ -82,6 +82,7 @@ function useSelect({ return { componentId, + isComponentRelation: Boolean(componentUid), queryInfos: { ...queryInfos, endpoints: {