refactor: tidy up entityId

This commit is contained in:
Josh 2022-11-02 14:59:41 +00:00
parent c1f8d20245
commit cabfa37ff3
3 changed files with 15 additions and 6 deletions

View File

@ -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]
);

View File

@ -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({

View File

@ -82,6 +82,7 @@ function useSelect({
return {
componentId,
isComponentRelation: Boolean(componentUid),
queryInfos: {
...queryInfos,
endpoints: {