mirror of
https://github.com/strapi/strapi.git
synced 2025-11-08 14:19:40 +00:00
Merge pull request #14402 from strapi/feature/relations-main-view-components
RelationInputWrapper: Fix and properly transform query params for components
This commit is contained in:
commit
a72197c78a
@ -48,12 +48,14 @@ function useSelect({ isUserAllowedToEditField, isUserAllowedToReadField, name, q
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getRequestUrl(`${collectionTypePrefix}/${slug}/${initialData.id}/${name}`);
|
return getRequestUrl(
|
||||||
|
`${collectionTypePrefix}/${slug}/${initialData.id}/${name.split('.').at(-1)}`
|
||||||
|
);
|
||||||
}, [isCreatingEntry, slug, initialData, name, isSingleType]);
|
}, [isCreatingEntry, slug, initialData, name, isSingleType]);
|
||||||
|
|
||||||
// /content-manager/relations/[content-type]/[field-name]
|
// /content-manager/relations/[content-type]/[field-name]
|
||||||
const relationSearchEndpoint = useMemo(() => {
|
const relationSearchEndpoint = useMemo(() => {
|
||||||
return getRequestUrl(`relations/${slug}/${name}`);
|
return getRequestUrl(`relations/${slug}/${name.split('.').at(-1)}`);
|
||||||
}, [slug, name]);
|
}, [slug, name]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -163,4 +163,23 @@ describe('RelationInputWrapper | select', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('splits the name properly, so that components are handled for endpoints', async () => {
|
||||||
|
useCMEditViewDataManager.mockReturnValueOnce({
|
||||||
|
...CM_DATA_FIXTURE,
|
||||||
|
isCreatingEntry: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
const { result } = await setup({
|
||||||
|
...SELECT_ATTR_FIXTURE,
|
||||||
|
name: 'someting.component-name.field-name',
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.current.queryInfos).toStrictEqual({
|
||||||
|
endpoints: {
|
||||||
|
relation: '/content-manager/collection-types/slug/2/field-name',
|
||||||
|
search: '/content-manager/relations/slug/field-name',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -174,7 +174,7 @@ const generateRelationQueryInfosForComponents = (contentTypeConfiguration, field
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
defaultParams: {
|
defaultParams: {
|
||||||
_component: contentTypeConfiguration.uid,
|
component: contentTypeConfiguration.uid,
|
||||||
},
|
},
|
||||||
shouldDisplayRelationLink,
|
shouldDisplayRelationLink,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -568,7 +568,7 @@ describe('Content Manager | hooks | useFetchContentTypeLayout | utils ', () => {
|
|||||||
generateRelationQueryInfosForComponents(addressSchema, 'categories', simpleModels)
|
generateRelationQueryInfosForComponents(addressSchema, 'categories', simpleModels)
|
||||||
).toEqual({
|
).toEqual({
|
||||||
defaultParams: {
|
defaultParams: {
|
||||||
_component: 'api::address.address',
|
component: 'api::address.address',
|
||||||
},
|
},
|
||||||
shouldDisplayRelationLink: true,
|
shouldDisplayRelationLink: true,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user