Add published_at field

Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
soupette 2020-09-01 10:03:21 +02:00 committed by Pierre Noël
parent 1fcbb15143
commit bea6dada63
6 changed files with 44 additions and 30 deletions

View File

@ -3,17 +3,13 @@ import PropTypes from 'prop-types';
import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash'; import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash';
import moment from 'moment'; import moment from 'moment';
import { useGlobalContext } from 'strapi-helper-plugin'; import { useGlobalContext } from 'strapi-helper-plugin';
import { IconLinks, Text } from '@buffetjs/core'; import { IconLinks } from '@buffetjs/core';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { useIntl } from 'react-intl';
import useListView from '../../hooks/useListView'; import useListView from '../../hooks/useListView';
import dateFormats from '../../utils/dateFormats'; import dateFormats from '../../utils/dateFormats';
import CustomInputCheckbox from '../CustomInputCheckbox'; import CustomInputCheckbox from '../CustomInputCheckbox';
import getTrad from '../../utils/getTrad';
import MediaPreviewList from '../MediaPreviewList'; import MediaPreviewList from '../MediaPreviewList';
import { ActionContainer, Truncate, Truncated } from './styledComponents'; import { ActionContainer, Truncate, Truncated } from './styledComponents';
import State from './State';
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
@ -72,7 +68,6 @@ const getDisplayedValue = (type, value, name) => {
function Row({ canDelete, canUpdate, isBulkable, row, headers }) { function Row({ canDelete, canUpdate, isBulkable, row, headers }) {
const { entriesToDelete, onChangeBulk, onClickDelete, schema } = useListView(); const { entriesToDelete, onChangeBulk, onClickDelete, schema } = useListView();
const { formatMessage } = useIntl();
const memoizedDisplayedValue = useCallback( const memoizedDisplayedValue = useCallback(
name => { name => {
@ -120,18 +115,10 @@ function Row({ canDelete, canUpdate, isBulkable, row, headers }) {
)} )}
{headers.map(header => { {headers.map(header => {
return ( return (
<td key={header.name}> <td key={header.key || header.name}>
{isMedia(header) && <MediaPreviewList files={memoizedDisplayedValue(header.name)} />} {isMedia(header) && <MediaPreviewList files={memoizedDisplayedValue(header.name)} />}
{header.name === 'published_at' && ( {header.cellFormatter && header.cellFormatter(row)}
<State isGreen={row.published_at}> {!isMedia(header) && !header.cellFormatter && (
<Text>
{formatMessage({
id: getTrad(`containers.List.${row.published_at ? 'published' : 'draft'}`),
})}
</Text>
</State>
)}
{!isMedia(header) && header.name !== 'published_at' && (
<Truncate> <Truncate>
<Truncated>{memoizedDisplayedValue(header.name)}</Truncated> <Truncated>{memoizedDisplayedValue(header.name)}</Truncated>
</Truncate> </Truncate>

View File

@ -35,7 +35,7 @@ function TableHeader({ headers, isBulkable }) {
{headers.map(header => { {headers.map(header => {
return ( return (
<th <th
key={header.name} key={header.key || header.name}
onClick={() => { onClick={() => {
if (header.sortable) { if (header.sortable) {
const isCurrentSort = header.name === sortBy; const isCurrentSort = header.name === sortBy;

View File

@ -12,7 +12,6 @@ import {
useGlobalContext, useGlobalContext,
} from 'strapi-helper-plugin'; } from 'strapi-helper-plugin';
import pluginId from '../../pluginId'; import pluginId from '../../pluginId';
import { removePublishedAtFromMetas } from '../../utils';
import Block from '../Block'; import Block from '../Block';
import Container from '../Container'; import Container from '../Container';
import SectionTitle from '../SectionTitle'; import SectionTitle from '../SectionTitle';
@ -37,7 +36,7 @@ const SettingsViewWrapper = ({
const [showWarningSubmit, setWarningSubmit] = useState(false); const [showWarningSubmit, setWarningSubmit] = useState(false);
const attributes = useMemo(() => { const attributes = useMemo(() => {
return removePublishedAtFromMetas(get(modifiedData, ['schema', 'attributes'], {})); return get(modifiedData, ['schema', 'attributes'], {});
}, [modifiedData]); }, [modifiedData]);
const toggleWarningCancel = () => setWarningCancel(prevState => !prevState); const toggleWarningCancel = () => setWarningCancel(prevState => !prevState);

View File

@ -1,7 +1,7 @@
import styled from 'styled-components'; import styled from 'styled-components';
import { Text } from '@buffetjs/core'; import { Text } from '@buffetjs/core';
const State = styled.div` const Wrapper = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@ -27,4 +27,4 @@ const State = styled.div`
`}; `};
`; `;
export default State; export default Wrapper;

View File

@ -0,0 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { Text } from '@buffetjs/core';
import { getTrad } from '../../utils';
import Wrapper from './Wrapper';
const State = ({ isPublished }) => {
const { formatMessage } = useIntl();
return (
<Wrapper isGreen={isPublished}>
<Text>
{formatMessage({
id: getTrad(`containers.List.${isPublished ? 'published' : 'draft'}`),
})}
</Text>
</Wrapper>
);
};
State.propTypes = {
isPublished: PropTypes.bool.isRequired,
};
export default State;

View File

@ -2,7 +2,7 @@ import React, { memo, useCallback, useEffect, useMemo, useRef, useState } from '
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators, compose } from 'redux'; import { bindActionCreators, compose } from 'redux';
import { get, sortBy } from 'lodash'; import { get, isEmpty, sortBy } from 'lodash';
import { FormattedMessage, useIntl } from 'react-intl'; import { FormattedMessage, useIntl } from 'react-intl';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { Header } from '@buffetjs/custom'; import { Header } from '@buffetjs/custom';
@ -16,18 +16,14 @@ 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 { import { generatePermissionsObject, getRequestUrl, getTrad } from '../../utils';
generatePermissionsObject,
getRequestUrl,
getTrad,
removePublishedAtFromMetas,
} from '../../utils';
import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown'; import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown';
import Container from '../../components/Container'; import Container from '../../components/Container';
import CustomTable from '../../components/CustomTable'; import CustomTable from '../../components/CustomTable';
import FilterPicker from '../../components/FilterPicker'; import FilterPicker from '../../components/FilterPicker';
import Search from '../../components/Search'; import Search from '../../components/Search';
import State from '../../components/State';
import ListViewProvider from '../ListViewProvider'; import ListViewProvider from '../ListViewProvider';
import { onChangeListLabels, resetListLabels } from '../Main/actions'; import { onChangeListLabels, resetListLabels } from '../Main/actions';
import { AddFilterCta, FilterIcon, Wrapper } from './components'; import { AddFilterCta, FilterIcon, Wrapper } from './components';
@ -218,6 +214,12 @@ function ListView({
searchable: false, searchable: false,
sortable: true, sortable: true,
name: 'published_at', name: 'published_at',
key: '__published_at__',
cellFormatter: data => {
const isPublished = !isEmpty(data.published_at);
return <State isPublished={isPublished} />;
},
}); });
} }
@ -238,7 +240,7 @@ function ListView({
); );
const allLabels = useMemo(() => { const allLabels = useMemo(() => {
const filteredMetadatas = removePublishedAtFromMetas(getMetaDatas()); const filteredMetadatas = getMetaDatas();
return sortBy( return sortBy(
Object.keys(filteredMetadatas) Object.keys(filteredMetadatas)