mirror of
https://github.com/strapi/strapi.git
synced 2025-11-14 01:02:04 +00:00
Feature: Allow review workflow stage column as default sort option
This commit is contained in:
parent
54c54fabf3
commit
c020a6c78d
@ -10,14 +10,36 @@ import {
|
|||||||
ToggleInput,
|
ToggleInput,
|
||||||
Typography,
|
Typography,
|
||||||
} from '@strapi/design-system';
|
} from '@strapi/design-system';
|
||||||
|
import { useCollator } from '@strapi/helper-plugin';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
|
|
||||||
|
import { useEnterprise } from '../../../../hooks/useEnterprise';
|
||||||
import { getTrad } from '../../../utils';
|
import { getTrad } from '../../../utils';
|
||||||
|
|
||||||
export const Settings = ({ modifiedData, onChange, sortOptions }) => {
|
export const Settings = ({ contentTypeOptions, modifiedData, onChange, sortOptions: sortOptionsCE }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage, locale } = useIntl();
|
||||||
const { settings, metadatas } = modifiedData;
|
const formatter = useCollator(locale, {
|
||||||
|
sensitivity: 'base',
|
||||||
|
});
|
||||||
|
const sortOptions = useEnterprise(
|
||||||
|
sortOptionsCE,
|
||||||
|
async () =>
|
||||||
|
(await import('../../../../../../ee/admin/content-manager/pages/ListSettingsView/constants'))
|
||||||
|
.REVIEW_WORKFLOW_STAGE_SORT_OPTION_NAME,
|
||||||
|
{
|
||||||
|
combine(ceOptions, eeOption) {
|
||||||
|
return [...ceOptions, { ...eeOption, label: formatMessage(eeOption.label) }];
|
||||||
|
},
|
||||||
|
|
||||||
|
defaultValue: sortOptionsCE,
|
||||||
|
|
||||||
|
enabled: !!contentTypeOptions?.reviewWorkflows,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const sortOptionsSorted = sortOptions.sort((a, b) => formatter.compare(a.label, b.label));
|
||||||
|
const { settings } = modifiedData;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex direction="column" alignItems="stretch" gap={4}>
|
<Flex direction="column" alignItems="stretch" gap={4}>
|
||||||
@ -129,9 +151,9 @@ export const Settings = ({ modifiedData, onChange, sortOptions }) => {
|
|||||||
name="settings.defaultSortBy"
|
name="settings.defaultSortBy"
|
||||||
value={modifiedData.settings.defaultSortBy || ''}
|
value={modifiedData.settings.defaultSortBy || ''}
|
||||||
>
|
>
|
||||||
{sortOptions.map((sortBy) => (
|
{sortOptionsSorted.map(({ value, label }) => (
|
||||||
<Option key={sortBy} value={sortBy}>
|
<Option key={value} value={value}>
|
||||||
{metadatas[sortBy].list.label || sortBy}
|
{label}
|
||||||
</Option>
|
</Option>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
@ -164,7 +186,13 @@ Settings.defaultProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Settings.propTypes = {
|
Settings.propTypes = {
|
||||||
|
contentTypeOptions: PropTypes.object.isRequired,
|
||||||
modifiedData: PropTypes.object,
|
modifiedData: PropTypes.object,
|
||||||
onChange: PropTypes.func.isRequired,
|
onChange: PropTypes.func.isRequired,
|
||||||
sortOptions: PropTypes.array,
|
sortOptions: PropTypes.arrayOf(
|
||||||
|
PropTypes.shape({
|
||||||
|
value: PropTypes.string,
|
||||||
|
label: PropTypes.string,
|
||||||
|
}).isRequired
|
||||||
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
@ -55,7 +55,7 @@ const ListSettingsView = ({ layout, slug }) => {
|
|||||||
|
|
||||||
const isModalFormOpen = Object.keys(fieldForm).length !== 0;
|
const isModalFormOpen = Object.keys(fieldForm).length !== 0;
|
||||||
|
|
||||||
const { attributes } = layout;
|
const { attributes, options } = layout;
|
||||||
const displayedFields = modifiedData.layouts.list;
|
const displayedFields = modifiedData.layouts.list;
|
||||||
|
|
||||||
const goBackUrl = () => {
|
const goBackUrl = () => {
|
||||||
@ -179,7 +179,10 @@ const ListSettingsView = ({ layout, slug }) => {
|
|||||||
|
|
||||||
const sortOptions = Object.entries(attributes)
|
const sortOptions = Object.entries(attributes)
|
||||||
.filter(([, attribute]) => !EXCLUDED_SORT_ATTRIBUTE_TYPES.includes(attribute.type))
|
.filter(([, attribute]) => !EXCLUDED_SORT_ATTRIBUTE_TYPES.includes(attribute.type))
|
||||||
.map(([name]) => name);
|
.map(([name]) => ({
|
||||||
|
value: name,
|
||||||
|
label: layout.metadatas[name].list.label,
|
||||||
|
}));
|
||||||
|
|
||||||
const move = (originalIndex, atIndex) => {
|
const move = (originalIndex, atIndex) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
@ -235,6 +238,7 @@ const ListSettingsView = ({ layout, slug }) => {
|
|||||||
paddingRight={7}
|
paddingRight={7}
|
||||||
>
|
>
|
||||||
<Settings
|
<Settings
|
||||||
|
contentTypeOptions={options}
|
||||||
modifiedData={modifiedData}
|
modifiedData={modifiedData}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
sortOptions={sortOptions}
|
sortOptions={sortOptions}
|
||||||
|
|||||||
@ -0,0 +1,7 @@
|
|||||||
|
export const REVIEW_WORKFLOW_STAGE_SORT_OPTION_NAME = {
|
||||||
|
value: 'strapi_stage[name]',
|
||||||
|
label: {
|
||||||
|
id: 'settings.defaultSortOrder.reviewWorkflows.label',
|
||||||
|
defaultMessage: 'Review Stage',
|
||||||
|
},
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user