Merge branch 'features/relational-fields' of github.com:strapi/strapi into core/cm-refacto-ediview-container

This commit is contained in:
soupette 2020-10-23 14:31:42 +02:00
commit 8c2bc447cb
6 changed files with 58 additions and 45 deletions

View File

@ -257,7 +257,7 @@ const EditSettingsView = ({
return ( return (
<div className="col-6" key={meta}> <div className="col-6" key={meta}>
<FormattedMessage <FormattedMessage
id={`${pluginId}.containers.SettingPage.editSettings.entry.title.description`} id={`${pluginId}.containers.SettingPage.editSettings.relation-field.description`}
> >
{description => ( {description => (
<FormattedMessage <FormattedMessage

View File

@ -7,12 +7,12 @@ import {
// contexts // contexts
useGlobalContext, useGlobalContext,
} from 'strapi-helper-plugin'; } from 'strapi-helper-plugin';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage, useIntl } from 'react-intl';
import { useDrop } from 'react-dnd'; import { useDrop } from 'react-dnd';
import { DropdownItem } from 'reactstrap'; import { DropdownItem } from 'reactstrap';
import { Inputs as Input } from '@buffetjs/custom'; import { Inputs as Input } from '@buffetjs/custom';
import pluginId from '../../pluginId'; import pluginId from '../../pluginId';
import { ItemTypes, getRequestUrl } from '../../utils'; import { checkIfAttributeIsDisplayable, ItemTypes, getRequestUrl } from '../../utils';
import PopupForm from '../../components/PopupForm'; import PopupForm from '../../components/PopupForm';
import SettingsViewWrapper from '../../components/SettingsViewWrapper'; import SettingsViewWrapper from '../../components/SettingsViewWrapper';
import SortWrapper from '../../components/SortWrapper'; import SortWrapper from '../../components/SortWrapper';
@ -30,6 +30,7 @@ const ListSettingsView = ({ deleteLayout, slug }) => {
const [isOpen, setIsOpen] = useState(false); const [isOpen, setIsOpen] = useState(false);
const [isModalFormOpen, setIsModalFormOpen] = useState(false); const [isModalFormOpen, setIsModalFormOpen] = useState(false);
const [isDraggingSibling, setIsDraggingSibling] = useState(false); const [isDraggingSibling, setIsDraggingSibling] = useState(false);
const { formatMessage } = useIntl();
const { emitEvent } = useGlobalContext(); const { emitEvent } = useGlobalContext();
@ -84,9 +85,7 @@ const ListSettingsView = ({ deleteLayout, slug }) => {
return Object.keys(metadatas) return Object.keys(metadatas)
.filter(key => { .filter(key => {
const type = get(attributes, [key, 'type'], ''); return checkIfAttributeIsDisplayable(get(attributes, key, {}));
return !['json', 'component', 'richtext', 'relation'].includes(type) && !!type;
}) })
.filter(field => { .filter(field => {
return !displayedFields.includes(field); return !displayedFields.includes(field);
@ -157,44 +156,43 @@ const ListSettingsView = ({ deleteLayout, slug }) => {
const [, drop] = useDrop({ accept: ItemTypes.FIELD }); const [, drop] = useDrop({ accept: ItemTypes.FIELD });
const renderForm = () => ( const renderForm = () => {
<> const type = get(attributes, [labelToEdit, 'type'], 'text');
<div className="col-6" style={{ marginBottom: 4 }}> const shouldDisplaySortToggle = !['media', 'relation'].includes(type);
<FormattedMessage id={`${pluginId}.form.Input.label`}> const label = formatMessage({ id: `${pluginId}.form.Input.label` });
{label => ( const description = formatMessage({ id: `${pluginId}.form.Input.label.inputDescription` });
<FormattedMessage id={`${pluginId}.form.Input.label.inputDescription`}>
{description => ( return (
<>
<div className="col-6" style={{ marginBottom: 4 }}>
<Input
description={description}
label={label}
type="text"
name="label"
onBlur={() => {}}
value={get(labelForm, 'label', '')}
onChange={handleChangeEditLabel}
/>
</div>
{shouldDisplaySortToggle && (
<div className="col-6" style={{ marginBottom: 4 }}>
<FormattedMessage id={`${pluginId}.form.Input.sort.field`}>
{label => (
<Input <Input
description={description}
label={label} label={label}
type="text" type="bool"
name="label" name="sortable"
onBlur={() => {}} value={get(labelForm, 'sortable', false)}
value={get(labelForm, 'label', '')}
onChange={handleChangeEditLabel} onChange={handleChangeEditLabel}
/> />
)} )}
</FormattedMessage> </FormattedMessage>
)} </div>
</FormattedMessage> )}
</div> </>
{get(attributes, [labelToEdit, 'type'], 'text') !== 'media' && ( );
<div className="col-6" style={{ marginBottom: 4 }}> };
<FormattedMessage id={`${pluginId}.form.Input.sort.field`}>
{label => (
<Input
label={label}
type="bool"
name="sortable"
value={get(labelForm, 'sortable', false)}
onChange={handleChangeEditLabel}
/>
)}
</FormattedMessage>
</div>
)}
</>
);
return ( return (
<LayoutDndProvider <LayoutDndProvider

View File

@ -16,7 +16,12 @@ import {
} from 'strapi-helper-plugin'; } from 'strapi-helper-plugin';
import pluginId from '../../pluginId'; import pluginId from '../../pluginId';
import pluginPermissions from '../../permissions'; import pluginPermissions from '../../permissions';
import { generatePermissionsObject, getRequestUrl, getTrad } from '../../utils'; import {
checkIfAttributeIsDisplayable,
generatePermissionsObject,
getRequestUrl,
getTrad,
} from '../../utils';
import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown'; import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown';
import Container from '../../components/Container'; import Container from '../../components/Container';
@ -244,12 +249,9 @@ function ListView({
return sortBy( return sortBy(
Object.keys(filteredMetadatas) Object.keys(filteredMetadatas)
.filter( .filter(key => {
key => return checkIfAttributeIsDisplayable(get(listSchema, ['attributes', key], {}));
!['json', 'component', 'dynamiczone', 'relation', 'richtext'].includes( })
get(listSchema, ['attributes', key, 'type'], '')
)
)
.map(label => ({ .map(label => ({
name: label, name: label,
value: listLayout.includes(label), value: listLayout.includes(label),

View File

@ -85,6 +85,7 @@
"containers.SettingPage.editSettings.description": "Drag & drop the fields to build the layout", "containers.SettingPage.editSettings.description": "Drag & drop the fields to build the layout",
"containers.SettingPage.editSettings.entry.title": "Entry title", "containers.SettingPage.editSettings.entry.title": "Entry title",
"containers.SettingPage.editSettings.entry.title.description": "Set the displayed field of your entry", "containers.SettingPage.editSettings.entry.title.description": "Set the displayed field of your entry",
"containers.SettingPage.editSettings.relation-field.description": "Set the displayed field in both the edit and list views",
"containers.SettingPage.editSettings.title": "Edit view (settings)", "containers.SettingPage.editSettings.title": "Edit view (settings)",
"containers.SettingPage.layout": "Layout", "containers.SettingPage.layout": "Layout",
"containers.SettingPage.listSettings.description": "Configure the options for this collection type", "containers.SettingPage.listSettings.description": "Configure the options for this collection type",

View File

@ -0,0 +1,11 @@
const checkIfAttributeIsDisplayable = attribute => {
const type = attribute.type;
if (type === 'relation') {
return !attribute.relationType.includes('morph');
}
return !['json', 'component', 'richtext'].includes(type) && !!type;
};
export default checkIfAttributeIsDisplayable;

View File

@ -1,3 +1,4 @@
export { default as checkIfAttributeIsDisplayable } from './checkIfAttributeIsDisplayable';
export { default as dateFormats } from './dateFormats'; export { default as dateFormats } from './dateFormats';
export { default as generatePermissionsObject } from './generatePermissionsObject'; export { default as generatePermissionsObject } from './generatePermissionsObject';
export { default as getFieldName } from './getFieldName'; export { default as getFieldName } from './getFieldName';