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( const options = useMemo(
() => () =>
data.flat().map((result) => ({ data.flat().map((result) =>
result
? {
...result, ...result,
value: result.id, value: result.id,
label: result.mainField, label: result.mainField,
})), }
: result
),
[data] [data]
); );

View File

@ -18,6 +18,7 @@ import { connect, select, normalizeSearchResults, diffRelations, normalizeRelati
export const RelationInputDataManager = ({ export const RelationInputDataManager = ({
error, error,
componentId, componentId,
isComponentRelation,
editable, editable,
description, description,
intlLabel, intlLabel,
@ -64,7 +65,8 @@ export const RelationInputDataManager = ({
endpoint: endpoints.search, endpoint: endpoints.search,
pageParams: { pageParams: {
...defaultParams, ...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, pageSize: SEARCH_RESULTS_TO_DISPLAY,
}, },
}, },
@ -212,6 +214,7 @@ RelationInputDataManager.defaultProps = {
error: undefined, error: undefined,
description: '', description: '',
labelAction: null, labelAction: null,
isComponentRelation: false,
isFieldAllowed: true, isFieldAllowed: true,
placeholder: null, placeholder: null,
required: false, required: false,
@ -229,6 +232,7 @@ RelationInputDataManager.propTypes = {
}).isRequired, }).isRequired,
labelAction: PropTypes.element, labelAction: PropTypes.element,
isCreatingEntry: PropTypes.bool.isRequired, isCreatingEntry: PropTypes.bool.isRequired,
isComponentRelation: PropTypes.bool,
isFieldAllowed: PropTypes.bool, isFieldAllowed: PropTypes.bool,
isFieldReadable: PropTypes.bool.isRequired, isFieldReadable: PropTypes.bool.isRequired,
mainField: PropTypes.shape({ mainField: PropTypes.shape({

View File

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