@evoke-platform/ui-components 1.1.0-testing.1 → 1.1.0-testing.3
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.
- package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.d.ts +4 -5
- package/dist/published/components/custom/CriteriaBuilder/CriteriaBuilder.js +32 -22
- package/dist/published/components/custom/CriteriaBuilder/ValueEditor.js +25 -4
- package/dist/published/index.d.ts +5 -3
- package/dist/published/index.js +4 -2
- package/package.json +1 -7
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
/// <reference types="react" />
|
2
2
|
import 'react-querybuilder/dist/query-builder.css';
|
3
3
|
import { EvokeObject } from '../../../types';
|
4
4
|
import { ObjectProperty, Operator, PresetValue, TreeViewObject } from './types';
|
@@ -10,10 +10,9 @@ export type CriteriaInputProps = {
|
|
10
10
|
originalCriteria?: Record<string, unknown>;
|
11
11
|
enablePresetValues?: boolean;
|
12
12
|
presetValues?: PresetValue[];
|
13
|
-
|
14
|
-
component:
|
15
|
-
|
16
|
-
trigger?: Record<string, unknown>;
|
13
|
+
customValueEditor?: {
|
14
|
+
component: (props: ValueEditorProps) => JSX.Element;
|
15
|
+
props?: Record<string, unknown>;
|
17
16
|
};
|
18
17
|
operators?: Operator[];
|
19
18
|
disabledCriteria?: {
|
@@ -212,7 +212,10 @@ const customSelector = (props) => {
|
|
212
212
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
213
213
|
onChange: (event, newValue) => {
|
214
214
|
handleOnChange(newValue?.value.name);
|
215
|
-
}, renderInput: (params) => React.createElement(TextField, { ...params, placeholder: placeholder, size: "small"
|
215
|
+
}, renderInput: (params) => (React.createElement(TextField, { ...params, placeholder: placeholder, size: "small", inputProps: {
|
216
|
+
...params.inputProps,
|
217
|
+
'aria-label': placeholder,
|
218
|
+
} })), sx: { width: width, background: '#fff' }, disableClearable: true, readOnly: readOnly }))));
|
216
219
|
};
|
217
220
|
const customCombinator = (props) => {
|
218
221
|
const { value, handleOnChange, context, level, path } = props;
|
@@ -277,7 +280,7 @@ export const valueEditor = (props) => {
|
|
277
280
|
return ValueEditor(props);
|
278
281
|
};
|
279
282
|
const CriteriaBuilder = (props) => {
|
280
|
-
const { properties, criteria, setCriteria, originalCriteria, enablePresetValues, presetValues, operators,
|
283
|
+
const { properties, criteria, setCriteria, originalCriteria, enablePresetValues, presetValues, operators, disabled, disabledCriteria, hideBorder, presetGroupLabel, customValueEditor, treeViewOpts, disableRegexEscapeChars, } = props;
|
281
284
|
const [query, setQuery] = useState(undefined);
|
282
285
|
const [propertyTreeMap, setPropertyTreeMap] = useState();
|
283
286
|
useEffect(() => {
|
@@ -287,33 +290,40 @@ const CriteriaBuilder = (props) => {
|
|
287
290
|
!isEmpty(treeViewOpts) && updatePropertyTreeMap(updatedQuery);
|
288
291
|
setQuery({
|
289
292
|
...updatedQuery,
|
290
|
-
rules: processRules(updatedQuery.rules),
|
293
|
+
rules: processRules(updatedQuery.rules, true),
|
291
294
|
});
|
292
295
|
}
|
293
296
|
else {
|
294
297
|
setQuery({ combinator: 'and', rules: [] });
|
295
298
|
}
|
296
299
|
}, [originalCriteria]);
|
297
|
-
|
300
|
+
const processRules = (rules, isSavedValue) => {
|
298
301
|
return rules.map((rule) => {
|
299
302
|
if ('rules' in rule) {
|
300
303
|
return {
|
301
304
|
...rule,
|
302
|
-
rules: processRules(rule.rules),
|
305
|
+
rules: processRules(rule.rules, isSavedValue),
|
303
306
|
};
|
304
307
|
}
|
305
308
|
else {
|
306
309
|
const propertyType = properties.find((property) => property.id === rule.field)?.type;
|
310
|
+
let adjustedValue = rule.value;
|
311
|
+
if ((propertyType === 'array' ||
|
312
|
+
(propertyType === 'string' && (rule.operator === 'in' || rule.operator === 'notIn'))) &&
|
313
|
+
isSavedValue) {
|
314
|
+
adjustedValue = rule.value.split(',');
|
315
|
+
}
|
316
|
+
else if ((rule.operator === 'null' || rule.operator === 'notNull') && rule.value) {
|
317
|
+
adjustedValue = null;
|
318
|
+
}
|
307
319
|
return {
|
308
320
|
...rule,
|
309
|
-
|
310
|
-
|
311
|
-
? rule.value?.split(',')
|
312
|
-
: rule.value,
|
321
|
+
operator: propertyType === 'array' && rule.operator === '=' ? 'in' : rule.operator,
|
322
|
+
value: adjustedValue,
|
313
323
|
};
|
314
324
|
}
|
315
325
|
});
|
316
|
-
}
|
326
|
+
};
|
317
327
|
// this retrieves the properties from a treeview for each property in the query
|
318
328
|
// they are then used in the custom query builder components to determine the input type etc
|
319
329
|
const updatePropertyTreeMap = (q) => {
|
@@ -358,8 +368,12 @@ const CriteriaBuilder = (props) => {
|
|
358
368
|
}
|
359
369
|
};
|
360
370
|
const handleQueryChange = (q) => {
|
361
|
-
|
362
|
-
|
371
|
+
const processedQuery = {
|
372
|
+
...q,
|
373
|
+
rules: processRules(q.rules, false),
|
374
|
+
};
|
375
|
+
setQuery(processedQuery);
|
376
|
+
const newCriteria = JSON.parse(formatQuery(processedQuery, {
|
363
377
|
format: 'mongodb',
|
364
378
|
ruleProcessor: (rule, options) => {
|
365
379
|
let newRule = rule;
|
@@ -375,16 +389,12 @@ const CriteriaBuilder = (props) => {
|
|
375
389
|
return defaultRuleProcessorMongoDB(newRule, options);
|
376
390
|
},
|
377
391
|
}));
|
378
|
-
|
379
|
-
|
380
|
-
// since the Add Condition / Add Group buttons add rules with all the fields empty,
|
381
|
-
// we need to check if the first rule was added because q will still parse to { $and: [{ $expr: true }] }
|
382
|
-
const firstRuleAdded = isEmpty(criteria) && q.rules.length > 0;
|
383
|
-
if (allRulesDeleted && !firstRuleAdded) {
|
384
|
-
setCriteria(undefined);
|
392
|
+
if (!isEmpty(difference(newCriteria, { $and: [{ $expr: true }] }))) {
|
393
|
+
setCriteria(newCriteria);
|
385
394
|
}
|
386
395
|
else {
|
387
|
-
|
396
|
+
if (q.rules.length === 0)
|
397
|
+
setCriteria(undefined);
|
388
398
|
}
|
389
399
|
};
|
390
400
|
const fields = useMemo(() => {
|
@@ -487,9 +497,9 @@ const CriteriaBuilder = (props) => {
|
|
487
497
|
ruleGroup: CustomRuleGroup,
|
488
498
|
removeGroupAction: customDelete,
|
489
499
|
removeRuleAction: customDelete,
|
490
|
-
valueEditor: valueEditor,
|
500
|
+
valueEditor: customValueEditor ? customValueEditor.component : valueEditor,
|
491
501
|
}, context: {
|
492
|
-
|
502
|
+
...(customValueEditor?.props ?? {}),
|
493
503
|
presetValues,
|
494
504
|
enablePresetValues,
|
495
505
|
presetGroupLabel,
|
@@ -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('');
|
@@ -1,11 +1,13 @@
|
|
1
|
-
export { ClickAwayListener,
|
1
|
+
export { ClickAwayListener, createTheme, darken, lighten, styled, Toolbar } from '@mui/material';
|
2
2
|
export { CalendarPicker, DateTimePicker, MonthPicker, PickersDay, StaticDateTimePicker, StaticTimePicker, TimePicker, YearPicker, } from '@mui/x-date-pickers';
|
3
|
+
export * from './colors';
|
3
4
|
export * from './components/core';
|
4
|
-
export { BuilderGrid, CriteriaBuilder, DataGrid, ErrorComponent, Form, FormField, MenuBar, MultiSelect, RepeatableField,
|
5
|
+
export { BuilderGrid, CriteriaBuilder, DataGrid, ErrorComponent, Form, FormField, HistoryLog, MenuBar, MultiSelect, RepeatableField, RichTextViewer, UserAvatar, } from './components/custom';
|
6
|
+
export { NumericFormat } from './components/custom/FormField/InputFieldComponent';
|
5
7
|
export { Box, Container, Grid, Stack } from './components/layout';
|
6
8
|
export * as EVOKE_TYPES from './types';
|
7
9
|
export * from './util';
|
8
|
-
export type { ButtonBaseActions, ButtonBaseClasses, FormControlProps, FormHelperTextProps, GridSize, MenuItemClasses, Theme, } from '@mui/material';
|
10
|
+
export type { AutocompleteRenderGroupParams, ButtonBaseActions, ButtonBaseClasses, FormControlProps, FormHelperTextProps, GridSize, MenuItemClasses, TextFieldProps, Theme, } from '@mui/material';
|
9
11
|
export type { TouchRippleActions, TouchRippleProps } from '@mui/material/ButtonBase/TouchRipple';
|
10
12
|
export type { CommonProps } from '@mui/material/OverridableComponent';
|
11
13
|
export type { SxProps } from '@mui/system';
|
package/dist/published/index.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
export { ClickAwayListener,
|
1
|
+
export { ClickAwayListener, createTheme, darken, lighten, styled, Toolbar } from '@mui/material';
|
2
2
|
export { CalendarPicker, DateTimePicker, MonthPicker, PickersDay, StaticDateTimePicker, StaticTimePicker, TimePicker, YearPicker, } from '@mui/x-date-pickers';
|
3
|
+
export * from './colors';
|
3
4
|
export * from './components/core';
|
4
|
-
export { BuilderGrid, CriteriaBuilder, DataGrid, ErrorComponent, Form, FormField, MenuBar, MultiSelect, RepeatableField,
|
5
|
+
export { BuilderGrid, CriteriaBuilder, DataGrid, ErrorComponent, Form, FormField, HistoryLog, MenuBar, MultiSelect, RepeatableField, RichTextViewer, UserAvatar, } from './components/custom';
|
6
|
+
export { NumericFormat } from './components/custom/FormField/InputFieldComponent';
|
5
7
|
export { Box, Container, Grid, Stack } from './components/layout';
|
6
8
|
export * as EVOKE_TYPES from './types';
|
7
9
|
export * from './util';
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@evoke-platform/ui-components",
|
3
|
-
"version": "1.1.0-testing.
|
3
|
+
"version": "1.1.0-testing.3",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/published/index.js",
|
6
6
|
"module": "dist/published/index.js",
|
@@ -135,12 +135,6 @@
|
|
135
135
|
"npm run lint:fix"
|
136
136
|
]
|
137
137
|
},
|
138
|
-
"husky": {
|
139
|
-
"hooks": {
|
140
|
-
"pre-commit": "npx lint-staged",
|
141
|
-
"commit-msg": "npx commitlint --edit $1"
|
142
|
-
}
|
143
|
-
},
|
144
138
|
"jest": {
|
145
139
|
"verbose": true,
|
146
140
|
"testEnvironment": "jsdom",
|