diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/EditSettingsView/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/EditSettingsView/index.js index 3a2412dcfb..fb2a6487af 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/EditSettingsView/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/EditSettingsView/index.js @@ -257,7 +257,7 @@ const EditSettingsView = ({ return (
{description => ( { const [isOpen, setIsOpen] = useState(false); const [isModalFormOpen, setIsModalFormOpen] = useState(false); const [isDraggingSibling, setIsDraggingSibling] = useState(false); + const { formatMessage } = useIntl(); const { emitEvent } = useGlobalContext(); @@ -84,9 +85,7 @@ const ListSettingsView = ({ deleteLayout, slug }) => { return Object.keys(metadatas) .filter(key => { - const type = get(attributes, [key, 'type'], ''); - - return !['json', 'component', 'richtext', 'relation'].includes(type) && !!type; + return checkIfAttributeIsDisplayable(get(attributes, key, {})); }) .filter(field => { return !displayedFields.includes(field); @@ -157,44 +156,43 @@ const ListSettingsView = ({ deleteLayout, slug }) => { const [, drop] = useDrop({ accept: ItemTypes.FIELD }); - const renderForm = () => ( - <> -
- - {label => ( - - {description => ( + const renderForm = () => { + const type = get(attributes, [labelToEdit, 'type'], 'text'); + const shouldDisplaySortToggle = !['media', 'relation'].includes(type); + const label = formatMessage({ id: `${pluginId}.form.Input.label` }); + const description = formatMessage({ id: `${pluginId}.form.Input.label.inputDescription` }); + + return ( + <> +
+ {}} + value={get(labelForm, 'label', '')} + onChange={handleChangeEditLabel} + /> +
+ {shouldDisplaySortToggle && ( +
+ + {label => ( {}} - value={get(labelForm, 'label', '')} + type="bool" + name="sortable" + value={get(labelForm, 'sortable', false)} onChange={handleChangeEditLabel} /> )} - )} - -
- {get(attributes, [labelToEdit, 'type'], 'text') !== 'media' && ( -
- - {label => ( - - )} - -
- )} - - ); +
+ )} + + ); + }; return ( - !['json', 'component', 'dynamiczone', 'relation', 'richtext'].includes( - get(listSchema, ['attributes', key, 'type'], '') - ) - ) + .filter(key => { + return checkIfAttributeIsDisplayable(get(listSchema, ['attributes', key], {})); + }) .map(label => ({ name: label, value: listLayout.includes(label), diff --git a/packages/strapi-plugin-content-manager/admin/src/translations/en.json b/packages/strapi-plugin-content-manager/admin/src/translations/en.json index 23fe1519b7..976547462f 100644 --- a/packages/strapi-plugin-content-manager/admin/src/translations/en.json +++ b/packages/strapi-plugin-content-manager/admin/src/translations/en.json @@ -85,6 +85,7 @@ "containers.SettingPage.editSettings.description": "Drag & drop the fields to build the layout", "containers.SettingPage.editSettings.entry.title": "Entry title", "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.layout": "Layout", "containers.SettingPage.listSettings.description": "Configure the options for this collection type", diff --git a/packages/strapi-plugin-content-manager/admin/src/utils/checkIfAttributeIsDisplayable.js b/packages/strapi-plugin-content-manager/admin/src/utils/checkIfAttributeIsDisplayable.js new file mode 100644 index 0000000000..f8a3a8fbe1 --- /dev/null +++ b/packages/strapi-plugin-content-manager/admin/src/utils/checkIfAttributeIsDisplayable.js @@ -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; diff --git a/packages/strapi-plugin-content-manager/admin/src/utils/index.js b/packages/strapi-plugin-content-manager/admin/src/utils/index.js index 479d32d2f4..5bfe03ccd3 100644 --- a/packages/strapi-plugin-content-manager/admin/src/utils/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/utils/index.js @@ -1,3 +1,4 @@ +export { default as checkIfAttributeIsDisplayable } from './checkIfAttributeIsDisplayable'; export { default as dateFormats } from './dateFormats'; export { default as generatePermissionsObject } from './generatePermissionsObject'; export { default as getFieldName } from './getFieldName';