CM: Remove all references to editRelations

This commit is contained in:
Gustav Hansen 2022-08-08 13:04:18 +02:00
parent 78c8651e1e
commit 2ba774c237
12 changed files with 2 additions and 326 deletions

View File

@ -338,65 +338,6 @@ const addressCT = {
},
],
],
editRelations: [
{
name: 'categories',
size: 6,
fieldSchema: {
collection: 'category',
via: 'addresses',
dominant: true,
attribute: 'category',
column: 'id',
isVirtual: true,
type: 'relation',
targetModel: 'api::category.category',
relationType: 'manyToMany',
},
metadatas: {
label: 'Categories',
description: '',
placeholder: '',
visible: true,
editable: true,
mainField: { name: 'name', schema: { type: 'string' } },
},
queryInfos: {
endPoint: '/content-manager/relations/api::address.address/categories',
containsKey: 'name_contains',
defaultParams: {},
shouldDisplayRelationLink: true,
},
targetModelPluginOptions: {},
},
{
name: 'likes',
size: 6,
fieldSchema: {
collection: 'like',
via: 'address',
isVirtual: true,
type: 'relation',
targetModel: 'api::like.like',
relationType: 'oneToMany',
},
metadatas: {
label: 'Likes',
description: '',
placeholder: '',
visible: true,
editable: true,
mainField: { name: 'id', schema: { type: 'integer' } },
},
queryInfos: {
endPoint: '/content-manager/relations/api::address.address/likes',
containsKey: 'id_contains',
defaultParams: {},
shouldDisplayRelationLink: true,
},
targetModelPluginOptions: {},
},
],
},
isDisplayed: true,
apiID: 'address',

View File

@ -118,7 +118,6 @@ DynamicTable.propTypes = {
metadatas: PropTypes.object.isRequired,
layouts: PropTypes.shape({
list: PropTypes.array.isRequired,
editRelations: PropTypes.array,
}).isRequired,
options: PropTypes.object.isRequired,
settings: PropTypes.object.isRequired,

View File

@ -13,9 +13,7 @@ const addressSchema = {
targetModel: 'api::category.category',
},
},
layouts: {
editRelations: ['categories'],
},
layouts: {},
metadatas: {
categories: {
edit: {
@ -134,7 +132,6 @@ describe('Content Manager | hooks | useFetchContentTypeLayout | utils ', () => {
uid: 'contentType',
layouts: {
list: [],
editRelations: [],
edit: [
[{ name: 'dz', size: 12 }],
[

View File

@ -369,7 +369,6 @@ EditSettingsView.propTypes = {
info: PropTypes.object.isRequired,
layouts: PropTypes.shape({
list: PropTypes.array.isRequired,
editRelations: PropTypes.array.isRequired,
edit: PropTypes.array.isRequired,
}).isRequired,
metadatas: PropTypes.object.isRequired,

View File

@ -5,11 +5,9 @@ import { CheckPermissions, useTracking, LinkButton } from '@strapi/helper-plugin
import { useIntl } from 'react-intl';
import { ContentLayout } from '@strapi/design-system/Layout';
import { Box } from '@strapi/design-system/Box';
import { Divider } from '@strapi/design-system/Divider';
import { Grid, GridItem } from '@strapi/design-system/Grid';
import { Main } from '@strapi/design-system/Main';
import { Stack } from '@strapi/design-system/Stack';
import { Typography } from '@strapi/design-system/Typography';
import Layer from '@strapi/icons/Layer';
import Pencil from '@strapi/icons/Pencil';
import { InjectionZone } from '../../../shared/components';
@ -17,7 +15,6 @@ import permissions from '../../../permissions';
import DynamicZone from '../../components/DynamicZone';
import FieldComponent from '../../components/FieldComponent';
import Inputs from '../../components/Inputs';
import SelectWrapper from '../../components/SelectWrapper';
import CollectionTypeFormWrapper from '../../components/CollectionTypeFormWrapper';
import EditViewDataManagerProvider from '../../components/EditViewDataManagerProvider';
import SingleTypeFormWrapper from '../../components/SingleTypeFormWrapper';
@ -87,9 +84,6 @@ const EditView = ({
);
}, [currentContentTypeLayoutData]);
const relationsLayout = currentContentTypeLayoutData.layouts.editRelations;
const displayedRelationsLength = relationsLayout.length;
return (
<DataManagementWrapper allLayoutData={layout} slug={slug} id={id} origin={origin}>
{({
@ -246,64 +240,6 @@ const EditView = ({
<Informations />
<InjectionZone area="contentManager.editView.informations" />
</Box>
{displayedRelationsLength > 0 && (
<Box
as="aside"
aria-labelledby="relations-title"
background="neutral0"
borderColor="neutral150"
hasRadius
paddingBottom={4}
paddingLeft={4}
paddingRight={4}
paddingTop={6}
shadow="tableShadow"
>
<Typography variant="sigma" textColor="neutral600" id="relations-title">
{formatMessage(
{
id: getTrad('containers.Edit.relations'),
defaultMessage:
'{number, plural, =0 {relations} one {relation} other {relations}}',
},
{ number: displayedRelationsLength }
)}
</Typography>
<Box paddingTop={2} paddingBottom={6}>
<Divider />
</Box>
<Stack spacing={4}>
{relationsLayout.map(
({ name, fieldSchema, labelAction, metadatas, queryInfos }) => {
return (
<SelectWrapper
{...fieldSchema}
{...metadatas}
key={name}
description={metadatas.description}
intlLabel={{
id: metadatas.label,
defaultMessage: metadatas.label,
}}
labelAction={labelAction}
name={name}
relationsType={fieldSchema.relationType}
queryInfos={queryInfos}
placeholder={
metadatas.placeholder
? {
id: metadatas.placeholder,
defaultMessage: metadatas.placeholder,
}
: null
}
/>
);
}
)}
</Stack>
</Box>
)}
<Box as="aside" aria-labelledby="links">
<Stack spacing={2}>
<InjectionZone area="contentManager.editView.right-links" slug={slug} />

View File

@ -84,7 +84,6 @@ FieldPicker.propTypes = {
metadatas: PropTypes.object.isRequired,
layouts: PropTypes.shape({
list: PropTypes.array.isRequired,
editRelations: PropTypes.array,
}).isRequired,
options: PropTypes.object.isRequired,
settings: PropTypes.object.isRequired,

View File

@ -361,7 +361,6 @@ ListView.propTypes = {
info: PropTypes.shape({ displayName: PropTypes.string.isRequired }).isRequired,
layouts: PropTypes.shape({
list: PropTypes.array.isRequired,
editRelations: PropTypes.array,
}).isRequired,
options: PropTypes.object.isRequired,
settings: PropTypes.object.isRequired,

View File

@ -45,7 +45,6 @@ ListViewLayout.propTypes = {
metadatas: PropTypes.object.isRequired,
layouts: PropTypes.shape({
list: PropTypes.array.isRequired,
editRelations: PropTypes.array,
}).isRequired,
options: PropTypes.object.isRequired,
settings: PropTypes.object.isRequired,

View File

@ -5,7 +5,6 @@ describe('CONTENT MANAGER | utils | formatLayoutToApi', () => {
const layouts = {
list: [{ name: 'test', size: 6 }],
edit: [],
editRelations: [],
};
expect(formatLayoutToApi({ layouts, metadatas: {} }).layouts.list).toEqual(['test']);
@ -15,7 +14,6 @@ describe('CONTENT MANAGER | utils | formatLayoutToApi', () => {
const layouts = {
list: ['test'],
edit: [],
editRelations: [],
};
expect(formatLayoutToApi({ layouts, metadatas: {} }).layouts.list).toEqual(['test']);
@ -25,7 +23,6 @@ describe('CONTENT MANAGER | utils | formatLayoutToApi', () => {
const layouts = {
list: ['test'],
edit: [],
editRelations: [],
};
const metadatas = {
categories: {

View File

@ -666,10 +666,6 @@ components:
type: array
items:
type: string
editRelations:
type: array
items:
type: string
edit:
type: array
items:

View File

@ -5,28 +5,6 @@ import StrikedWorld from '@strapi/icons/EarthStriked';
import LabelAction from '../components/LabelAction';
import { getTrad } from '../utils';
const enhanceRelationLayout = (layout, locale) =>
layout.map(current => {
const labelActionProps = {
title: {
id: getTrad('Field.localized'),
defaultMessage: 'This value is unique for the selected locale',
},
icon: <I18N aria-hidden />,
};
let queryInfos = current.queryInfos;
if (get(current, ['targetModelPluginOptions', 'i18n', 'localized'], false)) {
queryInfos = {
...queryInfos,
defaultParams: { ...queryInfos.defaultParams, locale },
paramsToKeep: ['plugins.i18n.locale'],
};
}
return { ...current, labelAction: <LabelAction {...labelActionProps} />, queryInfos };
});
const enhanceEditLayout = layout =>
layout.map(row => {
const enhancedRow = row.reduce((acc, field) => {
@ -120,15 +98,11 @@ const mutateEditViewLayoutHook = ({ layout, query }) => {
}
const editLayoutPath = getPathToContentType(['layouts', 'edit']);
const editRelationsPath = getPathToContentType(['layouts', 'editRelations']);
const editLayout = get(layout, editLayoutPath);
const editRelationsLayout = get(layout, editRelationsPath);
const nextEditRelationLayout = enhanceRelationLayout(editRelationsLayout, currentLocale);
const nextEditLayout = enhanceEditLayout(editLayout);
const enhancedLayouts = {
...layout.contentType.layouts,
editRelations: nextEditRelationLayout,
edit: nextEditLayout,
};
@ -150,9 +124,4 @@ const mutateEditViewLayoutHook = ({ layout, query }) => {
};
export default mutateEditViewLayoutHook;
export {
enhanceComponentLayoutForRelations,
enhanceComponentsLayout,
enhanceEditLayout,
enhanceRelationLayout,
};
export { enhanceComponentLayoutForRelations, enhanceComponentsLayout, enhanceEditLayout };

View File

@ -6,7 +6,6 @@ import { getTrad } from '../../utils';
import mutateEditViewLayout, {
enhanceComponentsLayout,
enhanceEditLayout,
enhanceRelationLayout,
} from '../mutateEditViewLayout';
const localizedTrad = getTrad('Field.localized');
@ -42,16 +41,6 @@ describe('i18n | contentManagerHooks | mutateEditViewLayout', () => {
pluginOptions: { i18n: { localized: true } },
layouts: {
edit: [],
editRelations: [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {},
size: 6,
targetModelPluginOptions: {},
},
],
},
},
};
@ -65,72 +54,6 @@ describe('i18n | contentManagerHooks | mutateEditViewLayout', () => {
expect(results).toEqual(data);
});
it('should modify the editRelations layout when i18n is enabled and the query.locale is defined', () => {
const layout = {
contentType: {
uid: 'test',
pluginOptions: { i18n: { localized: true } },
layouts: {
edit: [],
editRelations: [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {
test: true,
defaultParams: {},
paramsToKeep: ['plugins.i18n.locale'],
},
size: 6,
targetModelPluginOptions: {},
},
],
},
},
components: {},
};
const data = {
layout,
query: { plugins: { i18n: { locale: 'en' } } },
};
const results = mutateEditViewLayout(data);
expect(results).toEqual({
...data,
layout: {
...layout,
contentType: {
...layout.contentType,
layouts: {
edit: [],
editRelations: [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {
test: true,
defaultParams: {},
paramsToKeep: ['plugins.i18n.locale'],
},
size: 6,
targetModelPluginOptions: {},
labelAction: (
<LabelAction
title={{ id: localizedTrad, defaultMessage: localizedTradDefaultMessage }}
icon={<I18N aria-hidden />}
/>
),
},
],
},
},
},
});
});
describe('enhanceComponentsLayout', () => {
it('should not enhance the field when the type is not relation', () => {
const components = {
@ -459,82 +382,4 @@ describe('i18n | contentManagerHooks | mutateEditViewLayout', () => {
expect(enhanceEditLayout(edit)).toEqual(expected);
});
});
describe('enhanceRelationLayout', () => {
it('should add the labelIcon key to all relations fields', () => {
const editRelations = [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {},
size: 6,
targetModelPluginOptions: {},
},
];
const expected = [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {},
size: 6,
targetModelPluginOptions: {},
labelAction: (
<LabelAction
title={{ id: localizedTrad, defaultMessage: localizedTradDefaultMessage }}
icon={<I18N aria-hidden />}
/>
),
},
];
expect(enhanceRelationLayout(editRelations, 'en')).toEqual(expected);
});
it('should add the locale to the queryInfos.defaultParams when the targetModelPluginOptions.i18n.localized is enabled', () => {
const editRelations = [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {
defaultParams: {
test: true,
},
},
size: 6,
targetModelPluginOptions: {
i18n: { localized: true },
},
},
];
const expected = [
{
fieldSchema: {},
metadatas: {},
name: 'addresses',
queryInfos: {
defaultParams: {
test: true,
locale: 'en',
},
paramsToKeep: ['plugins.i18n.locale'],
},
size: 6,
targetModelPluginOptions: {
i18n: { localized: true },
},
labelAction: (
<LabelAction
title={{ id: localizedTrad, defaultMessage: localizedTradDefaultMessage }}
icon={<I18N aria-hidden />}
/>
),
},
];
expect(enhanceRelationLayout(editRelations, 'en')).toEqual(expected);
});
});
});