Skip to content

Commit 009f770

Browse files
author
Gustav Hansen
committed
Chore: Remove cellFormatter callback and inline columns in list-view
1 parent e0c7d79 commit 009f770

File tree

5 files changed

+104
-55
lines changed

5 files changed

+104
-55
lines changed

packages/core/admin/admin/src/content-manager/pages/ListView/components/TableRows/index.js

Lines changed: 86 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
11
import React from 'react';
22

3-
import { BaseCheckbox, IconButton, Tbody, Td, Tr, Flex } from '@strapi/design-system';
3+
import {
4+
BaseCheckbox,
5+
IconButton,
6+
Tbody,
7+
Td,
8+
Tr,
9+
Flex,
10+
lightTheme,
11+
Status,
12+
Typography,
13+
} from '@strapi/design-system';
414
import { useTracking, useFetchClient, useAPIErrorHandler } from '@strapi/helper-plugin';
515
import { Trash, Duplicate, Pencil } from '@strapi/icons';
616
import { AxiosError } from 'axios';
717
import PropTypes from 'prop-types';
818
import { useIntl } from 'react-intl';
919
import { Link, useHistory } from 'react-router-dom';
1020

21+
import { useEnterprise } from '../../../../../hooks/useEnterprise';
1122
import { getFullName } from '../../../../../utils';
1223
import { usePluginsQueryParams } from '../../../../hooks';
1324
import { getTrad } from '../../../../utils';
1425
import CellContent from '../CellContent';
1526

27+
const REVIEW_WORKFLOW_COLUMNS_CE = () => null;
28+
1629
export const TableRows = ({
1730
canCreate,
1831
canDelete,
1932
contentType,
33+
features: { hasDraftAndPublish, hasReviewWorkflows },
2034
headers,
2135
entriesToDelete,
2236
onClickDelete,
@@ -33,6 +47,18 @@ export const TableRows = ({
3347
const { trackUsage } = useTracking();
3448
const pluginsQueryParams = usePluginsQueryParams();
3549
const { formatAPIError } = useAPIErrorHandler(getTrad);
50+
const ReviewWorkflowsStage = useEnterprise(
51+
REVIEW_WORKFLOW_COLUMNS_CE,
52+
async () =>
53+
(
54+
await import(
55+
'../../../../../../../ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn'
56+
)
57+
).ReviewWorkflowsStageEE,
58+
{
59+
enabled: hasReviewWorkflows,
60+
}
61+
);
3662

3763
/**
3864
*
@@ -74,6 +100,11 @@ export const TableRows = ({
74100
}
75101
};
76102

103+
// block rendering until the review stage component is fully loaded in EE
104+
if (!ReviewWorkflowsStage) {
105+
return null;
106+
}
107+
77108
/**
78109
* Table Cells with actions e.g edit, delete, duplicate have `stopPropagation`
79110
* to prevent the row from being selected.
@@ -113,20 +144,59 @@ export const TableRows = ({
113144
/>
114145
</Td>
115146
)}
147+
116148
{headers.map(({ key, cellFormatter, name, ...rest }) => {
149+
if (hasDraftAndPublish && name === 'publishedAt') {
150+
return (
151+
<Td key={key}>
152+
<Status
153+
width="min-content"
154+
showBullet={false}
155+
variant={data.publishedAt ? 'success' : 'secondary'}
156+
size="S"
157+
>
158+
<Typography
159+
fontWeight="bold"
160+
textColor={`${data.publishedAt ? 'success' : 'secondary'}700`}
161+
>
162+
{formatMessage({
163+
id: getTrad(
164+
`containers.List.${data.publishedAt ? 'published' : 'draft'}`
165+
),
166+
defaultMessage: data.publishedAt ? 'Published' : 'Draft',
167+
})}
168+
</Typography>
169+
</Status>
170+
</Td>
171+
);
172+
}
173+
174+
if (hasReviewWorkflows && name === 'strapi_reviewWorkflows_stage') {
175+
return (
176+
<Td key={key}>
177+
{data.strapi_reviewWorkflows_stage ? (
178+
<ReviewWorkflowsStage
179+
color={
180+
data.strapi_reviewWorkflows_stage.color ?? lightTheme.colors.primary600
181+
}
182+
name={data.strapi_reviewWorkflows_stage.name}
183+
/>
184+
) : (
185+
<Typography textColor="neutral800">-</Typography>
186+
)}
187+
</Td>
188+
);
189+
}
190+
117191
return (
118192
<Td key={key}>
119-
{typeof cellFormatter === 'function' ? (
120-
cellFormatter(data, { key, name, ...rest })
121-
) : (
122-
<CellContent
123-
content={data[name.split('.')[0]]}
124-
name={name}
125-
contentType={contentType}
126-
{...rest}
127-
rowId={data.id}
128-
/>
129-
)}
193+
<CellContent
194+
content={data[name.split('.')[0]]}
195+
name={name}
196+
contentType={contentType}
197+
{...rest}
198+
rowId={data.id}
199+
/>
130200
</Td>
131201
);
132202
})}
@@ -212,6 +282,10 @@ TableRows.propTypes = {
212282
uid: PropTypes.string.isRequired,
213283
}).isRequired,
214284
entriesToDelete: PropTypes.array,
285+
features: PropTypes.shape({
286+
hasDraftAndPublish: PropTypes.bool.isRequired,
287+
hasReviewWorkflows: PropTypes.bool.isRequired,
288+
}).isRequired,
215289
headers: PropTypes.array.isRequired,
216290
onClickDelete: PropTypes.func,
217291
onSelectRow: PropTypes.func,

packages/core/admin/admin/src/content-manager/pages/ListView/index.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import {
1010
HeaderLayout,
1111
useNotifyAT,
1212
Flex,
13-
Typography,
14-
Status,
1513
} from '@strapi/design-system';
1614
import {
1715
NoPermissions,
@@ -109,8 +107,11 @@ function ListView({
109107
const { pathname } = useLocation();
110108
const { push } = useHistory();
111109
const { formatMessage } = useIntl();
112-
const hasDraftAndPublish = options?.draftAndPublish || false;
113110
const fetchClient = useFetchClient();
111+
112+
const hasDraftAndPublish = options?.draftAndPublish ?? false;
113+
const hasReviewWorkflows = options?.reviewWorkflows ?? false;
114+
114115
const reviewWorkflowColumns = useEnterprise(
115116
REVIEW_WORKFLOW_COLUMNS_CE,
116117
async () =>
@@ -418,27 +419,17 @@ function ListView({
418419
searchable: false,
419420
sortable: true,
420421
},
421-
// eslint-disable-next-line react/no-unstable-nested-components
422-
cellFormatter(cellData) {
423-
const isPublished = cellData.publishedAt;
424-
const variant = isPublished ? 'success' : 'secondary';
425-
426-
return (
427-
<Status width="min-content" showBullet={false} variant={variant} size="S">
428-
<Typography fontWeight="bold" textColor={`${variant}700`}>
429-
{formatMessage({
430-
id: getTrad(`containers.List.${isPublished ? 'published' : 'draft'}`),
431-
defaultMessage: isPublished ? 'Published' : 'Draft',
432-
})}
433-
</Typography>
434-
</Status>
435-
);
436-
},
437422
});
438423
}
439424

440425
if (reviewWorkflowColumns) {
441-
reviewWorkflowColumns.metadatas.label = formatMessage(reviewWorkflowColumns.metadatas.label);
426+
// Make sure the column header label is translated
427+
if (typeof reviewWorkflowColumns.metadatas.label !== 'string') {
428+
reviewWorkflowColumns.metadatas.label = formatMessage(
429+
reviewWorkflowColumns.metadatas.label
430+
);
431+
}
432+
442433
formattedHeaders.push(reviewWorkflowColumns);
443434
}
444435

@@ -593,6 +584,10 @@ function ListView({
593584
canCreate={canCreate}
594585
canDelete={canDelete}
595586
contentType={contentType}
587+
features={{
588+
hasDraftAndPublish,
589+
hasReviewWorkflows,
590+
}}
596591
headers={tableHeaders}
597592
rows={data}
598593
withBulkActions
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import React from 'react';
2-
3-
import { Typography } from '@strapi/design-system';
4-
51
import getTrad from '../../../../../../admin/src/content-manager/utils/getTrad';
6-
import { STAGE_COLOR_DEFAULT } from '../../../../pages/SettingsPage/pages/ReviewWorkflows/constants';
7-
8-
import ReviewWorkflowsStage from '.';
92

103
export const REVIEW_WORKFLOW_COLUMNS_EE = {
114
key: '__strapi_reviewWorkflows_stage_temp_key__',
@@ -28,15 +21,4 @@ export const REVIEW_WORKFLOW_COLUMNS_EE = {
2821
},
2922
},
3023
},
31-
cellFormatter({ strapi_reviewWorkflows_stage }) {
32-
// if entities are created e.g. through lifecycle methods
33-
// they may not have a stage assigned
34-
if (!strapi_reviewWorkflows_stage) {
35-
return <Typography textColor="neutral800">-</Typography>;
36-
}
37-
38-
const { color, name } = strapi_reviewWorkflows_stage;
39-
40-
return <ReviewWorkflowsStage color={color ?? STAGE_COLOR_DEFAULT} name={name} />;
41-
},
4224
};
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
import { ReviewWorkflowsStageEE } from './ReviewWorkflowsStageEE';
2-
3-
export default ReviewWorkflowsStageEE;
1+
export * from './ReviewWorkflowsStageEE';

packages/core/admin/ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn/tests/ReviewWorkflowsStage.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { lightTheme, ThemeProvider } from '@strapi/design-system';
44
import { render } from '@testing-library/react';
55
import { IntlProvider } from 'react-intl';
66

7-
import ReviewWorkflowsStage from '..';
7+
import { ReviewWorkflowsStageEE } from '..';
88

99
const ComponentFixture = (props) => (
1010
<ThemeProvider theme={lightTheme}>
1111
<IntlProvider locale="en" messages={{}}>
12-
<ReviewWorkflowsStage {...props} />
12+
<ReviewWorkflowsStageEE {...props} />
1313
</IntlProvider>
1414
</ThemeProvider>
1515
);

0 commit comments

Comments
 (0)