2020-09-01 15:17:50 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import styled from 'styled-components';
|
|
|
|
|
import { components } from 'react-select';
|
2020-09-02 15:52:20 +02:00
|
|
|
import { useIntl } from 'react-intl';
|
2020-09-01 15:17:50 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2020-09-01 15:38:51 +02:00
|
|
|
import { get, has, isEmpty } from 'lodash';
|
2020-09-01 15:17:50 +02:00
|
|
|
import { Flex, Text } from '@buffetjs/core';
|
2020-09-02 15:52:20 +02:00
|
|
|
import { getTrad } from '../../utils';
|
2020-09-01 15:17:50 +02:00
|
|
|
import RelationDPState from '../RelationDPState';
|
|
|
|
|
|
|
|
|
|
const TextGrow = styled(Text)`
|
|
|
|
|
flex-grow: 2;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const Option = props => {
|
2020-09-02 15:52:20 +02:00
|
|
|
const { formatMessage } = useIntl();
|
2020-09-01 15:17:50 +02:00
|
|
|
const Component = components.Option;
|
2020-09-01 15:38:51 +02:00
|
|
|
const hasDraftAndPublish = has(get(props, 'data.value'), 'published_at');
|
2020-09-01 15:17:50 +02:00
|
|
|
const isDraft = isEmpty(get(props, 'data.value.published_at'));
|
2020-09-02 15:52:20 +02:00
|
|
|
const titleLabelID = isDraft
|
|
|
|
|
? 'components.Select.draft-info-title'
|
|
|
|
|
: 'components.Select.publish-info-title';
|
|
|
|
|
const title = formatMessage({ id: getTrad(titleLabelID) });
|
|
|
|
|
const fontWeight = props.isFocused ? 'bold' : 'regular';
|
2020-09-01 15:17:50 +02:00
|
|
|
|
|
|
|
|
if (hasDraftAndPublish) {
|
|
|
|
|
return (
|
|
|
|
|
<Component {...props}>
|
|
|
|
|
<Flex>
|
|
|
|
|
<RelationDPState
|
|
|
|
|
marginLeft="0"
|
|
|
|
|
marginTop="1px"
|
|
|
|
|
marginRight="10px"
|
|
|
|
|
isDraft={isDraft}
|
|
|
|
|
marginBottom="0"
|
2020-09-02 15:52:20 +02:00
|
|
|
title={title}
|
2020-09-01 15:17:50 +02:00
|
|
|
/>
|
|
|
|
|
|
2020-09-02 15:52:20 +02:00
|
|
|
<TextGrow ellipsis as="div" fontWeight={fontWeight}>
|
2020-09-01 15:17:50 +02:00
|
|
|
{props.label}
|
|
|
|
|
</TextGrow>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Component>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Component {...props}>
|
|
|
|
|
<Text ellipsis>{props.label}</Text>
|
|
|
|
|
</Component>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Option.propTypes = {
|
2020-09-01 15:38:51 +02:00
|
|
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
|
2020-09-02 15:52:20 +02:00
|
|
|
isFocused: PropTypes.bool.isRequired,
|
2020-09-01 15:17:50 +02:00
|
|
|
selectProps: PropTypes.shape({
|
|
|
|
|
hasDraftAndPublish: PropTypes.bool,
|
|
|
|
|
}).isRequired,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Option;
|