Skip to content

Commit f006b53

Browse files
committed
Access state for LabelValueMetadata from its own container
1 parent 60ab8a0 commit f006b53

13 files changed

Lines changed: 53 additions & 47 deletions

__tests__/src/components/LabelValueMetadata.test.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
import { render, screen } from '@tests/utils/test-utils';
22
import { LabelValueMetadata } from '../../../src/components/LabelValueMetadata';
33

4+
/** */
5+
function createWrapper(props) {
6+
return render(
7+
<LabelValueMetadata
8+
{...props}
9+
/>,
10+
);
11+
}
12+
413
/* eslint-disable testing-library/no-node-access */
514
describe('LabelValueMetadata', () => {
615
let wrapper;
7-
let labelValuePair;
16+
let labelValuePairs;
817

918
describe('when the labelValuePair has content', () => {
1019
beforeEach(() => {
11-
labelValuePair = [
20+
labelValuePairs = [
1221
{
1322
label: 'Label 1',
1423
values: ['Value 1'],
@@ -18,9 +27,8 @@ describe('LabelValueMetadata', () => {
1827
values: ['Value 2', 'Value 3'],
1928
},
2029
];
21-
wrapper = render(
22-
<LabelValueMetadata labelValuePairs={labelValuePair} />,
23-
);
30+
31+
wrapper = createWrapper({ labelValuePairs });
2432
});
2533

2634
it('renders a dt/dd for each label/value pair', () => {
@@ -38,32 +46,28 @@ describe('LabelValueMetadata', () => {
3846
expect(screen.getByText('Value 1')).toBeInTheDocument();
3947
expect(screen.getByText('Value 2, Value 3')).toBeInTheDocument();
4048
});
41-
});
4249

43-
describe('when the labelValuePair has no content', () => {
44-
beforeEach(() => {
45-
labelValuePair = [];
46-
wrapper = render(
47-
<LabelValueMetadata labelValuePairs={labelValuePair} />,
48-
);
50+
it('uses the default labelValueJoiner from config', () => {
51+
expect(screen.getByText('Value 2, Value 3')).toBeInTheDocument();
4952
});
53+
});
5054

55+
describe('when the labelValuePair has no content', () => {
5156
it('renders an empty fragment instead of an empty dl', () => {
57+
wrapper = createWrapper({ labelValuePairs: [] });
5258
expect(wrapper.container).toBeEmptyDOMElement();
5359
});
5460
});
5561

5662
describe('when the labelValuePair has content and labelValueJoiner is set to a custom variable', () => {
5763
beforeEach(() => {
58-
labelValuePair = [
64+
labelValuePairs = [
5965
{
6066
label: 'Label 1',
6167
values: ['Value 1', 'Value 2'],
6268
},
6369
];
64-
wrapper = render(
65-
<LabelValueMetadata labelValuePairs={labelValuePair} labelValueJoiner="*" />,
66-
);
70+
wrapper = createWrapper({ labelValueJoiner: '*', labelValuePairs });
6771
});
6872

6973
it('renders a dt/dd for each label/value pair', () => {
@@ -83,7 +87,7 @@ describe('LabelValueMetadata', () => {
8387

8488
describe('when the labelValuePair has a default label', () => {
8589
beforeEach(() => {
86-
labelValuePair = [
90+
labelValuePairs = [
8791
{
8892
values: ['Value 1'],
8993
},
@@ -92,9 +96,7 @@ describe('LabelValueMetadata', () => {
9296
values: ['Value 2'],
9397
},
9498
];
95-
wrapper = render(
96-
<LabelValueMetadata labelValuePairs={labelValuePair} defaultLabel="Default label" />,
97-
);
99+
createWrapper({ defaultLabel: 'Default label', labelValuePairs });
98100
});
99101

100102
it('renders correct labels in dt', () => {

src/components/AttributionPanel.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useTranslation } from 'react-i18next';
77
import { Img } from 'react-image';
88
import CompanionWindow from '../containers/CompanionWindow';
99
import { CompanionWindowSection } from './CompanionWindowSection';
10-
import { LabelValueMetadata } from './LabelValueMetadata';
10+
import LabelValueMetadata from '../containers/LabelValueMetadata';
1111
import ns from '../config/css-ns';
1212
import { PluginHook } from './PluginHook';
1313

@@ -28,7 +28,6 @@ export function AttributionPanel({
2828
rights = null,
2929
windowId,
3030
id,
31-
labelValueJoiner,
3231
}) {
3332
const { t } = useTranslation();
3433

@@ -43,7 +42,7 @@ export function AttributionPanel({
4342
>
4443
<CompanionWindowSection>
4544
{ requiredStatement && (
46-
<LabelValueMetadata labelValuePairs={requiredStatement} labelValueJoiner={labelValueJoiner} defaultLabel={t('attribution')} />
45+
<LabelValueMetadata labelValuePairs={requiredStatement} defaultLabel={t('attribution')} />
4746
)}
4847
{
4948
rights && rights.length > 0 && (
@@ -88,5 +87,4 @@ AttributionPanel.propTypes = {
8887
})),
8988
rights: PropTypes.arrayOf(PropTypes.string),
9089
windowId: PropTypes.string.isRequired,
91-
labelValueJoiner: PropTypes.string,
9290
};

src/components/CanvasInfo.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Typography from '@mui/material/Typography';
44
import { useTranslation } from 'react-i18next';
55
import CollapsibleSection from '../containers/CollapsibleSection';
66
import SanitizedHtml from '../containers/SanitizedHtml';
7-
import { LabelValueMetadata } from './LabelValueMetadata';
7+
import LabelValueMetadata from '../containers/LabelValueMetadata';
88
import { PluginHook } from './PluginHook';
99

1010
/**
@@ -16,7 +16,6 @@ export function CanvasInfo({
1616
canvasMetadata = [],
1717
index = 1,
1818
totalSize = 1,
19-
labelValueJoiner,
2019
}) {
2120
const { t } = useTranslation();
2221
const id = useId();
@@ -48,7 +47,7 @@ export function CanvasInfo({
4847
)}
4948

5049
{canvasMetadata && canvasMetadata.length > 0 && (
51-
<LabelValueMetadata labelValuePairs={canvasMetadata} labelValueJoiner={labelValueJoiner} />
50+
<LabelValueMetadata labelValuePairs={canvasMetadata} />
5251
)}
5352
<PluginHook targetName="CanvasInfo" {...pluginProps} />
5453
</CollapsibleSection>
@@ -61,5 +60,4 @@ CanvasInfo.propTypes = {
6160
canvasMetadata: PropTypes.array, // eslint-disable-line react/forbid-prop-types
6261
index: PropTypes.number,
6362
totalSize: PropTypes.number,
64-
labelValueJoiner: PropTypes.string,
6563
};

src/components/CollectionDialog.jsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Skeleton from '@mui/material/Skeleton';
1616
import { styled } from '@mui/material/styles';
1717
import { useTranslation } from 'react-i18next';
1818
import asArray from '../lib/asArray';
19-
import { LabelValueMetadata } from './LabelValueMetadata';
19+
import LabelValueMetadata from '../containers/LabelValueMetadata';
2020
import CollapsibleSection from '../containers/CollapsibleSection';
2121
import ScrollIndicatedDialogContent from '../containers/ScrollIndicatedDialogContent';
2222
import ManifestInfo from '../containers/ManifestInfo';
@@ -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, labelValueJoiner,
70+
isMultipart = false, manifest, manifestId, ready = false,
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} labelValueJoiner={labelValueJoiner} defaultLabel={t('attribution')} />
164+
<LabelValueMetadata labelValuePairs={requiredStatement} defaultLabel={t('attribution')} />
165165
)}
166166
{
167167
rights && rights.length > 0 && (
@@ -241,5 +241,4 @@ CollectionDialog.propTypes = {
241241
showCollectionDialog: PropTypes.func.isRequired,
242242
updateWindow: PropTypes.func.isRequired,
243243
windowId: PropTypes.string,
244-
labelValueJoiner: PropTypes.string,
245244
};

src/components/LabelValueMetadata.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ 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, labelValueJoiner = ', '}) {
10+
export function LabelValueMetadata({ defaultLabel = undefined, labelValuePairs, labelValueJoiner=', ' }) {
11+
1112
if (labelValuePairs.length === 0) {
1213
return null;
1314
}
@@ -33,6 +34,5 @@ LabelValueMetadata.propTypes = {
3334
labelValuePairs: PropTypes.arrayOf(PropTypes.shape({
3435
label: PropTypes.string,
3536
values: PropTypes.arrayOf(PropTypes.string),
36-
labelValueJoiner: PropTypes.string
3737
})).isRequired,
3838
};

src/components/ManifestInfo.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import Typography from '@mui/material/Typography';
44
import { useTranslation } from 'react-i18next';
55
import CollapsibleSection from '../containers/CollapsibleSection';
66
import SanitizedHtml from '../containers/SanitizedHtml';
7-
import { LabelValueMetadata } from './LabelValueMetadata';
7+
import LabelValueMetadata from '../containers/LabelValueMetadata';
88
import { PluginHook } from './PluginHook';
99

1010
/**
1111
* ManifestInfo
1212
*/
1313
export function ManifestInfo({
1414
manifestDescription = null, manifestLabel = null, manifestMetadata = [], manifestSummary = null,
15-
labelValueJoiner,
1615
...rest
1716
}) {
1817
const { t } = useTranslation();
@@ -50,7 +49,7 @@ export function ManifestInfo({
5049
)}
5150

5251
{manifestMetadata.length > 0 && (
53-
<LabelValueMetadata labelValuePairs={manifestMetadata} labelValueJoiner={labelValueJoiner} />
52+
<LabelValueMetadata labelValuePairs={manifestMetadata} />
5453
)}
5554

5655
<PluginHook targetName="ManifestInfo" {...pluginProps} />
@@ -63,5 +62,4 @@ ManifestInfo.propTypes = {
6362
manifestLabel: PropTypes.string,
6463
manifestMetadata: PropTypes.array, // eslint-disable-line react/forbid-prop-types
6564
manifestSummary: PropTypes.string,
66-
labelValueJoiner: PropTypes.string
6765
};

src/config/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,5 +582,5 @@ export default {
582582
{ profile: 'http://iiif.io/api/auth/0/login' }
583583
]
584584
},
585-
labelValueJoiner: ", "
585+
labelValueJoiner: ', '
586586
};

src/containers/AttributionPanel.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
getManifestLogo,
55
getRequiredStatement,
66
getRights,
7-
getConfig,
87
} from '../state/selectors';
98
import { withPlugins } from '../extend/withPlugins';
109
import { AttributionPanel } from '../components/AttributionPanel';
@@ -15,7 +14,6 @@ import { AttributionPanel } from '../components/AttributionPanel';
1514
* @private
1615
*/
1716
const mapStateToProps = (state, { id, windowId }) => ({
18-
labelValueJoiner: getConfig(state).labelValueJoiner,
1917
manifestLogo: getManifestLogo(state, { windowId }),
2018
requiredStatement: getRequiredStatement(state, { windowId }),
2119
rights: getRights(state, { windowId }),

src/containers/CanvasInfo.js

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

@@ -21,7 +20,6 @@ const mapStateToProps = (state, { canvasId, companionWindowId, windowId }) => ({
2120
canvasMetadata: getDestructuredMetadata(
2221
getCanvas(state, { canvasId, companionWindowId, windowId }),
2322
),
24-
labelValueJoiner: getConfig(state).labelValueJoiner,
2523
});
2624

2725
const enhance = compose(

src/containers/CollectionDialog.js

Lines changed: 1 addition & 2 deletions
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, getConfig,
6+
getManifest, getManifestoInstance, getSequenceBehaviors, getWindow,
77
} from '../state/selectors';
88
import { CollectionDialog } from '../components/CollectionDialog';
99

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

0 commit comments

Comments
 (0)