Skip to content

Commit a485231

Browse files
authored
Configure metadata field title capitalization (#2144)
1 parent 234fe80 commit a485231

File tree

9 files changed

+58
-18
lines changed

9 files changed

+58
-18
lines changed

geonode_mapstore_client/client/js/plugins/MetadataEditor/MetadataViewer.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ const MetadataViewer = ({
4040
match,
4141
preview,
4242
setPreview,
43-
labelId = 'gnviewer.viewMetadata'
43+
labelId = 'gnviewer.viewMetadata',
44+
capitalizeFieldTitle = true
4445
}) => {
4546
const { params } = match || {};
4647
const pk = params?.pk;
48+
const customProp = encodeURIComponent(JSON.stringify({capitalizeTitle: capitalizeFieldTitle}));
4749
return (
4850
<Portal>
4951
<ResizableModal
@@ -54,7 +56,7 @@ const MetadataViewer = ({
5456
modalClassName="gn-simple-dialog"
5557
onClose={() => setPreview(false)}
5658
>
57-
<iframe style={{ border: 'none', position: 'absolute', width: '100%', height: '100%' }} src={`/metadata/${pk}/embed`} />
59+
<iframe style={{ border: 'none', position: 'absolute', width: '100%', height: '100%' }} src={`/metadata/${pk}/embed?props=${customProp}`} />
5860
</ResizableModal>
5961
</Portal>
6062
);

geonode_mapstore_client/client/js/plugins/MetadataEditor/components/_fields/SchemaField.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ const SchemaField = (props) => {
5050
name,
5151
errorSchema,
5252
uiSchema,
53-
required
53+
required,
54+
formContext
5455
} = props;
5556
const uiOptions = uiSchema?.['ui:options'];
5657
const autocomplete = uiOptions?.['geonode-ui:autocomplete'];
@@ -102,7 +103,7 @@ const SchemaField = (props) => {
102103
const placeholder = autoCompletePlaceholder ?? ' ';
103104

104105
let autoCompleteProps = {
105-
className: `field${classNames ? ' ' + classNames : ''}`,
106+
className: `field${classNames ? ' ' + classNames : ''} ${formContext?.capitalizeTitle ? 'capitalize' : ''}`,
106107
clearable: !required,
107108
creatable,
108109
id: idSchema.$id,

geonode_mapstore_client/client/js/plugins/MetadataEditor/components/_templates/FieldTemplate.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from '@rjsf/utils';
1414

1515
function FieldTemplate(props) {
16-
const { id, label, children, errors, help, description, hidden, required, displayLabel, registry, uiSchema } = props;
16+
const { id, label, children, errors, help, description, hidden, required, displayLabel, registry, uiSchema, formContext } = props;
1717
const uiOptions = getUiOptions(uiSchema);
1818
const WrapIfAdditionalTemplate = getTemplate(
1919
'WrapIfAdditionalTemplate',
@@ -26,7 +26,7 @@ function FieldTemplate(props) {
2626
return (
2727
<WrapIfAdditionalTemplate {...props}>
2828
{displayLabel &&
29-
<label className="control-label" htmlFor={id}>
29+
<label className={`control-label${formContext?.capitalizeTitle ? ' capitalize' : ''}`} htmlFor={id}>
3030
{label}
3131
{required && <span className="required">{' '}*</span>}
3232
{description ? <>{' '}{description}</> : null}

geonode_mapstore_client/client/js/plugins/MetadataEditor/components/_templates/ObjectFieldTemplate.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ function MetadataGroupList({
3434
idSchema,
3535
title,
3636
group,
37-
expanded: expandedProp
37+
expanded: expandedProp,
38+
capitalizeTitle
3839
}) {
3940
const [_expanded, setExpanded] = useState(false);
4041
const groupError = group.some(property => property.error);
4142
const expanded = expandedProp === undefined ? _expanded : expandedProp;
4243
return (
4344
<li>
44-
<Button className={groupError ? 'gn-metadata-error' : ''} size="xs" onClick={() => setExpanded((prevExpanded) => !prevExpanded)}>
45+
<Button className={`${groupError ? 'gn-metadata-error' : ''}${capitalizeTitle ? ' capitalize' : ''}`} size="xs" onClick={() => setExpanded((prevExpanded) => !prevExpanded)}>
4546
<Glyphicon glyph={expanded ? "bottom" : "next"} />{' '}{title}{groupError ? <>{' '}<Glyphicon glyph="exclamation-sign" /></> : null}
4647
</Button>
4748
{expanded ? <ul>
@@ -51,7 +52,7 @@ function MetadataGroupList({
5152
<li key={property.name}>
5253
<Button
5354
size="xs"
54-
className={property.error ? 'gn-metadata-error' : ''}
55+
className={`${property.error ? 'gn-metadata-error' : ''}${capitalizeTitle ? ' capitalize' : ''}`}
5556
onClick={() => scrollIntoView(idSchema[property.name]?.$id)}>
5657
{property.title}
5758
{property.error ? <>{' '}<Glyphicon glyph="exclamation-sign" /></> : null}
@@ -73,7 +74,8 @@ function RootMetadata({
7374
formContext
7475
}, context) {
7576
const {
76-
title: metadataTitle
77+
title: metadataTitle,
78+
capitalizeTitle
7779
} = formContext;
7880
const [filterText, setFilterText] = useState('');
7981

@@ -118,6 +120,7 @@ function RootMetadata({
118120
title={groupKey}
119121
group={group}
120122
expanded={filterText ? true : undefined}
123+
capitalizeTitle={capitalizeTitle}
121124
/>
122125
);
123126
})}
@@ -166,7 +169,8 @@ function ObjectFieldTemplate(props) {
166169
required,
167170
schema,
168171
title,
169-
uiSchema
172+
uiSchema,
173+
formContext
170174
} = props;
171175
const options = getUiOptions(uiSchema);
172176
const TitleFieldTemplate = getTemplate('TitleFieldTemplate', registry, options);
@@ -188,6 +192,7 @@ function ObjectFieldTemplate(props) {
188192
schema={schema}
189193
uiSchema={uiSchema}
190194
registry={registry}
195+
formContext={formContext}
191196
description={<DescriptionFieldTemplate
192197
id={descriptionId(idSchema)}
193198
description={description}

geonode_mapstore_client/client/js/plugins/MetadataEditor/components/_templates/TitleFieldTemplate.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import React from 'react';
1010

1111
const TitleFieldTemplate = (props) => {
12-
const { id, required, title, description } = props;
12+
const { id, required, title, description, formContext } = props;
1313
return (
1414
<div id={id}>
15-
<label>
15+
<label className={formContext?.capitalizeTitle ? 'capitalize' : ''}>
1616
{title}
1717
{required && <span className="required">{' '}*</span>}
1818
{description ? <>{' '}{description}</> : null}

geonode_mapstore_client/client/js/plugins/MetadataEditor/containers/MetadataEditor.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function MetadataEditor({
3030
schema,
3131
uiSchema,
3232
updateError,
33+
capitalizeFieldTitle,
3334
setLoading,
3435
setError,
3536
setUISchema,
@@ -117,7 +118,8 @@ function MetadataEditor({
117118
ref={initialize.current}
118119
formContext={{
119120
title: metadata?.title,
120-
metadata
121+
metadata,
122+
capitalizeTitle: capitalizeFieldTitle
121123
}}
122124
schema={schema}
123125
widgets={widgets}
@@ -162,4 +164,8 @@ MetadataEditor.contextTypes = {
162164
messages: PropTypes.object
163165
};
164166

167+
MetadataEditor.defaultProps = {
168+
capitalizeFieldTitle: true
169+
};
170+
165171
export default MetadataEditor;

geonode_mapstore_client/client/themes/geonode/less/_metadata.less

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
padding: 0;
120120
margin: 0;
121121
li {
122-
* {
122+
.capitalize {
123123
text-transform: capitalize;
124124
}
125125
padding: 0;
@@ -263,8 +263,10 @@
263263
}
264264
}
265265
.gn-metadata-group {
266-
label {
266+
.capitalize {
267267
text-transform: capitalize;
268+
}
269+
label {
268270
word-break: break-all;
269271
}
270272
}

geonode_mapstore_client/templates/geonode-mapstore-client/snippets/metadata_field.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
<div class="gn-metadata-group-value" id="{{prefix}}_{{name}}">
99
{% include 'geonode-mapstore-client/snippets/metadata_field_value.html' with name=name value=property.value schema=property.schema %}
1010
</div>
11-
</dd>
11+
</dd>

geonode_mapstore_client/templates/geonode-mapstore-client/snippets/metadata_fields.html

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,28 @@
44
{% include 'geonode-mapstore-client/snippets/metadata_field.html' with prefix=prefix name=name property=property %}
55
{% endblock property %}
66
{% endfor %}
7-
</dl>
7+
</dl>
8+
<script>
9+
// execute the function only when items are loaded
10+
{% if metadata.items|length > 1 %}
11+
// capitalize the title of the metadata fields based on config
12+
(function () {
13+
const params = new URLSearchParams(window.location.search);
14+
const propString = params.get('props');
15+
if (propString) {
16+
try {
17+
const props = JSON.parse(decodeURIComponent(propString));
18+
const capitalizeTitle = props.capitalizeTitle;
19+
const labels = document.querySelectorAll('.control-label');
20+
if (labels.length ) {
21+
labels.forEach(label => {
22+
label.classList.add('capitalize');
23+
});
24+
}
25+
} catch (e) {
26+
console.warn('Failed to parse metadata viewer props:', e);
27+
}
28+
}
29+
})();
30+
{% endif %}
31+
</script>

0 commit comments

Comments
 (0)