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