Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 26x 26x | import PropTypes from 'prop-types';
import { FormattedNumber } from 'react-intl';
import {
Card,
Col,
FormattedUTCDate,
InfoPopover,
KeyValue,
List,
NoValue,
Row,
} from '@folio/stripes/components';
import * as CUSTPROP_TYPES from '../../constants/customProperties';
import { useKintIntl } from '../../hooks';
const CustomPropertyCard = ({
ctx,
customProperty,
customPropertyDefinition = {},
index,
intlKey: passedIntlKey,
intlNS: passedIntlNS,
labelOverrides = {}
}) => {
const kintIntl = useKintIntl(passedIntlKey, passedIntlNS);
// We only need to display primary and set properties
const toDisplay = !!(customPropertyDefinition.primary || customProperty);
if (!toDisplay) {
return null;
}
const internalFalse = customProperty?.internal === false ||
(customProperty?.internal === undefined && customPropertyDefinition.defaultInternal === false);
const renderValue = () => {
if (!customProperty) {
return (
kintIntl.formatKintMessage({
id: 'notSet',
overrideValue: labelOverrides.notSet
})
);
}
switch (customPropertyDefinition.type) {
case CUSTPROP_TYPES.MULTI_REFDATA_CLASS_NAME:
return (
<List
items={customProperty.value?.map((item) => item?.label ?? item?.value)}
listStyle="bullets"
/>
);
case CUSTPROP_TYPES.REFDATA_CLASS_NAME:
return customProperty.value?.label ?? customProperty.value?.value;
case CUSTPROP_TYPES.DECIMAL_CLASS_NAME:
case CUSTPROP_TYPES.INTEGER_CLASS_NAME:
return <FormattedNumber value={customProperty.value} />;
case CUSTPROP_TYPES.DATE_CLASS_NAME:
return <FormattedUTCDate value={customProperty.value} />;
case CUSTPROP_TYPES.TEXT_CLASS_NAME:
default:
return customProperty.value;
}
};
return (
<Card
key={`customPropertyCard-${ctx}[${index}]`}
headerStart={
<>
<strong>
{customPropertyDefinition.retired ?
(kintIntl.formatKintMessage({
id: 'customProperty.retiredName',
overrideValue: labelOverrides.retiredName
}, { name: customPropertyDefinition.label })) :
customPropertyDefinition.label
}
</strong>
{customPropertyDefinition.description ? (
<InfoPopover
content={customPropertyDefinition.description}
/>
) : null}
</>
}
id={`customproperty-card-${index}`}
>
<Row>
<Col xs={6}>
<KeyValue
label={
kintIntl.formatKintMessage({
id: 'valueOrValues',
overrideValue: labelOverrides.valueOrValues
})
}
>
{renderValue()}
</KeyValue>
</Col>
{customProperty?.note ? (
<Col xs={6}>
<KeyValue
label={
kintIntl.formatKintMessage({
id: 'customProperties.internalNote',
overrideValue: labelOverrides.internalNote
})
}
>
<span
style={{ whiteSpace: 'pre-wrap' }}
>
{customProperty.note}
</span>
</KeyValue>
</Col>
) : null}
</Row>
<Row>
<Col xs={6}>
<KeyValue
label={
kintIntl.formatKintMessage({
id: 'customProperties.visibility',
overrideValue: labelOverrides.visibility
})
}
>
{kintIntl.formatKintMessage({
id: internalFalse ? 'customProperties.internalFalse' : 'customProperties.internalTrue',
overrideValue: internalFalse ? labelOverrides.internalFalse : labelOverrides.internalTrue,
})}
</KeyValue>
</Col>
{internalFalse &&
<Col xs={6}>
<KeyValue
label={
kintIntl.formatKintMessage({
id: 'customProperties.publicNote',
overrideValue: labelOverrides.publicNote
})
}
>
{customProperty?.publicNote ? (
<span
style={{ whiteSpace: 'pre-wrap' }}
>
{customProperty.publicNote}
</span>
) : (
<NoValue />
)}
</KeyValue>
</Col>
}
</Row>
</Card>
);
};
CustomPropertyCard.propTypes = {
ctx: PropTypes.string,
customProperty: PropTypes.object,
customPropertyDefinition: PropTypes.object,
index: PropTypes.number,
intlKey: PropTypes.string,
intlNS: PropTypes.string,
labelOverrides: PropTypes.object,
};
export default CustomPropertyCard;
|