Added errors to filter functions

This commit is contained in:
orangemug 2020-02-16 21:25:41 +00:00
parent 1300951a29
commit ff8a8fb749
6 changed files with 70 additions and 17 deletions

View file

@ -95,8 +95,9 @@ export default class FunctionSpecProperty extends React.Component {
static propTypes = { static propTypes = {
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
fieldName: PropTypes.string.isRequired, fieldName: PropTypes.string.isRequired,
fieldType: PropTypes.string.isRequired,
fieldSpec: PropTypes.object.isRequired, fieldSpec: PropTypes.object.isRequired,
error: PropTypes.object, errors: PropTypes.object,
value: PropTypes.oneOfType([ value: PropTypes.oneOfType([
PropTypes.object, PropTypes.object,
@ -225,11 +226,12 @@ export default class FunctionSpecProperty extends React.Component {
if (this.state.isExpression) { if (this.state.isExpression) {
specField = ( specField = (
<ExpressionProperty <ExpressionProperty
error={this.props.error} errors={this.props.errors}
onChange={this.props.onChange.bind(this, this.props.fieldName)} onChange={this.props.onChange.bind(this, this.props.fieldName)}
canUndo={this.canUndo} canUndo={this.canUndo}
onUndo={this.undoExpression} onUndo={this.undoExpression}
onDelete={this.deleteExpression} onDelete={this.deleteExpression}
fieldType={this.props.fieldType}
fieldName={this.props.fieldName} fieldName={this.props.fieldName}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
value={this.props.value} value={this.props.value}
@ -239,8 +241,9 @@ export default class FunctionSpecProperty extends React.Component {
else if (isZoomField(this.props.value)) { else if (isZoomField(this.props.value)) {
specField = ( specField = (
<ZoomProperty <ZoomProperty
error={this.props.error} errors={this.props.errors}
onChange={this.props.onChange.bind(this)} onChange={this.props.onChange.bind(this)}
fieldType={this.props.fieldType}
fieldName={this.props.fieldName} fieldName={this.props.fieldName}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
value={this.props.value} value={this.props.value}
@ -252,8 +255,9 @@ export default class FunctionSpecProperty extends React.Component {
else if (isDataField(this.props.value)) { else if (isDataField(this.props.value)) {
specField = ( specField = (
<DataProperty <DataProperty
error={this.props.error} errors={this.props.errors}
onChange={this.props.onChange.bind(this)} onChange={this.props.onChange.bind(this)}
fieldType={this.props.fieldType}
fieldName={this.props.fieldName} fieldName={this.props.fieldName}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
value={this.props.value} value={this.props.value}
@ -265,8 +269,9 @@ export default class FunctionSpecProperty extends React.Component {
else { else {
specField = ( specField = (
<SpecProperty <SpecProperty
error={this.props.error} errors={this.props.errors}
onChange={this.props.onChange.bind(this)} onChange={this.props.onChange.bind(this)}
fieldType={this.props.fieldType}
fieldName={this.props.fieldName} fieldName={this.props.fieldName}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
value={this.props.value} value={this.props.value}

View file

@ -57,14 +57,14 @@ export default class PropertyGroup extends React.Component {
const layout = this.props.layer.layout || {} const layout = this.props.layer.layout || {}
const fieldValue = fieldName in paint ? paint[fieldName] : layout[fieldName] const fieldValue = fieldName in paint ? paint[fieldName] : layout[fieldName]
const fieldType = fieldName in paint ? 'paint' : 'layout'; const fieldType = fieldName in paint ? 'paint' : 'layout';
const errorKey = fieldType+"."+fieldName;
return <FunctionSpecField return <FunctionSpecField
error={errors[errorKey]} errors={errors}
onChange={this.onPropertyChange} onChange={this.onPropertyChange}
key={fieldName} key={fieldName}
fieldName={fieldName} fieldName={fieldName}
value={fieldValue} value={fieldValue}
fieldType={fieldType}
fieldSpec={fieldSpec} fieldSpec={fieldSpec}
/> />
}) })

View file

@ -48,7 +48,7 @@ export default class DataProperty extends React.Component {
PropTypes.bool, PropTypes.bool,
PropTypes.array PropTypes.array
]), ]),
error: PropTypes.object, errors: PropTypes.object,
} }
state = { state = {
@ -145,6 +145,8 @@ export default class DataProperty extends React.Component {
} }
render() { render() {
const {fieldName, fieldType, errors} = this.props;
if (typeof this.props.value.type === "undefined") { if (typeof this.props.value.type === "undefined") {
this.props.value.type = this.getFieldFunctionType(this.props.fieldSpec) this.props.value.type = this.getFieldFunctionType(this.props.fieldSpec)
} }
@ -182,7 +184,22 @@ export default class DataProperty extends React.Component {
</div> </div>
} }
return <InputBlock key={key} action={deleteStopBtn} label=""> const errorKeyStart = `${fieldType}.${fieldName}.stops[${idx}]`;
const foundErrors = Object.entries(errors).filter(([key, error]) => {
return key.startsWith(errorKeyStart);
});
const message = foundErrors.map(([key, error]) => {
return error.message;
}).join("");
const error = message ? {message} : undefined;
return <InputBlock
error={error}
key={key}
action={deleteStopBtn}
label=""
>
{zoomInput} {zoomInput}
<div className="maputnik-data-spec-property-stop-data"> <div className="maputnik-data-spec-property-stop-data">
{dataInput} {dataInput}
@ -201,7 +218,6 @@ export default class DataProperty extends React.Component {
return <div className="maputnik-data-spec-block"> return <div className="maputnik-data-spec-block">
<div className="maputnik-data-spec-property"> <div className="maputnik-data-spec-property">
<InputBlock <InputBlock
error={this.props.error}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
label={labelFromFieldName(this.props.fieldName)} label={labelFromFieldName(this.props.fieldName)}
> >

View file

@ -17,18 +17,22 @@ export default class ExpressionProperty extends React.Component {
fieldName: PropTypes.string, fieldName: PropTypes.string,
fieldSpec: PropTypes.object, fieldSpec: PropTypes.object,
value: PropTypes.any, value: PropTypes.any,
error: PropTypes.object, errors: PropTypes.object,
onChange: PropTypes.func, onChange: PropTypes.func,
onUndo: PropTypes.func, onUndo: PropTypes.func,
canUndo: PropTypes.func, canUndo: PropTypes.func,
} }
static defaultProps = {
errors: {},
}
constructor (props) { constructor (props) {
super(); super();
} }
render() { render() {
const {value, canUndo} = this.props; const {errors, fieldName, fieldType, value, canUndo} = this.props;
const undoDisabled = canUndo ? !canUndo() : true; const undoDisabled = canUndo ? !canUndo() : true;
const deleteStopBtn = ( const deleteStopBtn = (
@ -53,8 +57,10 @@ export default class ExpressionProperty extends React.Component {
</> </>
); );
const error = errors[fieldType+"."+fieldName];
return <InputBlock return <InputBlock
error={this.props.error} error={error}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
label={labelFromFieldName(this.props.fieldName)} label={labelFromFieldName(this.props.fieldName)}
action={deleteStopBtn} action={deleteStopBtn}

View file

@ -13,13 +13,20 @@ export default class SpecProperty extends React.Component {
onZoomClick: PropTypes.func.isRequired, onZoomClick: PropTypes.func.isRequired,
onDataClick: PropTypes.func.isRequired, onDataClick: PropTypes.func.isRequired,
fieldName: PropTypes.string, fieldName: PropTypes.string,
fieldType: PropTypes.string,
fieldSpec: PropTypes.object, fieldSpec: PropTypes.object,
value: PropTypes.any, value: PropTypes.any,
error: PropTypes.object, errors: PropTypes.object,
onExpressionClick: PropTypes.func, onExpressionClick: PropTypes.func,
} }
static defaultProps = {
errors: {},
}
render() { render() {
const {errors, fieldName, fieldType} = this.props;
const functionBtn = <FunctionButtons const functionBtn = <FunctionButtons
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
onZoomClick={this.props.onZoomClick} onZoomClick={this.props.onZoomClick}
@ -28,8 +35,10 @@ export default class SpecProperty extends React.Component {
onExpressionClick={this.props.onExpressionClick} onExpressionClick={this.props.onExpressionClick}
/> />
const error = errors[fieldType+"."+fieldName];
return <InputBlock return <InputBlock
error={this.props.error} error={error}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
label={labelFromFieldName(this.props.fieldName)} label={labelFromFieldName(this.props.fieldName)}
action={functionBtn} action={functionBtn}

View file

@ -42,9 +42,10 @@ export default class ZoomProperty extends React.Component {
onChange: PropTypes.func, onChange: PropTypes.func,
onDeleteStop: PropTypes.func, onDeleteStop: PropTypes.func,
onAddStop: PropTypes.func, onAddStop: PropTypes.func,
fieldType: PropTypes.string,
fieldName: PropTypes.string, fieldName: PropTypes.string,
fieldSpec: PropTypes.object, fieldSpec: PropTypes.object,
error: PropTypes.object, errors: PropTypes.object,
value: PropTypes.oneOfType([ value: PropTypes.oneOfType([
PropTypes.object, PropTypes.object,
PropTypes.string, PropTypes.string,
@ -54,6 +55,10 @@ export default class ZoomProperty extends React.Component {
]), ]),
} }
static defaultProps = {
errors: {},
}
state = { state = {
refs: {} refs: {}
} }
@ -118,14 +123,26 @@ export default class ZoomProperty extends React.Component {
} }
render() { render() {
const {fieldName, fieldType, errors} = this.props;
const zoomFields = this.props.value.stops.map((stop, idx) => { const zoomFields = this.props.value.stops.map((stop, idx) => {
const zoomLevel = stop[0] const zoomLevel = stop[0]
const key = this.state.refs[idx]; const key = this.state.refs[idx];
const value = stop[1] const value = stop[1]
const deleteStopBtn= <DeleteStopButton onClick={this.props.onDeleteStop.bind(this, idx)} /> const deleteStopBtn= <DeleteStopButton onClick={this.props.onDeleteStop.bind(this, idx)} />
const errorKeyStart = `${fieldType}.${fieldName}.stops[${idx}]`;
const foundErrors = Object.entries(errors).filter(([key, error]) => {
return key.startsWith(errorKeyStart);
});
const message = foundErrors.map(([key, error]) => {
return error.message;
}).join("");
const error = message ? {message} : undefined;
return <InputBlock return <InputBlock
error={this.props.error} error={error}
key={key} key={key}
fieldSpec={this.props.fieldSpec} fieldSpec={this.props.fieldSpec}
label={labelFromFieldName(this.props.fieldName)} label={labelFromFieldName(this.props.fieldName)}