@evoke-platform/ui-components 1.0.0-dev.250 → 1.0.0-dev.252

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -328,8 +328,26 @@ const CriteriaBuilder = (props) => {
328
328
  const handleQueryChange = (q) => {
329
329
  setQuery(q);
330
330
  const newCriteria = JSON.parse(formatQuery(q, 'mongodb'));
331
+ //Filters out the empty rules
332
+ const filterEmptyRules = (newCriteria) => {
333
+ let updatedCriteria;
334
+ Object.keys(newCriteria).forEach((key) => {
335
+ updatedCriteria = newCriteria[key];
336
+ if (key === '$and' || key === '$or') {
337
+ if (Array.isArray(updatedCriteria)) {
338
+ newCriteria[key] = updatedCriteria.filter((query) => !isEmpty(difference(query, { $and: [{ $expr: true }] })));
339
+ }
340
+ }
341
+ //If it is an object filter there may be a nested rule
342
+ if (typeof updatedCriteria === 'object') {
343
+ filterEmptyRules(updatedCriteria);
344
+ }
345
+ });
346
+ return newCriteria;
347
+ };
348
+ const filteredCriteria = filterEmptyRules(newCriteria);
331
349
  //when q has no rules, it formats and parses to { $and: [{ $expr: true }] }
332
- const allRulesDeleted = isEmpty(difference(newCriteria, { $and: [{ $expr: true }] }));
350
+ const allRulesDeleted = isEmpty(difference(filteredCriteria, { $and: [{ $expr: true }] }));
333
351
  // since the Add Condition / Add Group buttons add rules with all the fields empty,
334
352
  // we need to check if the first rule was added because q will still parse to { $and: [{ $expr: true }] }
335
353
  const firstRuleAdded = isEmpty(criteria) && q.rules.length > 0;
@@ -35,11 +35,12 @@ export type TreeViewObject = {
35
35
  name: string;
36
36
  properties: TreeViewProperty[];
37
37
  };
38
- export type MongoDBQueryValue = null | string | {
38
+ export type MongoDBQueryValue = null | string | boolean | {
39
39
  $not?: {
40
40
  $regex?: string;
41
41
  };
42
42
  $regex?: string;
43
+ $expr?: boolean;
43
44
  $eq?: unknown;
44
45
  $ne?: unknown;
45
46
  $lt?: unknown;
@@ -159,14 +159,20 @@ export function parseMongoDB(mongoQuery) {
159
159
  * @returns {RuleType | undefined} - A RuleType if the value is valid, otherwise undefined.
160
160
  */
161
161
  const parseRule = (key, value) => {
162
- if (value === null) {
162
+ if (key === '$expr') {
163
+ return undefined;
164
+ }
165
+ else if (value === null) {
163
166
  return {
164
167
  field: key,
165
168
  operator: 'null',
166
169
  value: null,
167
170
  };
168
171
  }
169
- else if (typeof value === 'string' || typeof value === 'number' || '$eq' in value) {
172
+ else if (typeof value === 'string' ||
173
+ typeof value === 'number' ||
174
+ typeof value === 'boolean' ||
175
+ '$eq' in value) {
170
176
  return {
171
177
  field: key,
172
178
  operator: '=',
@@ -260,13 +266,13 @@ export function parseMongoDB(mongoQuery) {
260
266
  if ('$and' in query && isArray(query.$and)) {
261
267
  return {
262
268
  combinator: 'and',
263
- rules: query.$and.map(parseGroup),
269
+ rules: query.$and.map(parseGroup).filter((rule) => rule !== undefined),
264
270
  };
265
271
  }
266
272
  else if ('$or' in query && isArray(query.$or)) {
267
273
  return {
268
274
  combinator: 'or',
269
- rules: query.$or.map(parseGroup),
275
+ rules: query.$or.map(parseGroup).filter((rule) => rule !== undefined),
270
276
  };
271
277
  }
272
278
  else if (isEmpty(query)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.0.0-dev.250",
3
+ "version": "1.0.0-dev.252",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",