Skip to content

Commit

Permalink
Fixes #1355: FilterField by attribute configuration options
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Dec 19, 2016
1 parent 049e47e commit 31683a5
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
2 changes: 1 addition & 1 deletion createProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions web/client/components/data/query/FilterField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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 (
Expand Down
74 changes: 74 additions & 0 deletions web/client/components/data/query/__tests__/FilterField-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<FilterField
attributes={attributes}
filterField={filterField}>
<ComboField
attType="list"
valueField={'id'}
textField={'name'}
fieldOptions={attributes[0] && attributes[0].type === "list" ? [null, ...attributes[0].values] : null}/>
<DateField
attType="date"
operator={filterField.operator}/>
</FilterField>,
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');

});
});

0 comments on commit 31683a5

Please sign in to comment.