Extract DisplayedType component

This commit is contained in:
Rémi de Juvigny 2022-07-20 18:26:29 +02:00
parent 2e62447b55
commit b6c91f0cfe
2 changed files with 55 additions and 13 deletions

View File

@ -0,0 +1,48 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';
import { Typography } from '@strapi/design-system/Typography';
import getTrad from '../../utils/getTrad';
const DisplayedType = ({ readableType, customField, repeatable }) => {
const { formatMessage } = useIntl();
if (customField) {
return (
<Typography>
{formatMessage({
id: getTrad('attribute.customField'),
defaultMessage: 'Custom field',
})}
</Typography>
);
}
return (
<Typography>
{formatMessage({
id: getTrad(`attribute.${readableType}`),
defaultMessage: readableType,
})}
&nbsp;
{repeatable &&
formatMessage({
id: getTrad('component.repeatable'),
defaultMessage: '(repeatable)',
})}
</Typography>
);
};
DisplayedType.defaultProps = {
customField: null,
repeatable: false,
};
DisplayedType.propTypes = {
readableType: PropTypes.string.isRequired,
customField: PropTypes.bool,
repeatable: PropTypes.bool,
};
export default DisplayedType;

View File

@ -17,6 +17,7 @@ import Curve from '../../icons/Curve';
import UpperFist from '../UpperFirst'; import UpperFist from '../UpperFirst';
import BoxWrapper from './BoxWrapper'; import BoxWrapper from './BoxWrapper';
import AttributeIcon from '../AttributeIcon'; import AttributeIcon from '../AttributeIcon';
import DisplayedType from './DisplayedType';
function ListRow({ function ListRow({
configurable, configurable,
@ -39,7 +40,7 @@ function ListRow({
const isMorph = type === 'relation' && relation.includes('morph'); const isMorph = type === 'relation' && relation.includes('morph');
const ico = ['integer', 'biginteger', 'float', 'decimal'].includes(type) ? 'number' : type; const ico = ['integer', 'biginteger', 'float', 'decimal'].includes(type) ? 'number' : type;
let readableType = customField || type; let readableType = type;
if (['integer', 'biginteger', 'float', 'decimal'].includes(type)) { if (['integer', 'biginteger', 'float', 'decimal'].includes(type)) {
readableType = 'number'; readableType = 'number';
@ -119,18 +120,11 @@ function ListRow({
</span> </span>
</Typography> </Typography>
) : ( ) : (
<Typography> <DisplayedType
{formatMessage({ customField={customField}
id: getTrad(`attribute.${readableType}`), readableType={readableType}
defaultMessage: customField ? 'Custom field' : type, repeatable={repeatable}
})} />
&nbsp;
{repeatable &&
formatMessage({
id: getTrad('component.repeatable'),
defaultMessage: '(repeatable)',
})}
</Typography>
)} )}
</td> </td>
<td> <td>