mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 17:00:55 +00:00
Merge pull request #17340 from hasebsiddiqui/bug/fix-error-on-adding-relations
This commit is contained in:
commit
32d68f1f56
@ -20,6 +20,7 @@ const StyledBullet = styled.div`
|
|||||||
|
|
||||||
export const Option = ({ publicationState, mainField, id }) => {
|
export const Option = ({ publicationState, mainField, id }) => {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const stringifiedDisplayValue = (mainField ?? id).toString();
|
||||||
|
|
||||||
if (publicationState) {
|
if (publicationState) {
|
||||||
const isDraft = publicationState === 'draft';
|
const isDraft = publicationState === 'draft';
|
||||||
@ -34,18 +35,18 @@ export const Option = ({ publicationState, mainField, id }) => {
|
|||||||
const title = isDraft ? formatMessage(draftMessage) : formatMessage(publishedMessage);
|
const title = isDraft ? formatMessage(draftMessage) : formatMessage(publishedMessage);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ComboboxOption value={id} textValue={mainField ?? id}>
|
<ComboboxOption value={id} textValue={stringifiedDisplayValue}>
|
||||||
<Flex>
|
<Flex>
|
||||||
<StyledBullet title={title} isDraft={isDraft} />
|
<StyledBullet title={title} isDraft={isDraft} />
|
||||||
<Typography ellipsis>{mainField ?? id}</Typography>
|
<Typography ellipsis>{stringifiedDisplayValue}</Typography>
|
||||||
</Flex>
|
</Flex>
|
||||||
</ComboboxOption>
|
</ComboboxOption>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ComboboxOption value={id} textValue={mainField ?? id}>
|
<ComboboxOption value={id} textValue={stringifiedDisplayValue}>
|
||||||
{mainField ?? id}
|
{stringifiedDisplayValue}
|
||||||
</ComboboxOption>
|
</ComboboxOption>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@ -57,6 +58,6 @@ Option.defaultProps = {
|
|||||||
|
|
||||||
Option.propTypes = {
|
Option.propTypes = {
|
||||||
id: PropTypes.number.isRequired,
|
id: PropTypes.number.isRequired,
|
||||||
mainField: PropTypes.string,
|
mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||||
publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||||
};
|
};
|
||||||
|
@ -44,4 +44,14 @@ describe('Content-Manager || RelationInput || Option', () => {
|
|||||||
expect(getByText('relation 1')).toBeInTheDocument();
|
expect(getByText('relation 1')).toBeInTheDocument();
|
||||||
expect(getByTitle('State: Draft')).toBeInTheDocument();
|
expect(getByTitle('State: Draft')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should render custom Option with mainField prop as number type', async () => {
|
||||||
|
const { user, getByRole } = setup({
|
||||||
|
options: [{ id: 1, mainField: 1, publicationState: 'published' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
await user.click(getByRole('combobox'));
|
||||||
|
|
||||||
|
expect(getByRole('option', { publicationState: 'State: Published' })).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user