mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 11:25:17 +00:00
share componentId through select
This commit is contained in:
parent
d90073a8e1
commit
35afaa675a
@ -12,7 +12,7 @@ import { PUBLICATION_STATES, RELATIONS_TO_DISPLAY, SEARCH_RESULTS_TO_DISPLAY } f
|
||||
import { getTrad } from '../../utils';
|
||||
|
||||
export const RelationInputDataManager = ({
|
||||
componentUid,
|
||||
componentId,
|
||||
editable,
|
||||
description,
|
||||
intlLabel,
|
||||
@ -33,14 +33,6 @@ export const RelationInputDataManager = ({
|
||||
const { connectRelation, disconnectRelation, loadRelation, modifiedData, slug, initialData } =
|
||||
useCMEditViewDataManager();
|
||||
|
||||
const getEntityId = () => {
|
||||
if (componentUid) {
|
||||
return get(initialData, name.split('.').slice(0, -1))?.id;
|
||||
}
|
||||
|
||||
return initialData.id;
|
||||
};
|
||||
|
||||
const { relations, search, searchFor } = useRelation(`${slug}-${name}-${initialData?.id ?? ''}`, {
|
||||
relation: {
|
||||
enabled: get(initialData, name)?.count !== 0 && !!endpoints.relation,
|
||||
@ -55,7 +47,7 @@ export const RelationInputDataManager = ({
|
||||
endpoint: endpoints.search,
|
||||
pageParams: {
|
||||
...defaultParams,
|
||||
entityId: isCreatingEntry ? undefined : getEntityId(),
|
||||
entityId: isCreatingEntry ? undefined : componentId ?? initialData.id,
|
||||
pageSize: SEARCH_RESULTS_TO_DISPLAY,
|
||||
},
|
||||
},
|
||||
@ -213,7 +205,7 @@ export const RelationInputDataManager = ({
|
||||
};
|
||||
|
||||
RelationInputDataManager.defaultProps = {
|
||||
componentUid: undefined,
|
||||
componentId: undefined,
|
||||
editable: true,
|
||||
description: '',
|
||||
labelAction: null,
|
||||
@ -223,7 +215,7 @@ RelationInputDataManager.defaultProps = {
|
||||
};
|
||||
|
||||
RelationInputDataManager.propTypes = {
|
||||
componentUid: PropTypes.string,
|
||||
componentId: PropTypes.number,
|
||||
editable: PropTypes.bool,
|
||||
description: PropTypes.string,
|
||||
intlLabel: PropTypes.shape({
|
||||
|
||||
@ -46,6 +46,13 @@ function useSelect({
|
||||
return allowedFields.includes(name);
|
||||
}, [isCreatingEntry, isUserAllowedToReadField, name, readActionAllowedFields]);
|
||||
|
||||
const fieldNameKeys = name.split('.');
|
||||
let componentId;
|
||||
|
||||
if (componentUid) {
|
||||
componentId = get(initialData, fieldNameKeys.slice(0, -1))?.id;
|
||||
}
|
||||
|
||||
// /content-manager/relations/[model]/[id]/[field-name]
|
||||
const relationFetchEndpoint = useMemo(() => {
|
||||
if (isCreatingEntry) {
|
||||
@ -53,9 +60,6 @@ function useSelect({
|
||||
}
|
||||
|
||||
if (componentUid) {
|
||||
const fieldNameKeys = name.split('.');
|
||||
const componentId = get(initialData, fieldNameKeys.slice(0, -1))?.id;
|
||||
|
||||
// repeatable components and dz are dynamically created
|
||||
// if no componentId exists in initialData it means that the user just created it
|
||||
// there then are no relations to request
|
||||
@ -65,7 +69,7 @@ function useSelect({
|
||||
}
|
||||
|
||||
return getRequestUrl(`relations/${slug}/${initialData.id}/${name.split('.').at(-1)}`);
|
||||
}, [isCreatingEntry, slug, initialData, name, componentUid]);
|
||||
}, [isCreatingEntry, componentUid, slug, initialData.id, name, componentId, fieldNameKeys]);
|
||||
|
||||
// /content-manager/relations/[model]/[field-name]
|
||||
const relationSearchEndpoint = useMemo(() => {
|
||||
@ -77,6 +81,7 @@ function useSelect({
|
||||
}, [componentUid, slug, name]);
|
||||
|
||||
return {
|
||||
componentId,
|
||||
queryInfos: {
|
||||
...queryInfos,
|
||||
endpoints: {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user