diff --git a/packages/strapi-plugin-content-manager/admin/src/components/SettingsViewWrapper/index.js b/packages/strapi-plugin-content-manager/admin/src/components/SettingsViewWrapper/index.js index abf5c97357..540aa2b1a9 100644 --- a/packages/strapi-plugin-content-manager/admin/src/components/SettingsViewWrapper/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/components/SettingsViewWrapper/index.js @@ -12,6 +12,7 @@ import { useGlobalContext, } from 'strapi-helper-plugin'; import pluginId from '../../pluginId'; +import { removePublishedAtFromMetas } from '../../utils'; import Block from '../Block'; import Container from '../Container'; import SectionTitle from '../SectionTitle'; @@ -35,8 +36,8 @@ const SettingsViewWrapper = ({ const [showWarningCancel, setWarningCancel] = useState(false); const [showWarningSubmit, setWarningSubmit] = useState(false); - const getAttributes = useMemo(() => { - return get(modifiedData, ['schema', 'attributes'], {}); + const attributes = useMemo(() => { + return removePublishedAtFromMetas(get(modifiedData, ['schema', 'attributes'], {})); }, [modifiedData]); const toggleWarningCancel = () => setWarningCancel(prevState => !prevState); @@ -96,15 +97,14 @@ const SettingsViewWrapper = ({ 'id', ...displayedFields.filter( name => - get(getAttributes, [name, 'type'], '') !== 'media' && + get(attributes, [name, 'type'], '') !== 'media' && name !== 'id' && - get(getAttributes, [name, 'type'], '') !== 'richtext' + get(attributes, [name, 'type'], '') !== 'richtext' ), ]; } if (input.name === 'settings.mainField') { - const attributes = getAttributes; const options = Object.keys(attributes).filter(attr => { const type = get(attributes, [attr, 'type'], ''); diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/ListSettingsView/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/ListSettingsView/index.js index ae8dc75b87..0ce3c34d68 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/ListSettingsView/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/ListSettingsView/index.js @@ -1,6 +1,6 @@ import React, { useEffect, useMemo, useReducer, useState } from 'react'; import PropTypes from 'prop-types'; -import { cloneDeep, get, omit } from 'lodash'; +import { cloneDeep, get } from 'lodash'; import { // utils request, @@ -12,8 +12,7 @@ import { useDrop } from 'react-dnd'; import { DropdownItem } from 'reactstrap'; import { Inputs as Input } from '@buffetjs/custom'; import pluginId from '../../pluginId'; -import ItemTypes from '../../utils/ItemTypes'; -import getRequestUrl from '../../utils/getRequestUrl'; +import { ItemTypes, getRequestUrl, removePublishedAtFromMetas } from '../../utils'; import PopupForm from '../../components/PopupForm'; import SettingsViewWrapper from '../../components/SettingsViewWrapper'; import SortWrapper from '../../components/SortWrapper'; @@ -82,7 +81,7 @@ const ListSettingsView = ({ deleteLayout, slug }) => { const listRemainingFields = useMemo(() => { const metadatas = get(modifiedData, ['metadatas'], {}); - const filteredMetadatas = omit(metadatas, ['published_at']); + const filteredMetadatas = removePublishedAtFromMetas(metadatas); return Object.keys(filteredMetadatas) .filter(key => { diff --git a/packages/strapi-plugin-content-manager/admin/src/containers/ListView/index.js b/packages/strapi-plugin-content-manager/admin/src/containers/ListView/index.js index c49796fa94..4ee16bff78 100644 --- a/packages/strapi-plugin-content-manager/admin/src/containers/ListView/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/containers/ListView/index.js @@ -2,14 +2,13 @@ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from ' import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators, compose } from 'redux'; -import { get, sortBy, omit } from 'lodash'; -import { FormattedMessage } from 'react-intl'; +import { get, sortBy } from 'lodash'; +import { FormattedMessage, useIntl } from 'react-intl'; import { useLocation } from 'react-router-dom'; import { Header } from '@buffetjs/custom'; import { PopUpWarning, generateFiltersFromSearch, - useGlobalContext, request, CheckPermissions, useUserPermissions, @@ -17,7 +16,12 @@ import { } from 'strapi-helper-plugin'; import pluginId from '../../pluginId'; import pluginPermissions from '../../permissions'; -import { generatePermissionsObject, getRequestUrl } from '../../utils'; +import { + generatePermissionsObject, + getRequestUrl, + getTrad, + removePublishedAtFromMetas, +} from '../../utils'; import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown'; import Container from '../../components/Container'; @@ -83,7 +87,7 @@ function ListView({ const query = useQuery(); const { search } = useLocation(); const isFirstRender = useRef(true); - const { formatMessage } = useGlobalContext(); + const { formatMessage } = useIntl(); const [isLabelPickerOpen, setLabelPickerState] = useState(false); const [isFilterPickerOpen, setFilterPickerState] = useState(false); @@ -209,11 +213,16 @@ function ListView({ }); if (hasDraftAndPublish) { - headers.push({ label: 'State', searchable: false, sortable: true, name: 'published_at' }); + headers.push({ + label: formatMessage({ id: getTrad('containers.ListPage.table-headers.published_at') }), + searchable: false, + sortable: true, + name: 'published_at', + }); } return headers; - }, [getMetaDatas, hasDraftAndPublish, listLayout]); + }, [formatMessage, getMetaDatas, hasDraftAndPublish, listLayout]); const getFirstSortableElement = useCallback( (name = '') => { @@ -229,7 +238,7 @@ function ListView({ ); const allLabels = useMemo(() => { - const filteredMetadatas = omit(getMetaDatas(), ['published_at']); + const filteredMetadatas = removePublishedAtFromMetas(getMetaDatas()); return sortBy( Object.keys(filteredMetadatas) 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 cfff7e42d9..e35c435531 100644 --- a/packages/strapi-plugin-content-manager/admin/src/translations/en.json +++ b/packages/strapi-plugin-content-manager/admin/src/translations/en.json @@ -73,6 +73,7 @@ "containers.List.pluginHeaderDescription": "{label} entries found", "containers.List.pluginHeaderDescription.singular": "{label} entry found", "containers.List.published": "Published", + "containers.ListPage.table-headers.published_at": "State", "containers.ListPage.displayedFields": "Displayed Fields", "containers.ListSettingsView.modal-form.edit-label": "Edit the label", "containers.SettingPage.add.field": "Insert another field", 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..aecd72479a 100644 --- a/packages/strapi-plugin-content-manager/admin/src/utils/index.js +++ b/packages/strapi-plugin-content-manager/admin/src/utils/index.js @@ -4,3 +4,4 @@ export { default as getFieldName } from './getFieldName'; export { default as getRequestUrl } from './getRequestUrl'; export { default as getTrad } from './getTrad'; export { default as ItemTypes } from './ItemTypes'; +export { default as removePublishedAtFromMetas } from './removePublishedAtFromMetas'; diff --git a/packages/strapi-plugin-content-manager/admin/src/utils/removePublishedAtFromMetas.js b/packages/strapi-plugin-content-manager/admin/src/utils/removePublishedAtFromMetas.js new file mode 100644 index 0000000000..54b352fb2b --- /dev/null +++ b/packages/strapi-plugin-content-manager/admin/src/utils/removePublishedAtFromMetas.js @@ -0,0 +1,5 @@ +import { omit } from 'lodash'; + +const removePublishedAtFromMetas = metas => omit(metas, ['published_at']); + +export default removePublishedAtFromMetas; diff --git a/packages/strapi-plugin-content-manager/admin/src/utils/tests/removePublishedAtFromMetas.test.js b/packages/strapi-plugin-content-manager/admin/src/utils/tests/removePublishedAtFromMetas.test.js new file mode 100644 index 0000000000..e5ae92ce0b --- /dev/null +++ b/packages/strapi-plugin-content-manager/admin/src/utils/tests/removePublishedAtFromMetas.test.js @@ -0,0 +1,12 @@ +import removePublishedAtFromMetas from '../removePublishedAtFromMetas'; + +describe('CONTENT MANAGER | utils | removePublishedAtFromMetas', () => { + it('should remove the published_at key from the given object', () => { + const data = { + ok: true, + published_at: true, + }; + + expect(removePublishedAtFromMetas(data)).toEqual({ ok: true }); + }); +});