mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
Add published_at field
Signed-off-by: soupette <cyril.lpz@gmail.com>
This commit is contained in:
parent
1fcbb15143
commit
bea6dada63
@ -3,17 +3,13 @@ import PropTypes from 'prop-types';
|
||||
import { get, isEmpty, isNull, isObject, toLower, toString } from 'lodash';
|
||||
import moment from 'moment';
|
||||
import { useGlobalContext } from 'strapi-helper-plugin';
|
||||
import { IconLinks, Text } from '@buffetjs/core';
|
||||
import { IconLinks } from '@buffetjs/core';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import useListView from '../../hooks/useListView';
|
||||
import dateFormats from '../../utils/dateFormats';
|
||||
import CustomInputCheckbox from '../CustomInputCheckbox';
|
||||
import getTrad from '../../utils/getTrad';
|
||||
import MediaPreviewList from '../MediaPreviewList';
|
||||
import { ActionContainer, Truncate, Truncated } from './styledComponents';
|
||||
import State from './State';
|
||||
|
||||
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
|
||||
|
||||
@ -72,7 +68,6 @@ const getDisplayedValue = (type, value, name) => {
|
||||
|
||||
function Row({ canDelete, canUpdate, isBulkable, row, headers }) {
|
||||
const { entriesToDelete, onChangeBulk, onClickDelete, schema } = useListView();
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const memoizedDisplayedValue = useCallback(
|
||||
name => {
|
||||
@ -120,18 +115,10 @@ function Row({ canDelete, canUpdate, isBulkable, row, headers }) {
|
||||
)}
|
||||
{headers.map(header => {
|
||||
return (
|
||||
<td key={header.name}>
|
||||
<td key={header.key || header.name}>
|
||||
{isMedia(header) && <MediaPreviewList files={memoizedDisplayedValue(header.name)} />}
|
||||
{header.name === 'published_at' && (
|
||||
<State isGreen={row.published_at}>
|
||||
<Text>
|
||||
{formatMessage({
|
||||
id: getTrad(`containers.List.${row.published_at ? 'published' : 'draft'}`),
|
||||
})}
|
||||
</Text>
|
||||
</State>
|
||||
)}
|
||||
{!isMedia(header) && header.name !== 'published_at' && (
|
||||
{header.cellFormatter && header.cellFormatter(row)}
|
||||
{!isMedia(header) && !header.cellFormatter && (
|
||||
<Truncate>
|
||||
<Truncated>{memoizedDisplayedValue(header.name)}</Truncated>
|
||||
</Truncate>
|
||||
|
@ -35,7 +35,7 @@ function TableHeader({ headers, isBulkable }) {
|
||||
{headers.map(header => {
|
||||
return (
|
||||
<th
|
||||
key={header.name}
|
||||
key={header.key || header.name}
|
||||
onClick={() => {
|
||||
if (header.sortable) {
|
||||
const isCurrentSort = header.name === sortBy;
|
||||
|
@ -12,7 +12,6 @@ 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';
|
||||
@ -37,7 +36,7 @@ const SettingsViewWrapper = ({
|
||||
const [showWarningSubmit, setWarningSubmit] = useState(false);
|
||||
|
||||
const attributes = useMemo(() => {
|
||||
return removePublishedAtFromMetas(get(modifiedData, ['schema', 'attributes'], {}));
|
||||
return get(modifiedData, ['schema', 'attributes'], {});
|
||||
}, [modifiedData]);
|
||||
|
||||
const toggleWarningCancel = () => setWarningCancel(prevState => !prevState);
|
||||
|
@ -1,7 +1,7 @@
|
||||
import styled from 'styled-components';
|
||||
import { Text } from '@buffetjs/core';
|
||||
|
||||
const State = styled.div`
|
||||
const Wrapper = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@ -27,4 +27,4 @@ const State = styled.div`
|
||||
`};
|
||||
`;
|
||||
|
||||
export default State;
|
||||
export default Wrapper;
|
@ -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;
|
@ -2,7 +2,7 @@ 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 } from 'lodash';
|
||||
import { get, isEmpty, sortBy } from 'lodash';
|
||||
import { FormattedMessage, useIntl } from 'react-intl';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { Header } from '@buffetjs/custom';
|
||||
@ -16,18 +16,14 @@ import {
|
||||
} from 'strapi-helper-plugin';
|
||||
import pluginId from '../../pluginId';
|
||||
import pluginPermissions from '../../permissions';
|
||||
import {
|
||||
generatePermissionsObject,
|
||||
getRequestUrl,
|
||||
getTrad,
|
||||
removePublishedAtFromMetas,
|
||||
} from '../../utils';
|
||||
import { generatePermissionsObject, getRequestUrl, getTrad } from '../../utils';
|
||||
|
||||
import DisplayedFieldsDropdown from '../../components/DisplayedFieldsDropdown';
|
||||
import Container from '../../components/Container';
|
||||
import CustomTable from '../../components/CustomTable';
|
||||
import FilterPicker from '../../components/FilterPicker';
|
||||
import Search from '../../components/Search';
|
||||
import State from '../../components/State';
|
||||
import ListViewProvider from '../ListViewProvider';
|
||||
import { onChangeListLabels, resetListLabels } from '../Main/actions';
|
||||
import { AddFilterCta, FilterIcon, Wrapper } from './components';
|
||||
@ -218,6 +214,12 @@ function ListView({
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
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 filteredMetadatas = removePublishedAtFromMetas(getMetaDatas());
|
||||
const filteredMetadatas = getMetaDatas();
|
||||
|
||||
return sortBy(
|
||||
Object.keys(filteredMetadatas)
|
||||
|
Loading…
x
Reference in New Issue
Block a user