mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 06:50:51 +00:00
publicationState and translations
This commit is contained in:
parent
15f9b9094a
commit
94eb2c631a
@ -36,10 +36,9 @@ export const RelationInput = ({
|
|||||||
onSearchNextPage,
|
onSearchNextPage,
|
||||||
onSearch,
|
onSearch,
|
||||||
placeholder,
|
placeholder,
|
||||||
|
publicationStateTranslations,
|
||||||
searchResults,
|
searchResults,
|
||||||
}) => {
|
}) => {
|
||||||
const { data } = searchResults;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Field error={error} name={name} hint={description} id={id}>
|
<Field error={error} name={name} hint={description} id={id}>
|
||||||
<Relation
|
<Relation
|
||||||
@ -48,7 +47,7 @@ export const RelationInput = ({
|
|||||||
<FieldLabel>{label}</FieldLabel>
|
<FieldLabel>{label}</FieldLabel>
|
||||||
<ReactSelect
|
<ReactSelect
|
||||||
components={{ Option }}
|
components={{ Option }}
|
||||||
options={data?.pages || []}
|
options={searchResults.data.pages.flat()}
|
||||||
isDisabled={disabled}
|
isDisabled={disabled}
|
||||||
error={error}
|
error={error}
|
||||||
inputId={id}
|
inputId={id}
|
||||||
@ -74,8 +73,8 @@ export const RelationInput = ({
|
|||||||
<RelationList height={listHeight}>
|
<RelationList height={listHeight}>
|
||||||
{relations.isSuccess &&
|
{relations.isSuccess &&
|
||||||
relations.data.pages.flatMap((relation) => {
|
relations.data.pages.flatMap((relation) => {
|
||||||
const { isDraft, href, mainField, id } = relation;
|
const { publicationState, href, mainField, id } = relation;
|
||||||
const badgeColor = isDraft ? 'secondary' : 'success';
|
const badgeColor = publicationState === 'draft' ? 'secondary' : 'success';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RelationItem
|
<RelationItem
|
||||||
@ -101,15 +100,16 @@ export const RelationInput = ({
|
|||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
{/* TO FIX: not showing badge if D&P is not activated */}
|
{publicationState && (
|
||||||
<Badge
|
<Badge
|
||||||
borderSize={1}
|
borderSize={1}
|
||||||
borderColor={`${badgeColor}200`}
|
borderColor={`${badgeColor}200`}
|
||||||
backgroundColor={`${badgeColor}100`}
|
backgroundColor={`${badgeColor}100`}
|
||||||
textColor={`${badgeColor}700`}
|
textColor={`${badgeColor}700`}
|
||||||
>
|
>
|
||||||
{isDraft ? 'Draft' : 'Published'}
|
{publicationStateTranslations[publicationState]}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
)}
|
||||||
</RelationItem>
|
</RelationItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
@ -129,7 +129,7 @@ const ReactQueryRelationResult = PropTypes.shape({
|
|||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
href: PropTypes.string,
|
href: PropTypes.string,
|
||||||
id: PropTypes.number.isRequired,
|
id: PropTypes.number.isRequired,
|
||||||
isDraft: PropTypes.bool,
|
publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||||
mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
@ -144,6 +144,7 @@ const ReactQuerySearchResult = PropTypes.shape({
|
|||||||
PropTypes.shape({
|
PropTypes.shape({
|
||||||
isDraft: PropTypes.bool,
|
isDraft: PropTypes.bool,
|
||||||
mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
|
publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
@ -177,6 +178,10 @@ RelationInput.propTypes = {
|
|||||||
onSearch: PropTypes.func.isRequired,
|
onSearch: PropTypes.func.isRequired,
|
||||||
onSearchNextPage: PropTypes.func.isRequired,
|
onSearchNextPage: PropTypes.func.isRequired,
|
||||||
placeholder: PropTypes.string.isRequired,
|
placeholder: PropTypes.string.isRequired,
|
||||||
|
publicationStateTranslations: PropTypes.shape({
|
||||||
|
draft: PropTypes.string.isRequired,
|
||||||
|
published: PropTypes.string.isRequired,
|
||||||
|
}).isRequired,
|
||||||
searchResults: ReactQuerySearchResult,
|
searchResults: ReactQuerySearchResult,
|
||||||
relations: ReactQueryRelationResult,
|
relations: ReactQueryRelationResult,
|
||||||
};
|
};
|
||||||
|
@ -26,16 +26,24 @@ WIP
|
|||||||
labelLoadMore="Load More"
|
labelLoadMore="Load More"
|
||||||
listHeight="200px"
|
listHeight="200px"
|
||||||
name="options"
|
name="options"
|
||||||
|
publicationStateTranslations={{ draft: 'Draft', published: 'Published' }}
|
||||||
searchResults={{
|
searchResults={{
|
||||||
data: {
|
data: {
|
||||||
pages: [
|
pages: [
|
||||||
{
|
{
|
||||||
isDraft: true,
|
isDraft: true,
|
||||||
mainField: 'Relation 6',
|
mainField: 'Relation 6',
|
||||||
|
publicationState: 'draft',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
isDraft: false,
|
isDraft: false,
|
||||||
mainField: 'Relation 7',
|
mainField: 'Relation 7',
|
||||||
|
publicationState: 'published',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
isDraft: false,
|
||||||
|
mainField: 'Relation 8',
|
||||||
|
publicationState: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -49,30 +57,31 @@ WIP
|
|||||||
id: 1,
|
id: 1,
|
||||||
href: '/',
|
href: '/',
|
||||||
mainField: 'Relation 1',
|
mainField: 'Relation 1',
|
||||||
|
publicationState: 'draft',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
href: '',
|
href: '',
|
||||||
mainField: 'Relation 2',
|
mainField: 'Relation 2',
|
||||||
isDraft: true,
|
publicationState: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
href: '',
|
href: '',
|
||||||
mainField: 'Relation 3',
|
mainField: 'Relation 3',
|
||||||
isDraft: false,
|
publicationState: 'published',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
href: '',
|
href: '',
|
||||||
mainField: 'Relation 4',
|
mainField: 'Relation 4',
|
||||||
isDraft: false,
|
publicationState: 'draft',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
href: '',
|
href: '',
|
||||||
mainField: 'Relation 5',
|
mainField: 'Relation 5',
|
||||||
isDraft: true,
|
publicationState: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -3,7 +3,6 @@ import styled from 'styled-components';
|
|||||||
import { components } from 'react-select';
|
import { components } from 'react-select';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { get, has } from 'lodash';
|
|
||||||
import { Flex } from '@strapi/design-system/Flex';
|
import { Flex } from '@strapi/design-system/Flex';
|
||||||
import { Typography } from '@strapi/design-system/Typography';
|
import { Typography } from '@strapi/design-system/Typography';
|
||||||
|
|
||||||
@ -20,12 +19,12 @@ const StyledBullet = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export const Option = (props) => {
|
export const Option = (props) => {
|
||||||
console.log(props);
|
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const Component = components.Option;
|
const Component = components.Option;
|
||||||
const hasDraftAndPublish = has(get(props, 'data'), 'isDraft');
|
const { publicationState, mainField } = props.data;
|
||||||
|
|
||||||
if (hasDraftAndPublish) {
|
if (publicationState) {
|
||||||
|
const isDraft = publicationState === 'draft';
|
||||||
// To fix: use getTrad utils from CM once component is migrated into CM components
|
// To fix: use getTrad utils from CM once component is migrated into CM components
|
||||||
const draftMessage = {
|
const draftMessage = {
|
||||||
id: 'content-manager.components.Select.draft-info-title',
|
id: 'content-manager.components.Select.draft-info-title',
|
||||||
@ -36,20 +35,19 @@ export const Option = (props) => {
|
|||||||
id: 'content-manager.components.Select.publish-info-title',
|
id: 'content-manager.components.Select.publish-info-title',
|
||||||
defaultMessage: 'State: Published',
|
defaultMessage: 'State: Published',
|
||||||
};
|
};
|
||||||
const { isDraft } = props.data;
|
|
||||||
const title = isDraft ? formatMessage(draftMessage) : formatMessage(publishedMessage);
|
const title = isDraft ? formatMessage(draftMessage) : formatMessage(publishedMessage);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Component {...props}>
|
<Component {...props}>
|
||||||
<Flex>
|
<Flex>
|
||||||
<StyledBullet title={title} isDraft={isDraft} />
|
<StyledBullet title={title} isDraft={isDraft} />
|
||||||
<Typography ellipsis>{props.data.mainField || '-'}</Typography>
|
<Typography ellipsis>{mainField ?? '-'}</Typography>
|
||||||
</Flex>
|
</Flex>
|
||||||
</Component>
|
</Component>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Component {...props}>{props.data.mainField || '-'}</Component>;
|
return <Component {...props}>{mainField ?? '-'}</Component>;
|
||||||
};
|
};
|
||||||
|
|
||||||
Option.propTypes = {
|
Option.propTypes = {
|
||||||
@ -57,5 +55,6 @@ Option.propTypes = {
|
|||||||
data: PropTypes.shape({
|
data: PropTypes.shape({
|
||||||
isDraft: PropTypes.bool,
|
isDraft: PropTypes.bool,
|
||||||
mainField: PropTypes.string,
|
mainField: PropTypes.string,
|
||||||
|
publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||||
}).isRequired,
|
}).isRequired,
|
||||||
};
|
};
|
||||||
|
@ -17,7 +17,7 @@ const setup = (props) =>
|
|||||||
|
|
||||||
describe('RelationInput || Option', () => {
|
describe('RelationInput || Option', () => {
|
||||||
it('should render custom Option with published state title', () => {
|
it('should render custom Option with published state title', () => {
|
||||||
setup({ options: [{ mainField: 'relation 1', isDraft: false }] });
|
setup({ options: [{ mainField: 'relation 1', publicationState: 'published' }] });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
fireEvent.mouseDown(screen.getByRole('button'));
|
fireEvent.mouseDown(screen.getByRole('button'));
|
||||||
@ -28,7 +28,7 @@ describe('RelationInput || Option', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should render custom Option with draft state title', () => {
|
it('should render custom Option with draft state title', () => {
|
||||||
setup({ options: [{ mainField: 'relation 1', isDraft: true }] });
|
setup({ options: [{ mainField: 'relation 1', publicationState: 'draft' }] });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
fireEvent.mouseDown(screen.getByRole('button'));
|
fireEvent.mouseDown(screen.getByRole('button'));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user