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:
Gustav Hansen 2022-09-13 16:11:02 +02:00 committed by GitHub
commit a72197c78a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 4 deletions

View File

@ -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 {

View File

@ -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',
},
});
});
}); });

View File

@ -174,7 +174,7 @@ const generateRelationQueryInfosForComponents = (contentTypeConfiguration, field
return { return {
defaultParams: { defaultParams: {
_component: contentTypeConfiguration.uid, component: contentTypeConfiguration.uid,
}, },
shouldDisplayRelationLink, shouldDisplayRelationLink,
}; };

View File

@ -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,
}); });