@evoke-platform/ui-components 1.1.0-testing.0 → 1.1.0-testing.2
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',
|
@@ -282,29 +287,36 @@ const CriteriaBuilder = (props) => {
|
|
282
287
|
!isEmpty(treeViewOpts) && updatePropertyTreeMap(updatedQuery);
|
283
288
|
setQuery({
|
284
289
|
...updatedQuery,
|
285
|
-
rules: processRules(updatedQuery.rules),
|
290
|
+
rules: processRules(updatedQuery.rules, true),
|
286
291
|
});
|
287
292
|
}
|
288
293
|
else {
|
289
294
|
setQuery({ combinator: 'and', rules: [] });
|
290
295
|
}
|
291
296
|
}, [originalCriteria]);
|
292
|
-
function processRules(rules) {
|
297
|
+
function processRules(rules, isSavedValue) {
|
293
298
|
return rules.map((rule) => {
|
294
299
|
if ('rules' in rule) {
|
295
300
|
return {
|
296
301
|
...rule,
|
297
|
-
rules: processRules(rule.rules),
|
302
|
+
rules: processRules(rule.rules, isSavedValue),
|
298
303
|
};
|
299
304
|
}
|
300
305
|
else {
|
301
306
|
const propertyType = properties.find((property) => property.id === rule.field)?.type;
|
307
|
+
let adjustedValue = rule.value;
|
308
|
+
if ((propertyType === 'array' ||
|
309
|
+
(propertyType === 'string' && (rule.operator === 'in' || rule.operator === 'notIn'))) &&
|
310
|
+
isSavedValue) {
|
311
|
+
adjustedValue = rule.value.split(',');
|
312
|
+
}
|
313
|
+
else if ((rule.operator === 'null' || rule.operator === 'notNull') && rule.value) {
|
314
|
+
adjustedValue = null;
|
315
|
+
}
|
302
316
|
return {
|
303
317
|
...rule,
|
304
|
-
|
305
|
-
|
306
|
-
? rule.value?.split(',')
|
307
|
-
: rule.value,
|
318
|
+
operator: propertyType === 'array' && rule.operator === '=' ? 'in' : rule.operator,
|
319
|
+
value: adjustedValue,
|
308
320
|
};
|
309
321
|
}
|
310
322
|
});
|
@@ -334,9 +346,31 @@ const CriteriaBuilder = (props) => {
|
|
334
346
|
setPropertyTreeMap(tempPropertyMap);
|
335
347
|
});
|
336
348
|
};
|
349
|
+
const handleClearAll = () => {
|
350
|
+
handleQueryChange({ combinator: 'and', rules: [] });
|
351
|
+
};
|
352
|
+
const handleAddRule = () => {
|
353
|
+
if (query) {
|
354
|
+
const newQuery = add(query, { field: '', operator: '', value: '' }, []);
|
355
|
+
setQuery(newQuery);
|
356
|
+
}
|
357
|
+
};
|
358
|
+
const handleAddGroup = () => {
|
359
|
+
if (query) {
|
360
|
+
const newQuery = add(query, {
|
361
|
+
combinator: 'and',
|
362
|
+
rules: [{ field: '', operator: '', value: '' }],
|
363
|
+
}, []);
|
364
|
+
setQuery(newQuery);
|
365
|
+
}
|
366
|
+
};
|
337
367
|
const handleQueryChange = (q) => {
|
338
|
-
|
339
|
-
|
368
|
+
const processedQuery = {
|
369
|
+
...q,
|
370
|
+
rules: processRules(q.rules, false),
|
371
|
+
};
|
372
|
+
setQuery(processedQuery);
|
373
|
+
const newCriteria = JSON.parse(formatQuery(processedQuery, {
|
340
374
|
format: 'mongodb',
|
341
375
|
ruleProcessor: (rule, options) => {
|
342
376
|
let newRule = rule;
|
@@ -405,6 +439,7 @@ const CriteriaBuilder = (props) => {
|
|
405
439
|
borderStyle: 'hidden',
|
406
440
|
background: '#fff',
|
407
441
|
maxWidth: '70vw',
|
442
|
+
margin: 'auto',
|
408
443
|
},
|
409
444
|
'.ruleGroup-header': {
|
410
445
|
display: 'block',
|
@@ -424,7 +459,9 @@ const CriteriaBuilder = (props) => {
|
|
424
459
|
'.ruleGroup .ruleGroup': { borderStyle: 'solid' },
|
425
460
|
} },
|
426
461
|
React.createElement(QueryBuilderMaterial, null,
|
427
|
-
React.createElement(QueryBuilder, { query: !criteria && !originalCriteria
|
462
|
+
React.createElement(QueryBuilder, { query: !criteria && !originalCriteria && query.rules.length === 0
|
463
|
+
? { combinator: 'and', rules: [] }
|
464
|
+
: query, fields: fields, onQueryChange: (q) => {
|
428
465
|
handleQueryChange(q);
|
429
466
|
}, onAddRule: (rule) => {
|
430
467
|
// overrides new rule and sets up an empty rule with all three fields empty
|
@@ -483,7 +520,45 @@ const CriteriaBuilder = (props) => {
|
|
483
520
|
ruleGroup: 'container',
|
484
521
|
}, operators: operators
|
485
522
|
? ALL_OPERATORS.filter((o) => operators.includes(o.name))
|
486
|
-
: ALL_OPERATORS }))
|
523
|
+
: ALL_OPERATORS })),
|
524
|
+
React.createElement(Box, { sx: {
|
525
|
+
display: 'flex',
|
526
|
+
justifyContent: 'space-between',
|
527
|
+
alignItems: 'center',
|
528
|
+
marginBottom: '10px',
|
529
|
+
maxWidth: '71vw',
|
530
|
+
marginLeft: 'auto',
|
531
|
+
marginRight: 'auto',
|
532
|
+
} },
|
533
|
+
React.createElement(Box, null,
|
534
|
+
React.createElement(Button, { sx: {
|
535
|
+
backgroundColor: 'rgba(0, 117, 167, 0.08)',
|
536
|
+
color: '#0075A7',
|
537
|
+
marginLeft: '10px',
|
538
|
+
'&:hover': {
|
539
|
+
backgroundColor: 'rgba(0, 117, 167, 0.08)',
|
540
|
+
},
|
541
|
+
...styles.buttons,
|
542
|
+
}, startIcon: React.createElement(AddRounded, null), onClick: handleAddRule }, "Add Condition"),
|
543
|
+
React.createElement(Button, { sx: {
|
544
|
+
backgroundColor: '#f6f7f8',
|
545
|
+
color: '#000',
|
546
|
+
marginLeft: '8px',
|
547
|
+
'&:hover': {
|
548
|
+
backgroundColor: '#f6f7f8',
|
549
|
+
},
|
550
|
+
...styles.buttons,
|
551
|
+
}, startIcon: React.createElement(AddRounded, null), onClick: handleAddGroup, title: "Add a rule at the bottom of the group" }, "Add Condition Group")),
|
552
|
+
React.createElement(Button, { variant: 'text', sx: {
|
553
|
+
justifyContent: 'flex-end',
|
554
|
+
color: '#000',
|
555
|
+
fontWeight: 500,
|
556
|
+
paddingLeft: '0px',
|
557
|
+
'&:hover': {
|
558
|
+
backgroundColor: 'transparent',
|
559
|
+
},
|
560
|
+
...styles.buttons,
|
561
|
+
}, onClick: handleClearAll, title: "Clear all conditions", disabled: isEmpty(query.rules) }, "Clear All"))));
|
487
562
|
}
|
488
563
|
return React.createElement(React.Fragment, null);
|
489
564
|
};
|
@@ -2,7 +2,7 @@ import { Instant, LocalDate, LocalDateTime, LocalTime, ZoneId } from '@js-joda/c
|
|
2
2
|
import { ClearRounded } from '@mui/icons-material';
|
3
3
|
import { Box, darken, lighten, styled } from '@mui/material';
|
4
4
|
import { DateTimePicker, TimePicker } from '@mui/x-date-pickers';
|
5
|
-
import React, { useRef, useState } from 'react';
|
5
|
+
import React, { useEffect, useRef, useState } from 'react';
|
6
6
|
import { Autocomplete, Chip, DatePicker, LocalizationProvider, Menu, MenuItem, TextField, Typography, } from '../../core';
|
7
7
|
import { NumericFormat } from '../FormField/InputFieldComponent';
|
8
8
|
const GroupHeader = styled('div')(({ theme }) => ({
|
@@ -18,7 +18,7 @@ const GroupHeader = styled('div')(({ theme }) => ({
|
|
18
18
|
}));
|
19
19
|
const GroupItems = styled('ul')({ padding: 0 });
|
20
20
|
const ValueEditor = (props) => {
|
21
|
-
const { handleOnChange, value, operator, context, level, rule } = props;
|
21
|
+
const { handleOnChange, value, operator, context, level, rule, fieldData } = props;
|
22
22
|
let inputType = props.inputType;
|
23
23
|
let values = props.values;
|
24
24
|
const property = context.propertyTreeMap?.[rule.field];
|
@@ -43,6 +43,15 @@ const ValueEditor = (props) => {
|
|
43
43
|
const isPresetValueSelected = presetValues && typeof value === 'string' && isPresetValue(value);
|
44
44
|
const presetDisplayValue = presetValues?.find((option) => option.value.name === value)?.label ?? '';
|
45
45
|
let readOnly = false;
|
46
|
+
useEffect(() => {
|
47
|
+
if (!['in', 'notIn'].includes(operator) && Array.isArray(value)) {
|
48
|
+
handleOnChange('');
|
49
|
+
}
|
50
|
+
else if (['in', 'notIn'].includes(operator) && !Array.isArray(value)) {
|
51
|
+
handleOnChange([]);
|
52
|
+
setInputValue('');
|
53
|
+
}
|
54
|
+
}, [operator]);
|
46
55
|
if (context.disabledCriteria) {
|
47
56
|
readOnly =
|
48
57
|
Object.entries(context.disabledCriteria.criteria).some(([key, value]) => key === rule.field && value === rule.value && rule.operator === '=') && level === context.disabledCriteria.level;
|
@@ -147,7 +156,7 @@ const ValueEditor = (props) => {
|
|
147
156
|
...(presetValues?.sort((a, b) => a.label.localeCompare(b.label)) ?? []),
|
148
157
|
];
|
149
158
|
if (isMultiple || values?.length) {
|
150
|
-
return (React.createElement(Autocomplete, { freeSolo: inputType !== 'array' &&
|
159
|
+
return (React.createElement(Autocomplete, { freeSolo: inputType !== 'array' && fieldData.valueEditorType !== 'select', multiple: isMultiple, options: options, value: isMultiple ? (Array.isArray(value) ? value : []) : Array.isArray(value) ? '' : value,
|
151
160
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
152
161
|
onChange: (event, newValue) => {
|
153
162
|
let value;
|
@@ -161,7 +170,19 @@ const ValueEditor = (props) => {
|
|
161
170
|
}
|
162
171
|
handleOnChange(value);
|
163
172
|
}, onBlur: () => {
|
164
|
-
if (inputValue &&
|
173
|
+
if (inputValue &&
|
174
|
+
(options.some((option) => option.name === inputValue) || !options.length) &&
|
175
|
+
(operator === 'in' || operator === 'notIn')) {
|
176
|
+
const newValues = Array.isArray(value) ? [...value, inputValue] : [inputValue];
|
177
|
+
handleOnChange(Array.from(new Set(newValues)));
|
178
|
+
setInputValue('');
|
179
|
+
}
|
180
|
+
}, onKeyDown: (event) => {
|
181
|
+
if (event.key === 'Enter' &&
|
182
|
+
inputValue &&
|
183
|
+
(options.some((option) => option.name === inputValue) || !options.length) &&
|
184
|
+
(operator === 'in' || operator === 'notIn')) {
|
185
|
+
event.preventDefault();
|
165
186
|
const newValues = Array.isArray(value) ? [...value, inputValue] : [inputValue];
|
166
187
|
handleOnChange(Array.from(new Set(newValues)));
|
167
188
|
setInputValue('');
|