mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +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 getRequestUrl(`${collectionTypePrefix}/${slug}/${initialData.id}/${name}`);
|
||||
return getRequestUrl(
|
||||
`${collectionTypePrefix}/${slug}/${initialData.id}/${name.split('.').at(-1)}`
|
||||
);
|
||||
}, [isCreatingEntry, slug, initialData, name, isSingleType]);
|
||||
|
||||
// /content-manager/relations/[content-type]/[field-name]
|
||||
const relationSearchEndpoint = useMemo(() => {
|
||||
return getRequestUrl(`relations/${slug}/${name}`);
|
||||
return getRequestUrl(`relations/${slug}/${name.split('.').at(-1)}`);
|
||||
}, [slug, name]);
|
||||
|
||||
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 {
|
||||
defaultParams: {
|
||||
_component: contentTypeConfiguration.uid,
|
||||
component: contentTypeConfiguration.uid,
|
||||
},
|
||||
shouldDisplayRelationLink,
|
||||
};
|
||||
|
||||
@ -568,7 +568,7 @@ describe('Content Manager | hooks | useFetchContentTypeLayout | utils ', () => {
|
||||
generateRelationQueryInfosForComponents(addressSchema, 'categories', simpleModels)
|
||||
).toEqual({
|
||||
defaultParams: {
|
||||
_component: 'api::address.address',
|
||||
component: 'api::address.address',
|
||||
},
|
||||
shouldDisplayRelationLink: true,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user