@evoke-platform/ui-components 1.1.0-testing.0 → 1.1.0-testing.1

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.
@@ -3,7 +3,7 @@ import { Typography } from '@mui/material';
3
3
  import { QueryBuilderMaterial } from '@react-querybuilder/material';
4
4
  import { isArray, isEmpty, startCase } from 'lodash';
5
5
  import React, { useEffect, useMemo, useState } from 'react';
6
- import { QueryBuilder, RuleGroupBodyComponents, RuleGroupHeaderComponents, TestID, defaultRuleProcessorMongoDB, formatQuery, useRuleGroup, } from 'react-querybuilder';
6
+ import { QueryBuilder, RuleGroupBodyComponents, RuleGroupHeaderComponents, TestID, add, defaultRuleProcessorMongoDB, formatQuery, useRuleGroup, } from 'react-querybuilder';
7
7
  import 'react-querybuilder/dist/query-builder.css';
8
8
  import escape from 'string-escape-regex';
9
9
  import { TrashCan } from '../../../icons/custom';
@@ -28,6 +28,14 @@ const ALL_OPERATORS = [
28
28
  { name: 'in', label: 'In' },
29
29
  { name: 'notIn', label: 'Not in' },
30
30
  ];
31
+ const styles = {
32
+ buttons: {
33
+ padding: '6px 16px',
34
+ fontSize: '0.875rem',
35
+ marginRight: '0px',
36
+ boxShadow: 'none',
37
+ },
38
+ };
31
39
  const CustomRuleGroup = (props) => {
32
40
  const rg = { ...props, ...useRuleGroup(props) };
33
41
  const [addRule, addGroup, cloneGroup, toggleLockGroup, removeGroup] = [
@@ -73,11 +81,8 @@ const customButton = (props) => {
73
81
  case 'Add rule':
74
82
  buttonLabel = 'Add Condition';
75
83
  break;
76
- case 'Remove group':
77
- buttonLabel = 'Clear All';
78
- break;
79
84
  }
80
- return (React.createElement(React.Fragment, null, (path.length < nestedConditionLimit || title === 'Add rule') && (React.createElement(Button, { onClick: handleOnClick, startIcon: React.createElement(AddRounded, null), sx: {
85
+ return (React.createElement(React.Fragment, null, !!path.length && (path.length < nestedConditionLimit || title === 'Add rule') && (React.createElement(Button, { onClick: handleOnClick, startIcon: React.createElement(AddRounded, null), sx: {
81
86
  padding: '6px 16px',
82
87
  fontSize: '0.875rem',
83
88
  marginRight: path.length === 0 ? '.5rem' : '0px',
@@ -334,6 +339,24 @@ const CriteriaBuilder = (props) => {
334
339
  setPropertyTreeMap(tempPropertyMap);
335
340
  });
336
341
  };
342
+ const handleClearAll = () => {
343
+ handleQueryChange({ combinator: 'and', rules: [] });
344
+ };
345
+ const handleAddRule = () => {
346
+ if (query) {
347
+ const newQuery = add(query, { field: '', operator: '', value: '' }, []);
348
+ setQuery(newQuery);
349
+ }
350
+ };
351
+ const handleAddGroup = () => {
352
+ if (query) {
353
+ const newQuery = add(query, {
354
+ combinator: 'and',
355
+ rules: [{ field: '', operator: '', value: '' }],
356
+ }, []);
357
+ setQuery(newQuery);
358
+ }
359
+ };
337
360
  const handleQueryChange = (q) => {
338
361
  setQuery(q);
339
362
  const newCriteria = JSON.parse(formatQuery(q, {
@@ -405,6 +428,7 @@ const CriteriaBuilder = (props) => {
405
428
  borderStyle: 'hidden',
406
429
  background: '#fff',
407
430
  maxWidth: '70vw',
431
+ margin: 'auto',
408
432
  },
409
433
  '.ruleGroup-header': {
410
434
  display: 'block',
@@ -424,7 +448,9 @@ const CriteriaBuilder = (props) => {
424
448
  '.ruleGroup .ruleGroup': { borderStyle: 'solid' },
425
449
  } },
426
450
  React.createElement(QueryBuilderMaterial, null,
427
- React.createElement(QueryBuilder, { query: !criteria && !originalCriteria ? { combinator: 'and', rules: [] } : query, fields: fields, onQueryChange: (q) => {
451
+ React.createElement(QueryBuilder, { query: !criteria && !originalCriteria && query.rules.length === 0
452
+ ? { combinator: 'and', rules: [] }
453
+ : query, fields: fields, onQueryChange: (q) => {
428
454
  handleQueryChange(q);
429
455
  }, onAddRule: (rule) => {
430
456
  // overrides new rule and sets up an empty rule with all three fields empty
@@ -483,7 +509,45 @@ const CriteriaBuilder = (props) => {
483
509
  ruleGroup: 'container',
484
510
  }, operators: operators
485
511
  ? ALL_OPERATORS.filter((o) => operators.includes(o.name))
486
- : ALL_OPERATORS }))));
512
+ : ALL_OPERATORS })),
513
+ React.createElement(Box, { sx: {
514
+ display: 'flex',
515
+ justifyContent: 'space-between',
516
+ alignItems: 'center',
517
+ marginBottom: '10px',
518
+ maxWidth: '71vw',
519
+ marginLeft: 'auto',
520
+ marginRight: 'auto',
521
+ } },
522
+ React.createElement(Box, null,
523
+ React.createElement(Button, { sx: {
524
+ backgroundColor: 'rgba(0, 117, 167, 0.08)',
525
+ color: '#0075A7',
526
+ marginLeft: '10px',
527
+ '&:hover': {
528
+ backgroundColor: 'rgba(0, 117, 167, 0.08)',
529
+ },
530
+ ...styles.buttons,
531
+ }, startIcon: React.createElement(AddRounded, null), onClick: handleAddRule }, "Add Condition"),
532
+ React.createElement(Button, { sx: {
533
+ backgroundColor: '#f6f7f8',
534
+ color: '#000',
535
+ marginLeft: '8px',
536
+ '&:hover': {
537
+ backgroundColor: '#f6f7f8',
538
+ },
539
+ ...styles.buttons,
540
+ }, startIcon: React.createElement(AddRounded, null), onClick: handleAddGroup, title: "Add a rule at the bottom of the group" }, "Add Condition Group")),
541
+ React.createElement(Button, { variant: 'text', sx: {
542
+ justifyContent: 'flex-end',
543
+ color: '#000',
544
+ fontWeight: 500,
545
+ paddingLeft: '0px',
546
+ '&:hover': {
547
+ backgroundColor: 'transparent',
548
+ },
549
+ ...styles.buttons,
550
+ }, onClick: handleClearAll, title: "Clear all conditions", disabled: isEmpty(query.rules) }, "Clear All"))));
487
551
  }
488
552
  return React.createElement(React.Fragment, null);
489
553
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.1.0-testing.0",
3
+ "version": "1.1.0-testing.1",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",