@evoke-platform/ui-components 1.0.0-dev.249 → 1.0.0-dev.251

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;
@@ -182,14 +182,14 @@ export function parseMongoDB(mongoQuery) {
182
182
  }
183
183
  else if (typeof value.$regex === 'string') {
184
184
  let operator = 'contains';
185
- const regexValue = value.$regex;
185
+ let regexValue = value.$regex;
186
186
  if (regexValue.startsWith('^')) {
187
187
  operator = 'beginsWith';
188
- regexValue.slice(1);
188
+ regexValue = regexValue.slice(1);
189
189
  }
190
190
  else if (regexValue.endsWith('$')) {
191
191
  operator = 'endsWith';
192
- regexValue.slice(0, -1);
192
+ regexValue = regexValue.slice(0, -1);
193
193
  }
194
194
  return {
195
195
  field: key,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.0.0-dev.249",
3
+ "version": "1.0.0-dev.251",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",