mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +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 }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const stringifiedDisplayValue = (mainField ?? id).toString();
|
||||
|
||||
if (publicationState) {
|
||||
const isDraft = publicationState === 'draft';
|
||||
@ -34,18 +35,18 @@ export const Option = ({ publicationState, mainField, id }) => {
|
||||
const title = isDraft ? formatMessage(draftMessage) : formatMessage(publishedMessage);
|
||||
|
||||
return (
|
||||
<ComboboxOption value={id} textValue={mainField ?? id}>
|
||||
<ComboboxOption value={id} textValue={stringifiedDisplayValue}>
|
||||
<Flex>
|
||||
<StyledBullet title={title} isDraft={isDraft} />
|
||||
<Typography ellipsis>{mainField ?? id}</Typography>
|
||||
<Typography ellipsis>{stringifiedDisplayValue}</Typography>
|
||||
</Flex>
|
||||
</ComboboxOption>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ComboboxOption value={id} textValue={mainField ?? id}>
|
||||
{mainField ?? id}
|
||||
<ComboboxOption value={id} textValue={stringifiedDisplayValue}>
|
||||
{stringifiedDisplayValue}
|
||||
</ComboboxOption>
|
||||
);
|
||||
};
|
||||
@ -57,6 +58,6 @@ Option.defaultProps = {
|
||||
|
||||
Option.propTypes = {
|
||||
id: PropTypes.number.isRequired,
|
||||
mainField: PropTypes.string,
|
||||
mainField: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
||||
publicationState: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
|
||||
};
|
||||
|
@ -44,4 +44,14 @@ describe('Content-Manager || RelationInput || Option', () => {
|
||||
expect(getByText('relation 1')).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