Skip to content

Commit 9e9cf7f

Browse files
committed
Compacted utils (now no files with 5 lines of code) Changed config.settings.locale (see antd instead of full2) Reworked logic of reusing value after changing field/op
1 parent 5dbc49f commit 9e9cf7f

31 files changed

+416
-314
lines changed

.babelrc.old

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/demo/config.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const {
1313
} = Widgets;
1414
const {ProximityOperator} = Operators;
1515
import moment from 'moment';
16+
import en_US from 'antd/lib/locale-provider/en_US';
17+
import ru_RU from 'antd/lib/locale-provider/ru_RU';
1618

1719
export default {
1820
conjunctions: {
@@ -40,17 +42,22 @@ export default {
4042
subfields: {
4143
subname: {
4244
//label: 'Subname', //'subname' should be used instead
43-
label2: 'MemberName',
45+
label2: 'MemberName', //only for menu's toggler
4446
type: 'number',
4547
operators: ['equal'],
4648
},
49+
prox1: {
50+
label: 'prox1',
51+
type: 'text',
52+
operators: ['proximity'],
53+
},
4754
}
4855
},
49-
name: {
50-
label: 'Name',
56+
prox2: {
57+
label: 'prox2',
5158
type: 'text',
5259
operators: ['proximity'],
53-
defaultOperator: 'not_equal',
60+
defaultOperator: 'not_equal', //will not be used
5461
},
5562
name2: {
5663
label: 'Name 2',
@@ -104,6 +111,11 @@ export default {
104111
type: 'datetime',
105112
valueSources: ['field']
106113
},
114+
datetime2: {
115+
label: 'DateTime2',
116+
type: 'datetime',
117+
valueSources: ['value']
118+
},
107119
color: {
108120
label: 'Color',
109121
type: 'select',
@@ -130,7 +142,23 @@ export default {
130142
listValues: {
131143
yellow: 'Yellow',
132144
green: 'Green',
133-
orange: 'Orange'
145+
orange: 'Orange',
146+
purple: 'Purple'
147+
},
148+
},
149+
color3: {
150+
label: 'Color3',
151+
type: 'select',
152+
defaultOperator: 'select_not_equals',
153+
operators: [
154+
'select_not_equals',
155+
'select_not_any_in'
156+
],
157+
listValues: {
158+
yellow: 'Yellow',
159+
green: 'Green',
160+
orange: 'Orange',
161+
purple: 'Purple'
134162
},
135163
},
136164
multicolor: {
@@ -146,6 +174,10 @@ export default {
146174
label: 'In stock',
147175
type: 'boolean',
148176
},
177+
expecting: {
178+
label: 'Expecting',
179+
type: 'boolean',
180+
},
149181
},
150182
types: {
151183
text: {
@@ -588,15 +620,16 @@ export default {
588620
settings: {
589621
locale: {
590622
short: 'en',
591-
full1: 'en-US',
592-
full2: 'en_US',
623+
full: 'en-US',
624+
antd: en_US,
593625
},
594626
hideConjForOne: true,
595627
renderSize: 'small',
596628
renderConjsAsRadios: false,
597629
renderFieldAndOpAsDropdown: false,
598-
setOpOnChangeField: ['default'], // 'default' (default if present), 'keep' (keep prev from last field), 'first', 'none'
599-
clearValueOnChangeField: true, //false - if prev & next fields have same type (widget), keep
630+
setOpOnChangeField: ['keep', 'default'], // 'default' (default if present), 'keep' (keep prev from last field), 'first', 'none'
631+
clearValueOnChangeField: false, //false - if prev & next fields have same type (widget), keep
632+
clearValueOnChangeOp: false,
600633
setDefaultFieldAndOp: false,
601634
maxNesting: 10,
602635
fieldSeparator: '.',

examples/demo/demo.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React, {Component} from 'react';
22
import {Query, Builder, Preview, Utils} from 'react-awesome-query-builder';
3-
const {queryBuilderFormat, queryString, extendConfig} = Utils;
3+
const {queryBuilderFormat, queryString} = Utils;
44
import config from './config';
55
var stringify = require('json-stringify-safe');
6-
76
import '../../css/reset.scss';
87
import '../../css/styles.scss';
98
import '../../css/compact_styles.scss';

modules/actions/tree.js

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import uuid from '../utils/uuid';
2-
import expandTreePath from '../utils/expandTreePath';
3-
import defaultRuleProperties from '../utils/defaultRuleProperties';
4-
import defaultGroupProperties from '../utils/defaultGroupProperties';
2+
import {expandTreePath} from '../utils/treeUtils';
3+
import {defaultRuleProperties, defaultGroupProperties} from '../utils/defaultUtils';
4+
55
import * as constants from '../constants';
66
import Immutable from 'immutable';
77

@@ -29,25 +29,25 @@ export const addRule = (config, path, properties) => ({
2929
properties: defaultRuleProperties(config).merge(properties || {})
3030
});
3131

32-
/**
33-
* @param {object} config
34-
* @param {Immutable.List} path
35-
*/
36-
export const removeRuleOld = (config, path) => {
37-
return (dispatch, getState) => {
38-
dispatch({
39-
type: constants.REMOVE_RULE,
40-
path: path,
41-
config: config
42-
});
43-
44-
const { tree } = getState();
45-
const parentPath = path.slice(0, -1);
46-
if (!hasChildren(tree, parentPath)) {
47-
dispatch(addRule(config, parentPath));
48-
}
49-
};
50-
};
32+
// /**
33+
// * @param {object} config
34+
// * @param {Immutable.List} path
35+
// */
36+
// export const removeRuleOld = (config, path) => {
37+
// return (dispatch, getState) => {
38+
// dispatch({
39+
// type: constants.REMOVE_RULE,
40+
// path: path,
41+
// config: config
42+
// });
43+
44+
// const { tree } = getState();
45+
// const parentPath = path.slice(0, -1);
46+
// if (!hasChildren(tree, parentPath)) {
47+
// dispatch(addRule(config, parentPath));
48+
// }
49+
// };
50+
// };
5151

5252
/**
5353
* @param {object} config
@@ -60,28 +60,28 @@ export const removeRule = (config, path) => ({
6060
});
6161

6262

63-
/**
64-
* @param {object} config
65-
* @param {Immutable.List} path
66-
* @param {object} properties
67-
*/
68-
export const addGroupOld = (config, path, properties) => {
69-
return (dispatch) => {
70-
const groupUuid = uuid();
71-
72-
dispatch({
73-
type: constants.ADD_GROUP,
74-
path: path,
75-
id: groupUuid,
76-
properties: defaultGroupProperties(config).merge(properties || {}),
77-
config: config
78-
});
79-
80-
const groupPath = path.push(groupUuid);
81-
dispatch(addRule(config, groupPath));
82-
dispatch(addRule(config, groupPath));
83-
};
84-
};
63+
// /**
64+
// * @param {object} config
65+
// * @param {Immutable.List} path
66+
// * @param {object} properties
67+
// */
68+
// export const addGroupOld = (config, path, properties) => {
69+
// return (dispatch) => {
70+
// const groupUuid = uuid();
71+
72+
// dispatch({
73+
// type: constants.ADD_GROUP,
74+
// path: path,
75+
// id: groupUuid,
76+
// properties: defaultGroupProperties(config).merge(properties || {}),
77+
// config: config
78+
// });
79+
80+
// const groupPath = path.push(groupUuid);
81+
// dispatch(addRule(config, groupPath));
82+
// dispatch(addRule(config, groupPath));
83+
// };
84+
// };
8585

8686
/**
8787
* @param {object} config
@@ -97,25 +97,25 @@ export const addGroup = (config, path, properties) => ({
9797

9898

9999

100-
/**
101-
* @param {object} config
102-
* @param {Immutable.List} path
103-
*/
104-
export const removeGroupOld = (config, path) => {
105-
return (dispatch, getState) => {
106-
dispatch({
107-
type: constants.REMOVE_GROUP,
108-
path: path,
109-
config: config
110-
});
111-
112-
const { tree } = getState();
113-
const parentPath = path.slice(0, -1);
114-
if (!hasChildren(tree, parentPath)) {
115-
dispatch(addRule(config, parentPath));
116-
}
117-
};
118-
};
100+
// /**
101+
// * @param {object} config
102+
// * @param {Immutable.List} path
103+
// */
104+
// export const removeGroupOld = (config, path) => {
105+
// return (dispatch, getState) => {
106+
// dispatch({
107+
// type: constants.REMOVE_GROUP,
108+
// path: path,
109+
// config: config
110+
// });
111+
112+
// const { tree } = getState();
113+
// const parentPath = path.slice(0, -1);
114+
// if (!hasChildren(tree, parentPath)) {
115+
// dispatch(addRule(config, parentPath));
116+
// }
117+
// };
118+
// };
119119

120120
/**
121121
* @param {object} config

modules/components/Field.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import shallowCompare from 'react-addons-shallow-compare';
3-
import {getFieldConfig, getFieldPath, getFieldPathLabels, calcTextWidth} from "../utils/index";
3+
import {getFieldConfig, getFieldPath, getFieldPathLabels} from "../utils/configUtils";
4+
import {calcTextWidth} from "../utils/stuff";
45
import { Menu, Dropdown, Icon, Tooltip, Button, Select } from 'antd';
56
const { Option, OptGroup } = Select;
67
const SubMenu = Menu.SubMenu;

modules/components/Operator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import shallowCompare from 'react-addons-shallow-compare';
3-
import {getFieldConfig, getFieldPath, getFieldPathLabels, calcTextWidth} from "../utils/index";
3+
import {getFieldConfig, getFieldPath, getFieldPathLabels} from "../utils/configUtils";
4+
import {calcTextWidth} from "../utils/stuff";
45
import { Menu, Dropdown, Icon, Tooltip, Button, Select } from 'antd';
56
const { Option, OptGroup } = Select;
67
const SubMenu = Menu.SubMenu;

modules/components/Query.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React, {Component, PropTypes} from 'react';
22
import createTreeStore from '../stores/tree';
33
import {createStore} from 'redux';
44
import {Provider, Connector, connect} from 'react-redux';
5-
import bindActionCreators from '../utils/bindActionCreators';
65
import * as actions from '../actions';
7-
import {extendConfig, getAntLocale} from "../utils/index";
6+
import {extendConfig} from "../utils/configUtils";
7+
import {bindActionCreators} from "../utils/stuff";
88
import { LocaleProvider } from 'antd';
99

1010

@@ -74,7 +74,7 @@ export default class Query extends Component {
7474
config = extendConfig(config);
7575

7676
return (
77-
<LocaleProvider locale={getAntLocale(config.settings.locale.full2)}>
77+
<LocaleProvider locale={config.settings.locale.antd}>
7878
<Provider store={this.state.store}>
7979
<QueryContainer store={this.state.store} get_children={get_children} config={config} onChange={onChange}/>
8080
</Provider>

modules/components/Rule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Row, Col, Menu, Dropdown, Icon, Tooltip, Button } from 'antd';
1010
const SubMenu = Menu.SubMenu;
1111
const MenuItem = Menu.Item;
1212
const DropdownButton = Dropdown.Button;
13-
import {getFieldConfig, getFieldPath, getFieldPathLabels, getOperatorConfig, getFieldWidgetConfig} from "../utils/index";
13+
import {getFieldConfig, getFieldPath, getFieldPathLabels, getOperatorConfig, getFieldWidgetConfig} from "../utils/configUtils";
1414
import size from 'lodash/size';
1515
var stringify = require('json-stringify-safe');
1616
const classNames = require('classnames');

modules/components/containers/OperatorOptionsContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import Immutable from 'immutable';
33
import shallowCompare from 'react-addons-shallow-compare';
4-
import {getOperatorConfig} from "../../utils/index";
4+
import {getOperatorConfig} from "../../utils/configUtils";
55

66
export default (OperatorOptions) => {
77
return class OperatorOptionsContainer extends Component {

modules/components/containers/RuleContainer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { Component, PropTypes } from 'react';
22
import shallowCompare from 'react-addons-shallow-compare';
33
import size from 'lodash/size';
4-
import {getFieldConfig} from "../../utils/index";
4+
import {getFieldConfig} from "../../utils/configUtils";
55

66
export default (Rule) => {
77
return class RuleContainer extends Component {

0 commit comments

Comments
 (0)