@irontec/ivoz-ui 1.7.14 → 1.7.16

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.
@@ -6,9 +6,11 @@ import { memo, useEffect, useMemo, useState } from 'react';
6
6
  import { LightButton, TonalButton, } from '../../../../components/shared/Button/Button.styles';
7
7
  import { isPropertyFk, isPropertyScalar, } from '../../../../services/api/ParsedApiSpecInterface';
8
8
  import { StyledDropdown } from '../../../../services/form/Field/Dropdown/Dropdown.styles';
9
+ import { StyledDynamicAutocomplete } from '../../../../services/form/Field/DynamicAutocomplete/DynamicAutocomplete.styles';
9
10
  import { StyledTextField } from '../../../../services/form/Field/TextField/TextField.styles';
10
11
  import _ from '../../../../services/translations/translate';
11
12
  import FilterIconFactory from '../icons/FilterIconFactory';
13
+ import StoreContainer from '../../../../store/StoreContainer';
12
14
  const StyledDropdownMemo = memo(StyledDropdown, (prev, next) => {
13
15
  return prev.value === next.value;
14
16
  });
@@ -36,19 +38,50 @@ export default function ContentFilterRow(props) {
36
38
  setValue(row.value);
37
39
  }, [row]);
38
40
  const column = columns[name];
39
- let enumValue = null;
40
- if (isPropertyFk(column)) {
41
- enumValue = fkChoices[name] || {};
42
- }
43
- else if (column.enum) {
44
- enumValue = column.enum;
45
- }
46
- else if (column.type === 'boolean') {
47
- enumValue = {
48
- true: _('True'),
49
- false: _('False'),
41
+ const [selectOptions, setSelectOptions] = useState(null);
42
+ const { useDynamicAutocomplete, entityName, enumValue } = useMemo(() => {
43
+ var _a;
44
+ let enumVal = null;
45
+ let useDynamic = false;
46
+ let entName = '';
47
+ if (isPropertyFk(column)) {
48
+ const entities = StoreContainer.store.getState().entities.entities;
49
+ entName = ((_a = column.$ref) === null || _a === void 0 ? void 0 : _a.replace('#/definitions/', '')) || '';
50
+ const entity = entities === null || entities === void 0 ? void 0 : entities[entName];
51
+ if (entity === null || entity === void 0 ? void 0 : entity.dynamicSelectOptions) {
52
+ useDynamic = true;
53
+ }
54
+ else {
55
+ enumVal = fkChoices[name] || {};
56
+ }
57
+ }
58
+ else if (column.enum) {
59
+ enumVal = column.enum;
60
+ }
61
+ else if (column.type === 'boolean') {
62
+ enumVal = {
63
+ true: _('True'),
64
+ false: _('False'),
65
+ };
66
+ }
67
+ return {
68
+ useDynamicAutocomplete: useDynamic,
69
+ entityName: entName,
70
+ enumValue: enumVal,
50
71
  };
51
- }
72
+ }, [column, name, fkChoices]);
73
+ useEffect(() => {
74
+ if (!useDynamicAutocomplete || !entityName) {
75
+ return;
76
+ }
77
+ const entities = StoreContainer.store.getState().entities.entities;
78
+ const entity = entities === null || entities === void 0 ? void 0 : entities[entityName];
79
+ if (entity === null || entity === void 0 ? void 0 : entity.selectOptions) {
80
+ entity.selectOptions().then((handler) => {
81
+ setSelectOptions(() => handler);
82
+ });
83
+ }
84
+ }, [useDynamicAutocomplete, entityName]);
52
85
  const columnFormat = isPropertyScalar(column) && column.format;
53
86
  let textFieldInputType = 'text';
54
87
  const inputProps = {};
@@ -81,13 +114,17 @@ export default function ContentFilterRow(props) {
81
114
  setType(target.value);
82
115
  }, onBlur: () => {
83
116
  /* noop */
84
- }, choices: filterChoices, error: false, errorMsg: '', hasChanged: false }), type !== 'exists' && !enumValue && (_jsx(StyledTextField, { name: 'value', value: value, type: textFieldInputType, error: false, errorMsg: '', inputProps: inputProps, InputProps: {}, hasChanged: false, onChange: ({ target }) => {
117
+ }, choices: filterChoices, error: false, errorMsg: '', hasChanged: false }), type !== 'exists' && !enumValue && !useDynamicAutocomplete && (_jsx(StyledTextField, { name: 'value', value: value, type: textFieldInputType, error: false, errorMsg: '', inputProps: inputProps, InputProps: {}, hasChanged: false, onChange: ({ target }) => {
85
118
  let { value } = target;
86
119
  if (textFieldInputType === 'datetime-local') {
87
120
  value = value.replace('T', ' ');
88
121
  }
89
122
  setValue(value);
90
- } })), type !== 'exists' && enumValue && (_jsx(StyledDropdown, { name: 'value', label: '', value: value, required: false, disabled: false, onChange: ({ target }) => {
123
+ } })), type !== 'exists' && useDynamicAutocomplete && selectOptions && (_jsx(StyledDynamicAutocomplete, { name: 'value', label: '', value: value, choices: {}, multiple: false, required: false, disabled: false, onChange: ({ target }) => {
124
+ setValue(target.value);
125
+ }, onBlur: () => {
126
+ /* noop */
127
+ }, selectOptions: selectOptions, error: false, errorMsg: '', hasChanged: false })), type !== 'exists' && enumValue && !useDynamicAutocomplete && (_jsx(StyledDropdown, { name: 'value', label: '', value: value, required: false, disabled: false, onChange: ({ target }) => {
91
128
  setValue(target.value);
92
129
  }, onBlur: () => {
93
130
  /* noop */
@@ -5,6 +5,10 @@ export const StyledContentFilterRow = styled(ContentFilterRow)(({ theme }) => {
5
5
  display: 'flex',
6
6
  alignItems: 'center',
7
7
  gap: 'var(--spacing-md)',
8
+ '& > *:not(button)': {
9
+ flex: 1,
10
+ minWidth: 0,
11
+ },
8
12
  [theme.breakpoints.down('md')]: {
9
13
  flexDirection: 'column',
10
14
  gap: 'var(--spacing-sm)',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@irontec/ivoz-ui",
3
- "version": "1.7.14",
3
+ "version": "1.7.16",
4
4
  "description": "UI library used in ivozprovider",
5
5
  "license": "GPL-3.0",
6
6
  "main": "index.js",
@@ -25,7 +25,11 @@ const DynamicAutocomplete = (props) => {
25
25
  const [loading, setLoading] = useState(false);
26
26
  const [currentOption, setCurrentOption] = useState(nullOptionObject);
27
27
  const debounceTimeoutRef = useRef();
28
+ const loadedValuesRef = useRef(new Set());
28
29
  useEffect(() => {
30
+ if (selectOptions && Object.keys(choices).length === 0) {
31
+ return;
32
+ }
29
33
  if (Array.isArray(choices)) {
30
34
  setArrayChoices(choices);
31
35
  return;
@@ -41,25 +45,27 @@ const DynamicAutocomplete = (props) => {
41
45
  if (nullValue) {
42
46
  return;
43
47
  }
44
- if (!choices) {
48
+ if (!selectOptions) {
45
49
  return;
46
50
  }
47
- const choicesIncludesValue = Array.isArray(choices)
48
- ? choices.some((item) => item.id === value)
49
- : choices && value in choices;
50
- if (choicesIncludesValue) {
51
+ if (loadedValuesRef.current.has(value)) {
51
52
  return;
52
53
  }
53
- selectOptions === null || selectOptions === void 0 ? void 0 : selectOptions({
54
+ loadedValuesRef.current.add(value);
55
+ selectOptions({
54
56
  callback: (options) => {
55
57
  const option = options[0];
56
- arrayChoices.push(option);
57
- setArrayChoices(arrayChoices);
58
+ if (option) {
59
+ setArrayChoices((prev) => {
60
+ const exists = prev.some((item) => item.id == option.id);
61
+ return exists ? prev : [...prev, option];
62
+ });
63
+ }
58
64
  },
59
65
  }, {
60
66
  id: value,
61
67
  });
62
- }, []);
68
+ }, [value, selectOptions]);
63
69
  const setOptions = useCallback((options) => {
64
70
  const isCurrentOptionIncluded = options.some((option) => option.id == (currentOption === null || currentOption === void 0 ? void 0 : currentOption.id));
65
71
  if (!isCurrentOptionIncluded &&
@@ -209,7 +215,7 @@ const DynamicAutocomplete = (props) => {
209
215
  const disableClearable = arrayChoices.find((item) => item.id === '__null__')
210
216
  ? false
211
217
  : true;
212
- const safeValue = arrayChoices.find((item) => item.id === value)
218
+ const safeValue = arrayChoices.find((item) => item.id == value)
213
219
  ? value
214
220
  : null;
215
221
  return (_jsx(MuiAutocomplete, { className: 'dynamic-autocomplete' + className, value: safeValue, multiple: multiple, disabled: disabled, disableClearable: disableClearable, onChange: onChangeWrapper, onBlur: onBlur, onInputChange: handleInputChange, options: arrayChoices !== null && arrayChoices !== void 0 ? arrayChoices : [], getOptionLabel: getOptionLabel, isOptionEqualToValue: isOptionEqualToValue, loading: loading, placeholder: props.placeholder, renderInput: renderInput, PaperComponent: CustomOption, renderOption: (props, option) => (_jsx(Box, Object.assign({ component: 'li', className: 'autocomplete-option', "data-value": option.id }, props, { children: option.label }))) }));
@@ -103,6 +103,7 @@ export const StyledAutocompleteTextField = styled(StyledTextField)(() => {
103
103
  return {
104
104
  '& .input-field': {
105
105
  paddingLeft: '9px',
106
+ maxHeight: '25px',
106
107
  },
107
108
  };
108
109
  });