diff --git a/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js b/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js
index 550307eb41..f95b3aa2be 100644
--- a/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js
+++ b/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.js
@@ -36,6 +36,7 @@ export const RelationInput = ({
onSearchNextPage,
onSearch,
placeholder,
+ publicationStateTranslations,
searchResults,
}) => {
return (
@@ -46,7 +47,7 @@ export const RelationInput = ({
{label}
{relations.isSuccess &&
- relations.data.pages.flatMap((relation) => {
- const { isDraft, href, title, id } = relation;
- const badgeColor = isDraft ? 'secondary' : 'success';
+ relations.data.pages.flat().map((relation) => {
+ const { publicationState, href, mainField, id } = relation;
+ const badgeColor = publicationState === 'draft' ? 'secondary' : 'success';
return (
{href ? (
- {title}
+ {mainField}
) : (
- title
+ mainField
)}
- {isDraft !== undefined && (
+ {publicationState && (
- {isDraft ? 'Draft' : 'Published'}
+ {publicationStateTranslations[publicationState]}
)}
@@ -125,28 +126,35 @@ export const RelationInput = ({
const ReactQueryRelationResult = PropTypes.shape({
data: PropTypes.shape({
pages: PropTypes.arrayOf(
- PropTypes.shape({
- id: PropTypes.number.isRequired,
- isDraft: PropTypes.bool,
- href: PropTypes.string,
- title: PropTypes.string.isRequired,
- })
+ PropTypes.arrayOf(
+ PropTypes.shape({
+ href: PropTypes.string,
+ id: PropTypes.number.isRequired,
+ publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
+ mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
+ })
+ )
),
}),
isLoading: PropTypes.bool.isRequired,
isSuccess: PropTypes.bool.isRequired,
});
-const ReactQuerySearchResult = PropTypes.arrayOf(
- PropTypes.shape({
- label: PropTypes.string,
- value: {
- id: PropTypes.number,
- name: PropTypes.string,
- publishedAt: PropTypes.string,
- },
- })
-);
+const ReactQuerySearchResult = PropTypes.shape({
+ data: PropTypes.shape({
+ pages: PropTypes.arrayOf(
+ PropTypes.arrayOf(
+ PropTypes.shape({
+ id: PropTypes.number.isRequired,
+ mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
+ publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
+ })
+ )
+ ),
+ }),
+ isLoading: PropTypes.bool.isRequired,
+ isSuccess: PropTypes.bool.isRequired,
+});
RelationInput.defaultProps = {
description: undefined,
@@ -174,6 +182,10 @@ RelationInput.propTypes = {
onSearch: PropTypes.func.isRequired,
onSearchNextPage: PropTypes.func.isRequired,
placeholder: PropTypes.string.isRequired,
+ publicationStateTranslations: PropTypes.shape({
+ draft: PropTypes.string.isRequired,
+ published: PropTypes.string.isRequired,
+ }).isRequired,
searchResults: ReactQuerySearchResult,
relations: ReactQueryRelationResult,
};
diff --git a/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.stories.mdx b/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.stories.mdx
index f54992b644..2c9ebe85ca 100644
--- a/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.stories.mdx
+++ b/packages/core/helper-plugin/lib/src/components/RelationInput/RelationInput.stories.mdx
@@ -21,52 +21,72 @@ WIP
{
const { formatMessage } = useIntl();
const Component = components.Option;
- const hasDraftAndPublish = has(get(props, 'data.value'), 'publishedAt');
+ const { publicationState, mainField } = props.data;
- if (hasDraftAndPublish) {
- const isDraft = isEmpty(get(props, 'data.value.publishedAt'));
+ if (publicationState) {
+ const isDraft = publicationState === 'draft';
// To fix: use getTrad utils from CM once component is migrated into CM components
const draftMessage = {
id: 'content-manager.components.Select.draft-info-title',
@@ -42,29 +41,20 @@ export const Option = (props) => {
- {props.label || '-'}
+ {mainField ?? '-'}
);
}
- return {props.label || '-'};
-};
-
-Option.defaultProps = {
- label: '',
+ return {mainField ?? '-'};
};
Option.propTypes = {
- label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
isFocused: PropTypes.bool.isRequired,
- selectProps: PropTypes.shape({
- hasDraftAndPublish: PropTypes.bool,
- mainField: PropTypes.shape({
- name: PropTypes.string.isRequired,
- schema: PropTypes.shape({
- type: PropTypes.string.isRequired,
- }).isRequired,
- }).isRequired,
+ data: PropTypes.shape({
+ isDraft: PropTypes.bool,
+ mainField: PropTypes.string,
+ publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
}).isRequired,
};
diff --git a/packages/core/helper-plugin/lib/src/components/RelationInput/components/tests/Option.test.js b/packages/core/helper-plugin/lib/src/components/RelationInput/components/tests/Option.test.js
index 6510b3d1b0..301c9437cd 100644
--- a/packages/core/helper-plugin/lib/src/components/RelationInput/components/tests/Option.test.js
+++ b/packages/core/helper-plugin/lib/src/components/RelationInput/components/tests/Option.test.js
@@ -17,7 +17,7 @@ const setup = (props) =>
describe('RelationInput || Option', () => {
it('should render custom Option with published state title', () => {
- setup({ options: [{ value: { id: 1, publishedAt: 'something' }, label: 'relation 1' }] });
+ setup({ options: [{ mainField: 'relation 1', publicationState: 'published' }] });
act(() => {
fireEvent.mouseDown(screen.getByRole('button'));
@@ -27,8 +27,8 @@ describe('RelationInput || Option', () => {
expect(screen.getByTitle('State: Published')).toBeInTheDocument();
});
- it('should render custom Option with published state title', () => {
- setup({ options: [{ value: { id: 1, publishedAt: null }, label: 'relation 1' }] });
+ it('should render custom Option with draft state title', () => {
+ setup({ options: [{ mainField: 'relation 1', publicationState: 'draft' }] });
act(() => {
fireEvent.mouseDown(screen.getByRole('button'));