Skip to content

Commit 60ab8a0

Browse files
dnoneillmarlo-longley
authored andcommitted
allow label-value-metadata joiner to be set in the config
1 parent 1c164d5 commit 60ab8a0

11 files changed

Lines changed: 55 additions & 11 deletions

File tree

__tests__/src/components/LabelValueMetadata.test.js

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe('LabelValueMetadata', () => {
1515
},
1616
{
1717
label: 'Label 2',
18-
values: ['Value 2'],
18+
values: ['Value 2', 'Value 3'],
1919
},
2020
];
2121
wrapper = render(
@@ -36,7 +36,7 @@ describe('LabelValueMetadata', () => {
3636

3737
it('renders SanitizedHtml component in dd for each value', () => {
3838
expect(screen.getByText('Value 1')).toBeInTheDocument();
39-
expect(screen.getByText('Value 2')).toBeInTheDocument();
39+
expect(screen.getByText('Value 2, Value 3')).toBeInTheDocument();
4040
});
4141
});
4242

@@ -53,6 +53,34 @@ describe('LabelValueMetadata', () => {
5353
});
5454
});
5555

56+
describe('when the labelValuePair has content and labelValueJoiner is set to a custom variable', () => {
57+
beforeEach(() => {
58+
labelValuePair = [
59+
{
60+
label: 'Label 1',
61+
values: ['Value 1', 'Value 2'],
62+
},
63+
];
64+
wrapper = render(
65+
<LabelValueMetadata labelValuePairs={labelValuePair} labelValueJoiner="*" />,
66+
);
67+
});
68+
69+
it('renders a dt/dd for each label/value pair', () => {
70+
expect(wrapper.container.querySelector('dl')).toBeInTheDocument();
71+
expect(wrapper.container.querySelectorAll('dt').length).toEqual(1);
72+
expect(wrapper.container.querySelectorAll('dd').length).toEqual(1);
73+
});
74+
75+
it('renders correct label in dt', () => {
76+
expect(screen.getByText('Label 1')).toBeInTheDocument();
77+
});
78+
79+
it('renders SanitizedHtml component in dd for each value with correct joiner', () => {
80+
expect(screen.getByText('Value 1*Value 2')).toBeInTheDocument();
81+
});
82+
});
83+
5684
describe('when the labelValuePair has a default label', () => {
5785
beforeEach(() => {
5886
labelValuePair = [

src/components/AttributionPanel.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function AttributionPanel({
2828
rights = null,
2929
windowId,
3030
id,
31+
labelValueJoiner,
3132
}) {
3233
const { t } = useTranslation();
3334

@@ -42,7 +43,7 @@ export function AttributionPanel({
4243
>
4344
<CompanionWindowSection>
4445
{ requiredStatement && (
45-
<LabelValueMetadata labelValuePairs={requiredStatement} defaultLabel={t('attribution')} />
46+
<LabelValueMetadata labelValuePairs={requiredStatement} labelValueJoiner={labelValueJoiner} defaultLabel={t('attribution')} />
4647
)}
4748
{
4849
rights && rights.length > 0 && (
@@ -87,4 +88,5 @@ AttributionPanel.propTypes = {
8788
})),
8889
rights: PropTypes.arrayOf(PropTypes.string),
8990
windowId: PropTypes.string.isRequired,
91+
labelValueJoiner: PropTypes.string,
9092
};

src/components/CanvasInfo.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function CanvasInfo({
1616
canvasMetadata = [],
1717
index = 1,
1818
totalSize = 1,
19+
labelValueJoiner,
1920
}) {
2021
const { t } = useTranslation();
2122
const id = useId();
@@ -47,7 +48,7 @@ export function CanvasInfo({
4748
)}
4849

4950
{canvasMetadata && canvasMetadata.length > 0 && (
50-
<LabelValueMetadata labelValuePairs={canvasMetadata} />
51+
<LabelValueMetadata labelValuePairs={canvasMetadata} labelValueJoiner={labelValueJoiner} />
5152
)}
5253
<PluginHook targetName="CanvasInfo" {...pluginProps} />
5354
</CollapsibleSection>
@@ -60,4 +61,5 @@ CanvasInfo.propTypes = {
6061
canvasMetadata: PropTypes.array, // eslint-disable-line react/forbid-prop-types
6162
index: PropTypes.number,
6263
totalSize: PropTypes.number,
64+
labelValueJoiner: PropTypes.string,
6365
};

src/components/CollectionDialog.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Placeholder.propTypes = {
6767
*/
6868
export function CollectionDialog({
6969
addWindow, collection = null, dialogCollectionPath = [], error = null, hideCollectionDialog,
70-
isMultipart = false, manifest, manifestId, ready = false,
70+
isMultipart = false, manifest, manifestId, ready = false, labelValueJoiner,
7171
setWorkspaceAddVisibility, showCollectionDialog, updateWindow, windowId = null,
7272
}) {
7373
const container = useContext(WorkspaceContext);
@@ -161,7 +161,7 @@ export function CollectionDialog({
161161
label={t('attributionTitle')}
162162
>
163163
{ requiredStatement && (
164-
<LabelValueMetadata labelValuePairs={requiredStatement} defaultLabel={t('attribution')} />
164+
<LabelValueMetadata labelValuePairs={requiredStatement} labelValueJoiner={labelValueJoiner} defaultLabel={t('attribution')} />
165165
)}
166166
{
167167
rights && rights.length > 0 && (
@@ -241,4 +241,5 @@ CollectionDialog.propTypes = {
241241
showCollectionDialog: PropTypes.func.isRequired,
242242
updateWindow: PropTypes.func.isRequired,
243243
windowId: PropTypes.string,
244+
labelValueJoiner: PropTypes.string,
244245
};

src/components/LabelValueMetadata.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ns from '../config/css-ns';
77
* Renders label/value pair metadata in a dl
88
* @prop {object} labelValuePair
99
*/
10-
export function LabelValueMetadata({ defaultLabel = undefined, labelValuePairs }) {
10+
export function LabelValueMetadata({ defaultLabel = undefined, labelValuePairs, labelValueJoiner = ', '}) {
1111
if (labelValuePairs.length === 0) {
1212
return null;
1313
}
@@ -21,7 +21,7 @@ export function LabelValueMetadata({ defaultLabel = undefined, labelValuePairs }
2121
{labelValuePairs.reduce((acc, labelValuePair, i) => acc.concat([
2222
<Typography component="dt" key={`label-${i}`} variant="subtitle2">{labelValuePair.label || defaultLabel}</Typography>,
2323
<Typography style={{ marginBottom: '.5em', marginLeft: '0px' }} component="dd" key={`value-${i}`} variant="body1">
24-
<SanitizedHtml htmlString={labelValuePair.values.join(', ')} ruleSet="iiif" />
24+
<SanitizedHtml htmlString={labelValuePair.values.join(labelValueJoiner)} ruleSet="iiif" />
2525
</Typography>,
2626
]), [])}
2727
</dl>
@@ -33,5 +33,6 @@ LabelValueMetadata.propTypes = {
3333
labelValuePairs: PropTypes.arrayOf(PropTypes.shape({
3434
label: PropTypes.string,
3535
values: PropTypes.arrayOf(PropTypes.string),
36+
labelValueJoiner: PropTypes.string
3637
})).isRequired,
3738
};

src/components/ManifestInfo.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { PluginHook } from './PluginHook';
1212
*/
1313
export function ManifestInfo({
1414
manifestDescription = null, manifestLabel = null, manifestMetadata = [], manifestSummary = null,
15+
labelValueJoiner,
1516
...rest
1617
}) {
1718
const { t } = useTranslation();
@@ -49,7 +50,7 @@ export function ManifestInfo({
4950
)}
5051

5152
{manifestMetadata.length > 0 && (
52-
<LabelValueMetadata labelValuePairs={manifestMetadata} />
53+
<LabelValueMetadata labelValuePairs={manifestMetadata} labelValueJoiner={labelValueJoiner} />
5354
)}
5455

5556
<PluginHook targetName="ManifestInfo" {...pluginProps} />
@@ -62,4 +63,5 @@ ManifestInfo.propTypes = {
6263
manifestLabel: PropTypes.string,
6364
manifestMetadata: PropTypes.array, // eslint-disable-line react/forbid-prop-types
6465
manifestSummary: PropTypes.string,
66+
labelValueJoiner: PropTypes.string
6567
};

src/config/settings.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,5 +581,6 @@ export default {
581581
{ profile: 'http://iiif.io/api/auth/0/clickthrough' },
582582
{ profile: 'http://iiif.io/api/auth/0/login' }
583583
]
584-
}
584+
},
585+
labelValueJoiner: ", "
585586
};

src/containers/AttributionPanel.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getManifestLogo,
55
getRequiredStatement,
66
getRights,
7+
getConfig,
78
} from '../state/selectors';
89
import { withPlugins } from '../extend/withPlugins';
910
import { AttributionPanel } from '../components/AttributionPanel';
@@ -14,6 +15,7 @@ import { AttributionPanel } from '../components/AttributionPanel';
1415
* @private
1516
*/
1617
const mapStateToProps = (state, { id, windowId }) => ({
18+
labelValueJoiner: getConfig(state).labelValueJoiner,
1719
manifestLogo: getManifestLogo(state, { windowId }),
1820
requiredStatement: getRequiredStatement(state, { windowId }),
1921
rights: getRights(state, { windowId }),

src/containers/CanvasInfo.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
getCanvas,
77
getCanvasLabel,
88
getCanvasDescription,
9+
getConfig,
910
} from '../state/selectors';
1011
import { CanvasInfo } from '../components/CanvasInfo';
1112

@@ -20,6 +21,7 @@ const mapStateToProps = (state, { canvasId, companionWindowId, windowId }) => ({
2021
canvasMetadata: getDestructuredMetadata(
2122
getCanvas(state, { canvasId, companionWindowId, windowId }),
2223
),
24+
labelValueJoiner: getConfig(state).labelValueJoiner,
2325
});
2426

2527
const enhance = compose(

src/containers/CollectionDialog.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { connect } from 'react-redux';
33
import { withPlugins } from '../extend/withPlugins';
44
import * as actions from '../state/actions';
55
import {
6-
getManifest, getManifestoInstance, getSequenceBehaviors, getWindow,
6+
getManifest, getManifestoInstance, getSequenceBehaviors, getWindow, getConfig,
77
} from '../state/selectors';
88
import { CollectionDialog } from '../components/CollectionDialog';
99

@@ -37,6 +37,7 @@ const mapStateToProps = (state, { windowId }) => {
3737
dialogCollectionPath,
3838
error: manifest && manifest.error,
3939
isMultipart: getSequenceBehaviors(state, { manifestId }).includes('multi-part'),
40+
labelValueJoiner: getConfig(state).labelValueJoiner,
4041
manifest: manifest && getManifestoInstance(state, { manifestId }),
4142
manifestId,
4243
open: state.workspace.collectionDialogOn,

0 commit comments

Comments
 (0)