Skip to content

Commit 753ed98

Browse files
authored
Handle options and errors on field (#1915)
1 parent 9f79aaf commit 753ed98

File tree

7 files changed

+53
-15
lines changed

7 files changed

+53
-15
lines changed

geonode_mapstore_client/client/js/components/Autocomplete/Autocomplete.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const Autocomplete = ({
2929
title,
3030
value,
3131
valueKey = "value",
32+
showLabel = true,
3233
...props
3334
}) => {
3435
const getValue = () => {
@@ -46,10 +47,10 @@ const Autocomplete = ({
4647

4748
return (
4849
<div className={`autocomplete${className ? " " + className : ""}${!!error ? " " + "has-error" : ""}`}>
49-
<div className="title-container">
50+
{showLabel && <div className="title-container">
5051
<label className="control-label" htmlFor={id}>{title || name}</label>
5152
{helpTitleIcon && !isEmpty(description) && <IconWithTooltip className="help-title" tooltip={description} tooltipPosition={"right"} />}
52-
</div>
53+
</div>}
5354
<SelectInfiniteScroll
5455
{...props}
5556
id={id}
@@ -72,7 +73,8 @@ Autocomplete.propTypes = {
7273
name: PropTypes.string,
7374
title: PropTypes.string,
7475
value: PropTypes.any.isRequired,
75-
valueKey: PropTypes.string
76+
valueKey: PropTypes.string,
77+
showLabel: PropTypes.bool
7678
};
7779

7880
export default Autocomplete;

geonode_mapstore_client/client/js/plugins/MetadataEditor/actions/metadata.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const SET_METADATA_UPDATING = 'GEONODE:SET_METADATA_UPDATING';
1616
export const SET_METADATA_UPDATE_ERROR = 'GEONODE:SET_METADATA_UPDATE_ERROR';
1717
export const SET_METADATA_PREVIEW = 'GEONODE:SET_METADATA_PREVIEW';
1818
export const SET_METADATA_RESOURCE = 'GEONODE:SET_METADATA_RESOURCE';
19+
export const SET_METADATA_EXTRA_ERRORS = 'GEONODE:SET_METADATA_EXTRA_ERRORS';
1920

2021
export const setMetadata = (metadata) => ({
2122
type: SET_METADATA,
@@ -66,3 +67,8 @@ export const setMetadataResource = (resource) => ({
6667
type: SET_METADATA_RESOURCE,
6768
resource
6869
});
70+
71+
export const setExtraErrors = (extraErrors) => ({
72+
type: SET_METADATA_EXTRA_ERRORS,
73+
extraErrors
74+
});

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ const SchemaField = (props) => {
2727
formData,
2828
idSchema,
2929
name,
30-
hideError,
3130
errorSchema,
3231
uiSchema
3332
} = props;
34-
const autocomplete = uiSchema?.['ui:options']?.['geonode-ui:autocomplete'];
33+
const uiOptions = uiSchema?.['ui:options'];
34+
const autocomplete = uiOptions?.['geonode-ui:autocomplete'];
3535
const isSchemaItemString = schema?.items?.type === 'string';
3636
const isSchemaItemObject = schema?.items?.type === 'object';
3737
const isMultiSelect = schema?.type === 'array' && (isSchemaItemString ||
@@ -40,6 +40,17 @@ const SchemaField = (props) => {
4040
const isSingleSelect = schema?.type === 'object' && !isEmpty(schema?.properties);
4141

4242
if (autocomplete && (isMultiSelect || isSingleSelect)) {
43+
const {
44+
classNames,
45+
style,
46+
description,
47+
disabled,
48+
help: helpText,
49+
hideError,
50+
label,
51+
placeholder: autoCompletePlaceholder,
52+
title
53+
} = uiOptions;
4354
const errors = (!hideError ? castArray(errorSchema) : [])
4455
.reduce((acc, errorEntry) => {
4556
if (errorEntry?.__errors) {
@@ -61,23 +72,26 @@ const SchemaField = (props) => {
6172
const resultsKey = autocompleteOptions?.resultsKey || 'results';
6273
const valueKey = autocompleteOptions?.valueKey || 'id';
6374
const labelKey = autocompleteOptions?.labelKey || 'label';
64-
const placeholder = autocompleteOptions?.placeholder ?? '...';
6575
const creatable = !!autocompleteOptions?.creatable;
76+
const placeholder = autoCompletePlaceholder ?? '...';
6677

6778
let autoCompleteProps = {
68-
className: "gn-metadata-autocomplete",
79+
className: `gn-metadata-autocomplete${classNames ? ' ' + classNames : ''}`,
6980
clearable: !isMultiSelect,
7081
creatable,
7182
id: idSchema.$id,
7283
labelKey,
7384
multi: isMultiSelect,
7485
name,
7586
placeholder,
76-
title: schema.title,
87+
showLabel: label ?? true,
88+
title: title ?? schema.title,
7789
value: formData,
7890
valueKey,
7991
helpTitleIcon: true,
80-
description: schema.description,
92+
description: helpText ?? description ?? schema.description, // Help text is preferred over description and displayed as a tooltip
93+
disabled,
94+
style,
8195
onChange: (selected) => {
8296
let _selected = selected?.result ?? null;
8397
if (isMultiSelect) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ function MetadataEditor({
2222
pk,
2323
loading,
2424
error,
25+
extraErrors,
2526
metadata,
2627
schema,
2728
uiSchema,
@@ -97,6 +98,7 @@ function MetadataEditor({
9798
validator={validator}
9899
templates={templates}
99100
fields={fields}
101+
extraErrors={extraErrors}
100102
experimental_defaultFormStateBehavior={{
101103
arrayMinItems: {
102104
populate: 'never',

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import React from 'react';
10+
import get from 'lodash/get';
1011
import { updateMetadata } from '@js/api/geonode/v2/metadata';
1112
import Message from '@mapstore/framework/components/I18N/Message';
1213
import Button from '@js/components/Button';
@@ -20,15 +21,17 @@ function MetadataUpdateButton({
2021
updating,
2122
setUpdating,
2223
setUpdateError,
23-
setInitialMetadata
24+
setInitialMetadata,
25+
setExtraErrors
2426
}) {
2527

2628
function handleUpdate() {
2729
setUpdating(true);
2830
setUpdateError(false);
2931
updateMetadata(pk, metadata)
30-
.then(() => {
32+
.then((res) => {
3133
setInitialMetadata(metadata);
34+
setExtraErrors(get(res, 'data.extraErrors', {}));
3235
})
3336
.catch(() => {
3437
setUpdateError(true);

geonode_mapstore_client/client/js/plugins/MetadataEditor/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import {
2121
setMetadataError,
2222
setMetadataUpdating,
2323
setMetadataUpdateError,
24-
setMetadataResource
24+
setMetadataResource,
25+
setExtraErrors
2526
} from './actions/metadata';
2627
import { parseDevHostname } from '@js/utils/APIUtils';
2728

@@ -35,16 +36,18 @@ const connectMetadata = connect(
3536
createSelector([
3637
state => state?.metadata?.loading,
3738
state => state?.metadata?.error,
39+
state => state?.metadata?.extraErrors,
3840
state => state?.metadata?.metadata,
3941
state => state?.metadata?.initialMetadata,
4042
state => state?.metadata?.schema,
4143
state => state?.metadata?.uiSchema,
4244
state => state?.metadata?.updating,
4345
state => state?.metadata?.updateError,
4446
state => state?.metadata?.resource
45-
], (loading, error, metadata, initialMetadata, schema, uiSchema, updating, updateError, resource) => ({
47+
], (loading, error, extraErrors, metadata, initialMetadata, schema, uiSchema, updating, updateError, resource) => ({
4648
loading,
4749
error,
50+
extraErrors,
4851
metadata,
4952
schema,
5053
uiSchema,
@@ -62,7 +65,8 @@ const connectMetadata = connect(
6265
setInitialMetadata,
6366
setUpdateError: setMetadataUpdateError,
6467
setUpdating: setMetadataUpdating,
65-
setResource: setMetadataResource
68+
setResource: setMetadataResource,
69+
setExtraErrors
6670
}
6771
);
6872

geonode_mapstore_client/client/js/plugins/MetadataEditor/reducers/metadata.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import {
1616
SET_METADATA_UPDATING,
1717
SET_METADATA_UPDATE_ERROR,
1818
SET_METADATA_PREVIEW,
19-
SET_METADATA_RESOURCE
19+
SET_METADATA_RESOURCE,
20+
SET_METADATA_EXTRA_ERRORS
2021
} from '../actions/metadata';
2122

2223
function metadata(state = {}, action) {
@@ -81,6 +82,12 @@ function metadata(state = {}, action) {
8182
resource: action.resource
8283
};
8384
}
85+
case SET_METADATA_EXTRA_ERRORS: {
86+
return {
87+
...state,
88+
extraErrors: action.extraErrors
89+
};
90+
}
8491
default:
8592
return state;
8693
}

0 commit comments

Comments
 (0)