Skip to content

Commit

Permalink
Fix #1775 Query panel fails when selecting a boolean attribute (#1781)
Browse files Browse the repository at this point in the history
* Added boolean type to query builder

* Added additional tests
  • Loading branch information
allyoucanmap authored and offtherailz committed May 11, 2017
1 parent c84fd7b commit fab2eca
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web/client/components/data/query/FilterField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const FilterField = React.createClass({
this.props.onUpdateExceptionField(rowId, message);
},
updateFieldElement(rowId, name, value, type) {
this.props.onUpdateField(rowId, name, value, type);
this.props.onUpdateField(rowId, name, value, type === 'boolean' ? 'string' : type);

if (name === "value") {
// For cascading: filter the attributes that depends on
Expand Down
7 changes: 7 additions & 0 deletions web/client/components/data/query/GroupField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const GroupField = React.createClass({
case "string": {
return ["=", "like", "ilike", "isNull"];
}
case "boolean": {
return ["="];
}
default:
return ["=", ">", "<", ">=", "<=", "<>", "><"];
}
Expand Down Expand Up @@ -129,6 +132,10 @@ const GroupField = React.createClass({
<TextField
operator={filterField.operator}
attType="string"/>
<ComboField
fieldOptions={['true', 'false']}
attType="boolean"
comboFilter={"contains"}/>
</FilterField>
</Col>
<Col xs={2}>
Expand Down
109 changes: 108 additions & 1 deletion web/client/components/data/query/__tests__/FilterField-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ describe('FilterField', () => {
{id: "attribute10", name: "attribute10"}
],
valueId: "id",
valueLabel: "name"
valueLabel: "name",
dependson: {
field: "Attribute1"
}
}
];

Expand Down Expand Up @@ -110,6 +113,9 @@ describe('FilterField', () => {

const valueSelect = filterFieldDOMNode.actual.getElementsByClassName('rw-input')[2];
expect(valueSelect.childNodes[0].nodeValue).toBe("attribute1");

filterfield.updateFieldElement(200, "value", "value", "string");
filterfield.updateExceptionFieldElement(200, "error");
});

it('creates the FilterField component with fieldOptions', () => {
Expand Down Expand Up @@ -185,4 +191,105 @@ describe('FilterField', () => {
expect(valueSelectContainer.style.display).toBe('none');

});

it('tests the FilterField actions', () => {

const actions = {
onUpdateField: () => {},
onUpdateExceptionField: () => {},
onChangeCascadingValue: () => {}
};

const filterField = {
attribute: "attribute"
};

const attributes = [
{
attribute: "Attribute1",
label: "Attribute1",
type: "list",
values: [
{id: "attribute1", name: "attribute1"},
{id: "Attribute2", name: "attribute2"},
{id: "attribute3", name: "attribute3"},
{id: "attribute4", name: "attribute4"},
{id: "attribute5", name: "attribute5"}
],
valueId: "id",
valueLabel: "name",
fieldOptions: {"style": {display: "none"}},
dependson: {
field: "attribute"
}
}
];

const spyUpdateField = expect.spyOn(actions, 'onUpdateField');
const spyUpdateExceptionField = expect.spyOn(actions, 'onUpdateExceptionField');
const spyChangeCascadingValue = expect.spyOn(actions, 'onChangeCascadingValue');

const filterfield = ReactDOM.render(<FilterField filterField={filterField} attributes={attributes} onUpdateField={actions.onUpdateField} onChangeCascadingValue={actions.onChangeCascadingValue} onUpdateExceptionField={actions.onUpdateExceptionField}/>, document.getElementById("container"));

filterfield.props.onUpdateField();
expect(filterfield).toExist();
filterfield.updateFieldElement(200, "name", "value", "string");
expect(spyUpdateField).toHaveBeenCalled();
expect(spyChangeCascadingValue).toNotHaveBeenCalled();
expect(spyUpdateField).toHaveBeenCalledWith(200, "name", "value", "string");
filterfield.updateFieldElement(200, "value", "value", "boolean");
expect(spyUpdateField).toHaveBeenCalled();
expect(spyChangeCascadingValue).toHaveBeenCalled();
expect(spyUpdateField).toHaveBeenCalledWith(200, "name", "value", "string");
expect(spyChangeCascadingValue).toHaveBeenCalledWith(attributes);
filterfield.updateExceptionFieldElement(200, 'error');
expect(spyUpdateExceptionField).toHaveBeenCalled();
expect(spyUpdateExceptionField).toHaveBeenCalledWith(200, 'error');
expect.restoreSpies();
});

it('tests the FilterField actions without dependson field attribute', () => {

const actions = {
onUpdateField: () => {},
onUpdateExceptionField: () => {},
onChangeCascadingValue: () => {}
};

const filterField = {
attribute: "attribute"
};

const attributes = [
{
attribute: "Attribute1",
label: "Attribute1",
type: "list",
values: [
{id: "attribute1", name: "attribute1"},
{id: "Attribute2", name: "attribute2"},
{id: "attribute3", name: "attribute3"},
{id: "attribute4", name: "attribute4"},
{id: "attribute5", name: "attribute5"}
],
valueId: "id",
valueLabel: "name",
fieldOptions: {"style": {display: "none"}},
dependson: {}
}
];

const spyUpdateField = expect.spyOn(actions, 'onUpdateField');
const spyChangeCascadingValue = expect.spyOn(actions, 'onChangeCascadingValue');

const filterfield = ReactDOM.render(<FilterField filterField={filterField} attributes={attributes} onUpdateField={actions.onUpdateField} onChangeCascadingValue={actions.onChangeCascadingValue} onUpdateExceptionField={actions.onUpdateExceptionField}/>, document.getElementById("container"));

expect(filterfield).toExist();
filterfield.updateFieldElement(200, "value", "value", "string");
expect(spyUpdateField).toHaveBeenCalled();
expect(spyUpdateField).toHaveBeenCalledWith(200, "value", "value", "string");
expect(spyChangeCascadingValue).toNotHaveBeenCalled();

expect.restoreSpies();
});
});
19 changes: 17 additions & 2 deletions web/client/components/data/query/__tests__/GroupField-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const ReactDOM = require('react-dom');

const expect = require('expect');

const GroupField = require('../QueryBuilder.jsx');
const GroupField = require('../GroupField.jsx');

describe('GroupField', () => {

Expand Down Expand Up @@ -114,7 +114,22 @@ describe('GroupField', () => {
}

const buttons = document.getElementsByClassName('btn btn-default');
expect(buttons.length).toBe(6);
expect(buttons.length).toBe(4);

const list = groupfield.getOperator({type: "list"});
expect(list).toEqual(["="]);
const string = groupfield.getOperator({type: "string"});
expect(string).toEqual(["=", "like", "ilike", "isNull"]);
const boolean = groupfield.getOperator({type: "boolean"});
expect(boolean).toEqual(["="]);
const noType = groupfield.getOperator();
expect(noType).toEqual(["=", ">", "<", ">=", "<=", "<>", "><"]);

const noSelected = groupfield.getComboValues();
expect(noSelected).toBe(null);

const selectedDependsOn = groupfield.getComboValues({dependson: { field: 'field'}}, attributes);
expect(selectedDependsOn).toBe(null);
});

it('creates the GroupField with cascading', () => {
Expand Down
55 changes: 53 additions & 2 deletions web/client/epics/wfsquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,62 @@ const {changeSpatialAttribute} = require('../actions/queryform');
const {FEATURE_TYPE_SELECTED, featureTypeLoaded, featureTypeError} = require('../actions/wfsquery');

const types = {
// string
// 'xsd:ENTITIES': 'string',
// 'xsd:ENTITY': 'string',
// 'xsd:ID': 'string',
// 'xsd:IDREF': 'string',
// 'xsd:IDREFS': 'string',
// 'xsd:language': 'string',
// 'xsd:Name': 'string',
// 'xsd:NCName': 'string',
// 'xsd:NMTOKEN': 'string',
// 'xsd:NMTOKENS': 'string',
'xsd:normalizedString': 'string',
// 'xsd:QName': 'string',
'xsd:string': 'string',
// 'xsd:token': 'string',

// date
'xsd:date': 'date',
'xsd:dateTime': 'date',
// 'xsd:duration': 'date',
// 'xsd:gDay': 'date',
// 'xsd:gMonth': 'date',
// 'xsd:gMonthDay': 'date',
// 'xsd:gYear': 'date',
// 'xsd:gYearMonth': 'date',
// 'xsd:time': 'date',

// number
// 'xsd:byte': 'number',
'xsd:decimal': 'number',
'xsd:int': 'number',
'xsd:integer': 'number',
'xsd:long': 'number',
'xsd:negativeInteger': 'number',
'xsd:nonNegativeInteger': 'number',
'xsd:nonPositiveInteger': 'number',
'xsd:positiveInteger': 'number',
'xsd:short': 'number',
'xsd:unsignedLong': 'number',
'xsd:unsignedInt': 'number',
'xsd:unsignedShort': 'number',
// 'xsd:unsignedByte': 'number',

// from old object
'xsd:number': 'number',
'xsd:int': 'number'

// misc
// 'xsd:anyURI': 'string',
// 'xsd:base64Binary': 'number',
'xsd:boolean': 'boolean',
'xsd:double': 'number',
// 'xsd:hexBinary': 'string',
// 'xsd:NOTATION': 'string',
'xsd:float': 'number'
};

const fieldConfig = {};
const extractInfo = (data) => {
return {
Expand All @@ -35,7 +86,7 @@ const extractInfo = (data) => {
return conf;
}),
attributes: data.featureTypes[0].properties
.filter((attribute) => attribute.type.indexOf('gml:') !== 0)
.filter((attribute) => attribute.type.indexOf('gml:') !== 0 && types[attribute.type])
.map((attribute) => {
let conf = {
label: attribute.name,
Expand Down

0 comments on commit fab2eca

Please sign in to comment.