From 31683a510c560ebb1829d6666073ebe85e0e64d0 Mon Sep 17 00:00:00 2001 From: Mauro Bartolomeoli Date: Mon, 19 Dec 2016 15:03:54 +0100 Subject: [PATCH] Fixes #1355: FilterField by attribute configuration options --- createProject.js | 2 +- .../components/data/query/FilterField.jsx | 5 +- .../data/query/__tests__/FilterField-test.jsx | 74 +++++++++++++++++++ 3 files changed, 78 insertions(+), 3 deletions(-) diff --git a/createProject.js b/createProject.js index a3c2d80a05..7328454eab 100644 --- a/createProject.js +++ b/createProject.js @@ -39,7 +39,7 @@ function copyStaticFiles() { }).forEach(function(stream) { stream.on('finish', function() { copied++; - if(copied == 4) { + if(copied === 4) { ncp('./project/static', outFolder, function(err) { if (err) { return console.log(err); diff --git a/web/client/components/data/query/FilterField.jsx b/web/client/components/data/query/FilterField.jsx index c0f98226aa..276d476657 100644 --- a/web/client/components/data/query/FilterField.jsx +++ b/web/client/components/data/query/FilterField.jsx @@ -9,6 +9,7 @@ const React = require('react'); const {Row, Col} = require('react-bootstrap'); const ComboField = require('./ComboField'); +const assign = require('object-assign'); const FilterField = React.createClass({ propTypes: { @@ -42,14 +43,14 @@ const FilterField = React.createClass({ renderValueField(selectedAttribute) { const valueElement = React.cloneElement( React.Children.toArray(this.props.children).filter((node) => node.props.attType === selectedAttribute.type)[0], - { + assign({ fieldName: "value", fieldRowId: this.props.filterField.rowId, fieldValue: this.props.filterField.value, fieldException: this.props.filterField.exception, onUpdateField: this.updateFieldElement, onUpdateExceptionField: this.updateExceptionFieldElement - } + }, selectedAttribute.fieldOptions || {}) ); return ( diff --git a/web/client/components/data/query/__tests__/FilterField-test.jsx b/web/client/components/data/query/__tests__/FilterField-test.jsx index 97a8e46c61..f763a8da81 100644 --- a/web/client/components/data/query/__tests__/FilterField-test.jsx +++ b/web/client/components/data/query/__tests__/FilterField-test.jsx @@ -111,4 +111,78 @@ describe('FilterField', () => { const valueSelect = filterFieldDOMNode.actual.getElementsByClassName('rw-input')[3]; expect(valueSelect.childNodes[0].nodeValue).toBe("attribute1"); }); + + it('creates the FilterField component with fieldOptions', () => { + const filterField = { + rowId: 200, + attribute: "Attribute1", + operator: "=", + value: null, + exception: null + }; + + 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"}} + } + ]; + + const filterfield = ReactDOM.render( + + + + , + document.getElementById("container")); + + expect(filterfield).toExist(); + + expect(filterfield.props.children).toExist(); + expect(filterfield.props.children.length).toBe(2); + + expect(filterfield.props.attributes).toExist(); + expect(filterfield.props.attributes.length).toBe(1); + + expect(filterfield.props.filterField).toExist(); + + const filterFieldDOMNode = expect(ReactDOM.findDOMNode(filterfield)); + + expect(filterFieldDOMNode).toExist(); + + let childNodes = filterFieldDOMNode.actual.childNodes; + + expect(childNodes.length).toBe(3); + + const inputFields = filterFieldDOMNode.actual.getElementsByClassName('rw-input'); + expect(inputFields.length).toBe(4); + + const attributeSelect = filterFieldDOMNode.actual.getElementsByClassName('rw-input')[0]; + expect(attributeSelect.childNodes[0].nodeValue).toBe("Attribute1"); + + const operatorSelect = filterFieldDOMNode.actual.getElementsByClassName('rw-input')[2]; + expect(operatorSelect.childNodes[0].nodeValue).toBe("="); + + const valueSelectContainer = filterFieldDOMNode.actual.getElementsByClassName('col-xs-6')[0].childNodes[0]; + expect(valueSelectContainer.style.display).toBe('none'); + + }); });