mirror of
https://github.com/strapi/strapi.git
synced 2025-08-10 17:58:07 +00:00
Merge pull request #17277 from strapi/fix/review-workflow-assignee-list-view
This commit is contained in:
commit
cd2903743b
@ -52,14 +52,15 @@ export const TableRows = ({
|
||||
const pluginsQueryParams = usePluginsQueryParams();
|
||||
const [{ query }] = useQueryParams();
|
||||
const { formatAPIError } = useAPIErrorHandler(getTrad);
|
||||
const ReviewWorkflowsStage = useEnterprise(
|
||||
const ReviewWorkflowsColumns = useEnterprise(
|
||||
REVIEW_WORKFLOW_COLUMNS_CE,
|
||||
async () =>
|
||||
(
|
||||
await import(
|
||||
'../../../../../../../ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn'
|
||||
)
|
||||
).ReviewWorkflowsStageEE,
|
||||
async () => {
|
||||
const { ReviewWorkflowsStageEE, ReviewWorkflowsAssigneeEE } = await import(
|
||||
'../../../../../../../ee/admin/content-manager/pages/ListView/ReviewWorkflowsColumn'
|
||||
);
|
||||
|
||||
return { ReviewWorkflowsStageEE, ReviewWorkflowsAssigneeEE };
|
||||
},
|
||||
{
|
||||
enabled: hasReviewWorkflows,
|
||||
}
|
||||
@ -108,7 +109,7 @@ export const TableRows = ({
|
||||
};
|
||||
|
||||
// block rendering until the review stage component is fully loaded in EE
|
||||
if (!ReviewWorkflowsStage) {
|
||||
if (!ReviewWorkflowsColumns) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -178,19 +179,36 @@ export const TableRows = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (hasReviewWorkflows && name === 'strapi_reviewWorkflows_stage') {
|
||||
return (
|
||||
<Td key={key}>
|
||||
{data.strapi_reviewWorkflows_stage ? (
|
||||
<ReviewWorkflowsStage
|
||||
color={data.strapi_reviewWorkflows_stage.color}
|
||||
name={data.strapi_reviewWorkflows_stage.name}
|
||||
/>
|
||||
) : (
|
||||
<Typography textColor="neutral800">-</Typography>
|
||||
)}
|
||||
</Td>
|
||||
);
|
||||
if (hasReviewWorkflows) {
|
||||
if (name === 'strapi_reviewWorkflows_stage') {
|
||||
return (
|
||||
<Td key={key}>
|
||||
{data.strapi_reviewWorkflows_stage ? (
|
||||
<ReviewWorkflowsColumns.ReviewWorkflowsStageEE
|
||||
color={data.strapi_reviewWorkflows_stage.color}
|
||||
name={data.strapi_reviewWorkflows_stage.name}
|
||||
/>
|
||||
) : (
|
||||
<Typography textColor="neutral800">-</Typography>
|
||||
)}
|
||||
</Td>
|
||||
);
|
||||
}
|
||||
if (name === 'strapi_assignee') {
|
||||
return (
|
||||
<Td key={key}>
|
||||
{data.strapi_assignee ? (
|
||||
<ReviewWorkflowsColumns.ReviewWorkflowsAssigneeEE
|
||||
firstname={data.strapi_assignee.firstname}
|
||||
lastname={data?.strapi_assignee?.lastname}
|
||||
displayname={data?.strapi_assignee?.username}
|
||||
/>
|
||||
) : (
|
||||
<Typography textColor="neutral800">-</Typography>
|
||||
)}
|
||||
</Td>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -422,13 +422,15 @@ function ListView({
|
||||
|
||||
if (reviewWorkflowColumns) {
|
||||
// Make sure the column header label is translated
|
||||
if (typeof reviewWorkflowColumns.metadatas.label !== 'string') {
|
||||
reviewWorkflowColumns.metadatas.label = formatMessage(
|
||||
reviewWorkflowColumns.metadatas.label
|
||||
);
|
||||
}
|
||||
reviewWorkflowColumns.map((column) => {
|
||||
if (typeof column.metadatas.label !== 'string') {
|
||||
column.metadatas.label = formatMessage(column.metadatas.label);
|
||||
}
|
||||
|
||||
formattedHeaders.push(reviewWorkflowColumns);
|
||||
return column;
|
||||
});
|
||||
|
||||
formattedHeaders.push(...reviewWorkflowColumns);
|
||||
}
|
||||
|
||||
return formattedHeaders;
|
||||
|
@ -0,0 +1,51 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Typography } from '@strapi/design-system';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import getTrad from '../../../../../../admin/src/content-manager/utils/getTrad';
|
||||
|
||||
export function ReviewWorkflowsAssigneeEE({ firstname, lastname, displayname }) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
// TODO align with changes from this PR, using the getDisplayName util
|
||||
// https://github.com/strapi/strapi/pull/17043/
|
||||
if (displayname) {
|
||||
return (
|
||||
<Typography textColor="neutral800">
|
||||
{formatMessage(
|
||||
{
|
||||
id: getTrad(`containers.ListPage.reviewWorkflows.assignee`),
|
||||
defaultMessage: '{displayname}',
|
||||
},
|
||||
{ displayname }
|
||||
)}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Typography textColor="neutral800">
|
||||
{formatMessage(
|
||||
{
|
||||
id: getTrad(`containers.ListPage.reviewWorkflows.assignee`),
|
||||
defaultMessage: '{firstname} {lastname}',
|
||||
},
|
||||
{ firstname, lastname }
|
||||
)}
|
||||
</Typography>
|
||||
);
|
||||
}
|
||||
|
||||
ReviewWorkflowsAssigneeEE.defaultProps = {
|
||||
firstname: '',
|
||||
lastname: '',
|
||||
displayname: '',
|
||||
};
|
||||
|
||||
ReviewWorkflowsAssigneeEE.propTypes = {
|
||||
firstname: PropTypes.string,
|
||||
lastname: PropTypes.string,
|
||||
displayname: PropTypes.string,
|
||||
};
|
@ -1,24 +1,45 @@
|
||||
import getTrad from '../../../../../../admin/src/content-manager/utils/getTrad';
|
||||
import {
|
||||
ASSIGNEE_ATTRIBUTE_NAME,
|
||||
STAGE_ATTRIBUTE_NAME,
|
||||
} from '../../EditView/InformationBox/constants';
|
||||
|
||||
export const REVIEW_WORKFLOW_COLUMNS_EE = {
|
||||
key: '__strapi_reviewWorkflows_stage_temp_key__',
|
||||
name: 'strapi_reviewWorkflows_stage',
|
||||
fieldSchema: {
|
||||
type: 'relation',
|
||||
},
|
||||
metadatas: {
|
||||
// formatMessage() will be applied when the column is rendered
|
||||
label: {
|
||||
id: getTrad(`containers.ListPage.table-headers.reviewWorkflows.stage`),
|
||||
defaultMessage: 'Review stage',
|
||||
export const REVIEW_WORKFLOW_COLUMNS_EE = [
|
||||
{
|
||||
key: `__${STAGE_ATTRIBUTE_NAME}_temp_key__`,
|
||||
name: STAGE_ATTRIBUTE_NAME,
|
||||
fieldSchema: {
|
||||
type: 'relation',
|
||||
},
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
mainField: {
|
||||
name: 'name',
|
||||
schema: {
|
||||
type: 'string',
|
||||
metadatas: {
|
||||
// formatMessage() will be applied when the column is rendered
|
||||
label: {
|
||||
id: getTrad(`containers.ListPage.table-headers.reviewWorkflows.stage`),
|
||||
defaultMessage: 'Review stage',
|
||||
},
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
mainField: {
|
||||
name: 'name',
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
{
|
||||
key: `__${ASSIGNEE_ATTRIBUTE_NAME}_temp_key__`,
|
||||
name: ASSIGNEE_ATTRIBUTE_NAME,
|
||||
fieldSchema: {
|
||||
type: 'relation',
|
||||
},
|
||||
metadatas: {
|
||||
label: {
|
||||
id: getTrad(`containers.ListPage.table-headers.reviewWorkflows.assignee`),
|
||||
defaultMessage: 'Assignee',
|
||||
},
|
||||
searchable: false,
|
||||
sortable: false,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
@ -1,95 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Typography } from '@strapi/design-system';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import getTrad from '../../../../../../admin/src/content-manager/utils/getTrad';
|
||||
import { STAGE_COLOR_DEFAULT } from '../../../../pages/SettingsPage/pages/ReviewWorkflows/constants';
|
||||
|
||||
import { ReviewWorkflowsStageEE } from '.';
|
||||
|
||||
export default (layout) => {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
// TODO: As soon as the feature was enabled in EE mode, the BE currently does not have a way to send
|
||||
// `false` once a user is in CE mode again. We shouldn't have to perform the window.strapi.isEE check here
|
||||
// and it is meant to be in interim solution until we find a better one.
|
||||
const hasReviewWorkflows =
|
||||
(window.strapi.features.isEnabled(window.strapi.features.REVIEW_WORKFLOWS) &&
|
||||
layout.contentType.options?.reviewWorkflows) ??
|
||||
false;
|
||||
|
||||
if (!hasReviewWorkflows) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
key: '__strapi_reviewWorkflows_stage_temp_key__',
|
||||
name: 'strapi_reviewWorkflows_stage',
|
||||
fieldSchema: {
|
||||
type: 'relation',
|
||||
},
|
||||
metadatas: {
|
||||
label: formatMessage({
|
||||
id: getTrad(`containers.ListPage.table-headers.reviewWorkflows.stage`),
|
||||
defaultMessage: 'Review stage',
|
||||
}),
|
||||
searchable: false,
|
||||
sortable: true,
|
||||
mainField: {
|
||||
name: 'name',
|
||||
schema: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
cellFormatter({ strapi_reviewWorkflows_stage }) {
|
||||
// if entities are created e.g. through lifecycle methods
|
||||
// they may not have a stage assigned
|
||||
if (!strapi_reviewWorkflows_stage) {
|
||||
return <Typography textColor="neutral800">-</Typography>;
|
||||
}
|
||||
|
||||
const { color, name } = strapi_reviewWorkflows_stage;
|
||||
|
||||
return <ReviewWorkflowsStageEE color={color ?? STAGE_COLOR_DEFAULT} name={name} />;
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
key: '__strapi_reviewWorkflows_assignee_temp_key__',
|
||||
name: 'strapi_reviewWorkflows_assignee',
|
||||
fieldSchema: {
|
||||
type: 'relation',
|
||||
},
|
||||
metadatas: {
|
||||
label: formatMessage({
|
||||
id: getTrad(`containers.ListPage.table-headers.reviewWorkflows.assignee`),
|
||||
defaultMessage: 'Assignee',
|
||||
}),
|
||||
searchable: false,
|
||||
sortable: false,
|
||||
},
|
||||
cellFormatter({ strapi_assignee }) {
|
||||
if (!strapi_assignee) {
|
||||
return <Typography textColor="neutral800">-</Typography>;
|
||||
}
|
||||
|
||||
const { firstname, lastname } = strapi_assignee;
|
||||
|
||||
return (
|
||||
<Typography textColor="neutral800">
|
||||
{formatMessage(
|
||||
{
|
||||
id: getTrad(`containers.ListPage.reviewWorkflows.assignee`),
|
||||
defaultMessage: '{firstname} {lastname}',
|
||||
},
|
||||
{ firstname, lastname }
|
||||
)}
|
||||
</Typography>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
@ -1 +1,2 @@
|
||||
export * from './ReviewWorkflowsStageEE';
|
||||
export * from './ReviewWorkflowsAssigneeEE';
|
||||
|
@ -0,0 +1,31 @@
|
||||
import React from 'react';
|
||||
|
||||
import { lightTheme, ThemeProvider } from '@strapi/design-system';
|
||||
import { render } from '@testing-library/react';
|
||||
import { IntlProvider } from 'react-intl';
|
||||
|
||||
import { ReviewWorkflowsAssigneeEE } from '..';
|
||||
|
||||
const ComponentFixture = (props) => (
|
||||
<ThemeProvider theme={lightTheme}>
|
||||
<IntlProvider locale="en" messages={{}}>
|
||||
<ReviewWorkflowsAssigneeEE {...props} />
|
||||
</IntlProvider>
|
||||
</ThemeProvider>
|
||||
);
|
||||
|
||||
const setup = (props) => render(<ComponentFixture {...props} />);
|
||||
|
||||
describe('DynamicTable | ReviewWorkflowsAssignee', () => {
|
||||
test('will use displayname over first and last name', () => {
|
||||
const displayname = 'Display Name';
|
||||
const { getByText } = setup({ displayname });
|
||||
|
||||
expect(getByText(displayname)).toBeInTheDocument();
|
||||
});
|
||||
test('render assignee name', () => {
|
||||
const { getByText } = setup({ firstname: 'Kai', lastname: 'Doe' });
|
||||
|
||||
expect(getByText('Kai Doe')).toBeInTheDocument();
|
||||
});
|
||||
});
|
@ -67,7 +67,7 @@ describe('Review workflows - Stages service', () => {
|
||||
toId
|
||||
);
|
||||
expect(entityServiceMock.update).toBeCalledWith(uid, id, {
|
||||
data: { strapi_assignee: toId },
|
||||
data: { [ENTITY_ASSIGNEE_ATTRIBUTE]: toId },
|
||||
fields: [],
|
||||
populate: [ENTITY_ASSIGNEE_ATTRIBUTE],
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user