Skip to content

Commit a195927

Browse files
authored
fix #252 (#285)
* fix #252 * mt * readme * pr * lint
1 parent 751867f commit a195927

File tree

6 files changed

+18
-18
lines changed

6 files changed

+18
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
2+
- 2.1.19
3+
- Fixed issue #252 ("Cannot update a component from inside the function body of a different component")
4+
- Issue #190: Fixed TS def for getTree/2 - added 2nd param light?
25
- 2.1.17
36
- Dropped support of loading query in obsolete Immutable string format used in versions 0.* (issue #254)
47
- 2.1.16

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ Wrapping in `div.query-builder-container` is necessary if you put query builder
192192

193193
### `Utils`
194194
- Save, load:
195-
#### getTree (immutableValue) -> Object
195+
#### getTree (immutableValue, light = true) -> Object
196196
Convert query value from internal Immutable format to JS format.
197-
You can use it to save value on backend in `onChange` callback of `<Query>`.
197+
You can use it to save value on backend in `onChange` callback of `<Query>`.
198+
Tip: Use `light = false` in case if you want to store query value in your state in JS format and pass it as `value` of `<Query>` after applying `loadTree()` (which is not recommended because of double conversion). See issue [#190](https://github.com/ukrbublik/react-awesome-query-builder/issues/190)
198199
#### loadTree (jsValue, config) -> Immutable
199200
Convert query value from JS format to internal Immutable format.
200201
You can use it to load saved value from backend and pass as `value` prop to `<Query>` (don't forget to also apply `checkTree()`).
@@ -205,7 +206,7 @@ Wrapping in `div.query-builder-container` is necessary if you put query builder
205206
#### isValidTree (immutableValue) -> Boolean
206207
If `showErrorMessage` in config.settings is true, use this method to check is query has bad values.
207208
- Export:
208-
#### queryString (immutableValue, config, isForDisplay) -> String
209+
#### queryString (immutableValue, config, isForDisplay = false) -> String
209210
Convert query value to custom string representation. `isForDisplay` = true can be used to make string more "human readable".
210211
#### mongodbFormat (immutableValue, config) -> Object
211212
Convert query value to MongoDb query object.

modules/components/Query.jsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,10 @@ export default class QueryContainer extends Component {
127127
}
128128

129129
shouldComponentUpdate = liteShouldComponentUpdate(this, {
130-
value: (nextValue, prevValue, state) => {
131-
const storeValue = state.store.getState().tree;
132-
return !immutableEqual(storeValue, nextValue) && !immutableEqual(prevValue, nextValue);
133-
}
130+
value: (nextValue, prevValue, state) => { return false; }
134131
});
135132

136133
onPropsChanged(nextProps) {
137-
if (this.props.dontDispatchOnNewProps)
138-
return;
139-
140134
// compare configs
141135
const oldConfig = pick(this.props, configKeys);
142136
let nextConfig = pick(nextProps, configKeys);
@@ -145,16 +139,18 @@ export default class QueryContainer extends Component {
145139
nextConfig = extendConfig(nextConfig);
146140
this.setState({config: nextConfig});
147141
}
148-
142+
149143
// compare trees
150144
const storeValue = this.state.store.getState().tree;
151145
const isTreeChanged = !immutableEqual(nextProps.value, this.props.value) && !immutableEqual(nextProps.value, storeValue);
152146
if (isTreeChanged) {
153147
const nextTree = nextProps.value || defaultRoot({ ...nextProps, tree: null });
154148
const validatedTree = validateAndFixTree(nextTree, null, nextConfig, oldConfig);
155-
this.state.store.dispatch(
156-
actions.tree.setTree(nextProps, validatedTree)
157-
);
149+
return Promise.resolve().then(() => {
150+
this.state.store.dispatch(
151+
actions.tree.setTree(nextProps, validatedTree)
152+
);
153+
});
158154
}
159155
}
160156

modules/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export interface Utils {
8989
sqlFormat(tree: ImmutableTree, config: Config): string;
9090
mongodbFormat(tree: ImmutableTree, config: Config): Object;
9191
// load, save
92-
getTree(tree: ImmutableTree): JsonTree;
92+
getTree(tree: ImmutableTree, light?: boolean): JsonTree;
9393
loadTree(jsonTree: JsonTree): ImmutableTree;
9494
checkTree(tree: ImmutableTree, config: Config): ImmutableTree;
9595
isValidTree(tree: ImmutableTree): boolean;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-awesome-query-builder",
3-
"version": "2.1.18",
3+
"version": "2.1.19",
44
"description": "User-friendly query builder for React. Demo: https://ukrbublik.github.io/react-awesome-query-builder",
55
"keywords": [
66
"query-builder",

tests/ChangeQueryProps.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { with_qb, load_tree } from "./utils";
66

77
describe("change props", () => {
88
it("change tree via props triggers onChange", () => {
9-
with_qb(configs.simple_with_2_numbers, inits.with_num_and_num2, "JsonLogic", (qb, onChange, {expect_jlogic}) => {
10-
qb.setProps({
9+
with_qb(configs.simple_with_2_numbers, inits.with_num_and_num2, "JsonLogic", async (qb, onChange, {expect_jlogic}) => {
10+
await qb.setProps({
1111
value: load_tree("JsonLogic", inits.with_number, configs.simple_with_2_numbers(BasicConfig))
1212
});
1313
expect_jlogic([null, inits.with_number]);

0 commit comments

Comments
 (0)