Skip to content

Commit 761f94a

Browse files
committed
feat: add workflow status to entry card
1 parent cd82f6b commit 761f94a

File tree

2 files changed

+58
-4
lines changed

2 files changed

+58
-4
lines changed

packages/decap-cms-core/src/components/Collection/Entries/EntryCard.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import styled from '@emotion/styled';
33
import { connect } from 'react-redux';
44
import { Link } from 'react-router-dom';
5-
import { colors, colorsRaw, components, lengths, zIndex } from 'decap-cms-ui-default';
5+
import { colors, colorsRaw, components, lengths, zIndex, Icon } from 'decap-cms-ui-default';
66

77
import { boundGetAsset } from '../../../actions/media';
88
import { VIEW_STYLE_LIST, VIEW_STYLE_GRID } from '../../../constants/collectionViews';
@@ -56,10 +56,14 @@ const CollectionLabel = styled.h2`
5656

5757
const ListCardTitle = styled.h2`
5858
margin-bottom: 0;
59+
display: flex;
60+
justify-content: space-between;
5961
`;
6062

6163
const CardHeading = styled.h2`
6264
margin: 0 0 2px;
65+
display: flex;
66+
justify-content: space-between;
6367
`;
6468

6569
const CardBody = styled.div`
@@ -89,21 +93,43 @@ const CardImage = styled.div`
8993
height: 150px;
9094
`;
9195

96+
const TitleIcons = styled.div`
97+
display: flex;
98+
align-items: center;
99+
gap: 8px;
100+
`;
101+
102+
const StatusIcon = styled(Icon)`
103+
color: ${props => {
104+
switch (props.workflowStatus) {
105+
case 'pending_review': return colors.statusReviewBackground;
106+
case 'pending_publish': return colors.statusReadyBackground;
107+
default: return colors.statusDraftBackground;
108+
}
109+
}};
110+
`;
111+
92112
function EntryCard({
93113
path,
94114
summary,
95115
image,
96116
imageField,
97117
collectionLabel,
98118
viewStyle = VIEW_STYLE_LIST,
119+
workflowStatus,
99120
getAsset,
100121
}) {
101122
if (viewStyle === VIEW_STYLE_LIST) {
102123
return (
103124
<ListCard>
104125
<ListCardLink to={path}>
105126
{collectionLabel ? <CollectionLabel>{collectionLabel}</CollectionLabel> : null}
106-
<ListCardTitle>{summary}</ListCardTitle>
127+
<ListCardTitle>
128+
{summary}
129+
<TitleIcons>
130+
{workflowStatus && <StatusIcon type="circle" />}
131+
</TitleIcons>
132+
</ListCardTitle>
107133
</ListCardLink>
108134
</ListCard>
109135
);

packages/decap-cms-core/src/components/Collection/Entries/EntryListing.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
44
import styled from '@emotion/styled';
55
import { Waypoint } from 'react-waypoint';
66
import { Map } from 'immutable';
7+
import { connect } from 'react-redux';
78

9+
import { selectUnpublishedEntry } from '../../../reducers';
810
import { selectFields, selectInferredField } from '../../../reducers/collections';
911
import EntryCard from './EntryCard';
1012

@@ -17,7 +19,7 @@ const CardsGrid = styled.ul`
1719
margin-bottom: 16px;
1820
`;
1921

20-
export default class EntryListing extends React.Component {
22+
class EntryListing extends React.Component {
2123
static propTypes = {
2224
collections: ImmutablePropTypes.iterable.isRequired,
2325
entries: ImmutablePropTypes.list,
@@ -53,7 +55,20 @@ export default class EntryListing extends React.Component {
5355
const { collections, entries, viewStyle } = this.props;
5456
const inferredFields = this.inferFields(collections);
5557
const entryCardProps = { collection: collections, inferredFields, viewStyle };
56-
return entries.map((entry, idx) => <EntryCard {...entryCardProps} entry={entry} key={idx} />);
58+
59+
return entries.map((entry, idx) => {
60+
const workflowStatus = this.props.getWorkflowStatus(collections.get('name'), entry.get('slug'));
61+
console.log('workflowStatus', workflowStatus);
62+
63+
return (
64+
<EntryCard
65+
{...entryCardProps}
66+
entry={entry}
67+
workflowStatus={workflowStatus}
68+
key={idx}
69+
/>
70+
);
71+
});
5772
};
5873

5974
renderCardsForMultipleCollections = () => {
@@ -84,3 +99,16 @@ export default class EntryListing extends React.Component {
8499
);
85100
}
86101
}
102+
103+
function mapStateToProps(state) {
104+
return {
105+
getWorkflowStatus: (collectionName, slug) => {
106+
107+
const unpublishedEntry = selectUnpublishedEntry(state, collectionName, slug);
108+
console.log('getWorkflowStatus', unpublishedEntry);
109+
return unpublishedEntry ? unpublishedEntry.get('status') : null;
110+
}
111+
};
112+
}
113+
114+
export default connect(mapStateToProps)(EntryListing);

0 commit comments

Comments
 (0)