impaktapps-jsonforms 5.426.30 → 5.426.31
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { memo, useContext, useEffect, useState } from "react";
|
|
1
|
+
import React, { memo, useContext, useEffect, useState, useMemo } from "react";
|
|
2
2
|
import { Autocomplete, TextField } from "@mui/material";
|
|
3
3
|
import { DataContext } from "../context/Context";
|
|
4
4
|
import ComponentWrapper from "../common/ComponentWrapper";
|
|
@@ -6,6 +6,7 @@ import { getFieldName } from "../permissions/getFieldName";
|
|
|
6
6
|
import { inputProps } from "../interface/inputfieldProps";
|
|
7
7
|
import { getComponentProps } from "../common/getComponentProps";
|
|
8
8
|
import _ from "lodash";
|
|
9
|
+
|
|
9
10
|
export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
10
11
|
props: inputProps | any
|
|
11
12
|
) {
|
|
@@ -20,56 +21,83 @@ export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
|
20
21
|
schema,
|
|
21
22
|
options,
|
|
22
23
|
} = props.props;
|
|
24
|
+
|
|
23
25
|
const uischemaData = uischema?.config?.main;
|
|
24
26
|
const { pageName, permissions, theme, setSchema, serviceProvider } =
|
|
25
27
|
useContext(DataContext);
|
|
26
28
|
const fieldName = getFieldName(path);
|
|
29
|
+
|
|
27
30
|
const [changeState, setChangeState] = useState("");
|
|
28
31
|
const [selectOptions, setSelectOptions] = useState(
|
|
29
32
|
options || uischemaData.options || []
|
|
30
33
|
);
|
|
31
|
-
const [value, setValue] = useState
|
|
34
|
+
const [value, setValue] = useState(uischemaData.multiple ? [] : "");
|
|
35
|
+
|
|
32
36
|
useEffect(() => {
|
|
33
|
-
// const filteredOptions = [];
|
|
34
|
-
// options?.map((e) => {
|
|
35
|
-
// if (uischemaData.multiple) {
|
|
36
|
-
// if (!data?.includes(e?.value)) {
|
|
37
|
-
// filteredOptions.push(e);
|
|
38
|
-
// }
|
|
39
|
-
// } else {
|
|
40
|
-
// if (!(data === e?.value)) {
|
|
41
|
-
// filteredOptions.push(e);
|
|
42
|
-
// }
|
|
43
|
-
// }
|
|
44
|
-
// });
|
|
45
37
|
setSelectOptions(options || []);
|
|
46
38
|
}, [options]);
|
|
39
|
+
|
|
47
40
|
useEffect(() => {
|
|
48
41
|
if (uischemaData.lazyLoading) {
|
|
49
42
|
throttledFunction();
|
|
50
43
|
}
|
|
51
44
|
}, []);
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
updateFreeSoloOptions();
|
|
48
|
+
}, [options, data]);
|
|
49
|
+
|
|
50
|
+
const throttledFunction = useMemo(
|
|
51
|
+
() =>
|
|
52
|
+
throttle((value) => {
|
|
53
|
+
serviceProvider(
|
|
54
|
+
props.ctx,
|
|
55
|
+
{
|
|
56
|
+
...uischemaData,
|
|
57
|
+
onInputChange: uischemaData.lazyLoadFunction || "getSelectOptions",
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
event: { _reactName: "onInputChange" },
|
|
61
|
+
path,
|
|
62
|
+
...uischemaData.additionalData,
|
|
63
|
+
paramValue: {
|
|
64
|
+
path,
|
|
65
|
+
serachValue: value,
|
|
66
|
+
currentValue: data,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
).then((response) => {
|
|
70
|
+
if (response) {
|
|
71
|
+
if (uischemaData.freeSolo) {
|
|
72
|
+
response.push({ const: changeState, title: changeState });
|
|
73
|
+
}
|
|
74
|
+
updateSchema({ options, response, setSchema, path, uischemaData });
|
|
75
|
+
const filteredOptions = response.filter(
|
|
76
|
+
(e) => !data?.includes(e?.const)
|
|
77
|
+
).map((e) => ({ label: e.title, value: e.const }));
|
|
78
|
+
setSelectOptions(filteredOptions);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}, 1000),
|
|
82
|
+
[uischemaData, serviceProvider, data, changeState]
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
function throttle(fn, delay) {
|
|
86
|
+
let timer;
|
|
54
87
|
return function (...args) {
|
|
55
88
|
clearTimeout(timer);
|
|
56
89
|
timer = setTimeout(() => fn(...args), delay);
|
|
57
90
|
};
|
|
58
91
|
}
|
|
59
|
-
|
|
60
|
-
updateFreeSoloOptions();
|
|
61
|
-
}, []);
|
|
92
|
+
|
|
62
93
|
function updateFreeSoloOptions() {
|
|
63
94
|
if (uischemaData.freeSolo && !uischemaData.lazyLoading && data) {
|
|
64
|
-
// let Updatedresponse = [{const:data||"",title:data||""}];
|
|
65
95
|
if (options) {
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
const filterResult = updatedOptions.filter((e) =>
|
|
71
|
-
return e.const === data;
|
|
72
|
-
});
|
|
96
|
+
const updatedOptions = _.cloneDeep(options).map((e) => ({
|
|
97
|
+
const: e.value,
|
|
98
|
+
title: e.label,
|
|
99
|
+
}));
|
|
100
|
+
const filterResult = updatedOptions.filter((e) => e.const === data);
|
|
73
101
|
if (filterResult.length > 0) {
|
|
74
102
|
return;
|
|
75
103
|
}
|
|
@@ -92,42 +120,7 @@ export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
|
92
120
|
}
|
|
93
121
|
}
|
|
94
122
|
}
|
|
95
|
-
|
|
96
|
-
serviceProvider(
|
|
97
|
-
props.ctx,
|
|
98
|
-
{
|
|
99
|
-
...uischemaData,
|
|
100
|
-
onInputChange: uischemaData.lazyLoadFunction || "getSelectOptions",
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
event: { _reactName: "onInputChange" },
|
|
104
|
-
path,
|
|
105
|
-
...uischemaData.additionalData,
|
|
106
|
-
paramValue: {
|
|
107
|
-
path,
|
|
108
|
-
serachValue: value,
|
|
109
|
-
currentValue: data,
|
|
110
|
-
},
|
|
111
|
-
}
|
|
112
|
-
).then((response: any) => {
|
|
113
|
-
if (response) {
|
|
114
|
-
if (uischemaData.freeSolo) {
|
|
115
|
-
response[response.length] = {
|
|
116
|
-
const: changeState,
|
|
117
|
-
title: changeState,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
updateSchema({ options, response, setSchema, path, uischemaData });
|
|
121
|
-
const filteredOptions = [];
|
|
122
|
-
response.map((e) => {
|
|
123
|
-
if (!data?.includes(e?.const)) {
|
|
124
|
-
filteredOptions.push({ label: e.title, value: e.const });
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
setSelectOptions(filteredOptions);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
}, 1000);
|
|
123
|
+
|
|
131
124
|
const findOptions = () => {
|
|
132
125
|
const value = data
|
|
133
126
|
? uischemaData.multiple
|
|
@@ -138,11 +131,13 @@ export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
|
138
131
|
: "";
|
|
139
132
|
setValue(value);
|
|
140
133
|
};
|
|
134
|
+
|
|
141
135
|
useEffect(() => {
|
|
142
136
|
if (options) {
|
|
143
137
|
findOptions();
|
|
144
138
|
}
|
|
145
139
|
}, [options, data]);
|
|
140
|
+
|
|
146
141
|
return (
|
|
147
142
|
<ComponentWrapper
|
|
148
143
|
{...getComponentProps(
|
|
@@ -155,14 +150,10 @@ export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
|
155
150
|
<Autocomplete
|
|
156
151
|
onChange={(event, newValue) => {
|
|
157
152
|
if (uischemaData.multiple) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
path,
|
|
163
|
-
newValue.map((e) => e?.value || e)
|
|
164
|
-
);
|
|
165
|
-
}
|
|
153
|
+
handleChange(
|
|
154
|
+
path,
|
|
155
|
+
newValue.length === 0 ? undefined : newValue.map((e) => e?.value || e)
|
|
156
|
+
);
|
|
166
157
|
} else {
|
|
167
158
|
handleChange(path, newValue === null ? undefined : newValue.value);
|
|
168
159
|
}
|
|
@@ -170,7 +161,7 @@ export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
|
170
161
|
onInputChange={(event, newInputValue) => {
|
|
171
162
|
uischemaData.lazyLoading && throttledFunction(newInputValue);
|
|
172
163
|
}}
|
|
173
|
-
onMouseLeave={
|
|
164
|
+
onMouseLeave={updateFreeSoloOptions}
|
|
174
165
|
placeholder={uischemaData.placeholder}
|
|
175
166
|
sx={{
|
|
176
167
|
...theme.InputFieldStyle,
|
|
@@ -180,59 +171,54 @@ export const ImpaktAppsAutoComplete = memo(function CustomAutoComplete(
|
|
|
180
171
|
color: theme.myTheme.palette.text.input,
|
|
181
172
|
border: `0.5px solid ${theme.myTheme.palette.text.input}`,
|
|
182
173
|
},
|
|
183
|
-
|
|
184
174
|
".MuiAutocomplete-clearIndicator": {
|
|
185
|
-
color: theme.myTheme.palette.text.input,
|
|
175
|
+
color: theme.myTheme.palette.text.input,
|
|
186
176
|
},
|
|
187
177
|
}}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
freeSolo={uischemaData.freeSolo ? true : false}
|
|
191
|
-
multiple={uischemaData.multiple ? true : false}
|
|
178
|
+
freeSolo={uischemaData.freeSolo ?? false}
|
|
179
|
+
multiple={uischemaData.multiple ?? false}
|
|
192
180
|
id="tags-standard"
|
|
193
|
-
options={selectOptions
|
|
181
|
+
options={selectOptions}
|
|
194
182
|
value={value}
|
|
195
|
-
renderInput={(params) =>
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
errors
|
|
202
|
-
?
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
);
|
|
235
|
-
}}
|
|
183
|
+
renderInput={(params) => (
|
|
184
|
+
<TextField
|
|
185
|
+
{...params}
|
|
186
|
+
size={uischemaData?.size ?? "medium"}
|
|
187
|
+
helperText={
|
|
188
|
+
errors
|
|
189
|
+
? errors.includes("pattern")
|
|
190
|
+
? uischemaData?.errorMessage
|
|
191
|
+
: errors
|
|
192
|
+
: uischemaData?.helperText
|
|
193
|
+
}
|
|
194
|
+
error={!!errors}
|
|
195
|
+
sx={{
|
|
196
|
+
...theme.InputFieldStyle,
|
|
197
|
+
fontSize: theme.myTheme.palette.typography.autoCompleteFontSize,
|
|
198
|
+
...uischema?.config?.TextFieldStyle,
|
|
199
|
+
}}
|
|
200
|
+
variant="outlined"
|
|
201
|
+
label={uischemaData?.label}
|
|
202
|
+
disabled={
|
|
203
|
+
getComponentProps(
|
|
204
|
+
`${pageName}:${fieldName}`,
|
|
205
|
+
permissions,
|
|
206
|
+
schema,
|
|
207
|
+
rootSchema
|
|
208
|
+
).disabled || uischemaData?.disabled
|
|
209
|
+
}
|
|
210
|
+
required={required}
|
|
211
|
+
placeholder={uischemaData?.placeholder}
|
|
212
|
+
onChange={
|
|
213
|
+
uischemaData.freeSolo
|
|
214
|
+
? (newValue) => {
|
|
215
|
+
setChangeState(newValue.target.value);
|
|
216
|
+
handleChange(path, newValue.target.value);
|
|
217
|
+
}
|
|
218
|
+
: undefined
|
|
219
|
+
}
|
|
220
|
+
/>
|
|
221
|
+
)}
|
|
236
222
|
/>
|
|
237
223
|
</ComponentWrapper>
|
|
238
224
|
);
|
|
@@ -242,35 +228,30 @@ export default ImpaktAppsAutoComplete;
|
|
|
242
228
|
|
|
243
229
|
function updateSchema(param) {
|
|
244
230
|
if (param.uischemaData.multiple) {
|
|
245
|
-
param.setSchema((pre
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
properties
|
|
249
|
-
|
|
250
|
-
[param.path]
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
oneOf: param.response,
|
|
255
|
-
},
|
|
231
|
+
param.setSchema((pre) => ({
|
|
232
|
+
...pre,
|
|
233
|
+
properties: {
|
|
234
|
+
...pre.properties,
|
|
235
|
+
[param.path]: {
|
|
236
|
+
...pre.properties?.[param.path],
|
|
237
|
+
type: "array",
|
|
238
|
+
items: {
|
|
239
|
+
oneOf: param.response,
|
|
256
240
|
},
|
|
257
241
|
},
|
|
258
|
-
}
|
|
259
|
-
});
|
|
242
|
+
},
|
|
243
|
+
}));
|
|
260
244
|
} else {
|
|
261
|
-
param.setSchema((pre
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
properties
|
|
265
|
-
|
|
266
|
-
[param.path]
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
uniqueItems: true,
|
|
270
|
-
oneOf: param.response || [],
|
|
271
|
-
},
|
|
245
|
+
param.setSchema((pre) => ({
|
|
246
|
+
...pre,
|
|
247
|
+
properties: {
|
|
248
|
+
...pre.properties,
|
|
249
|
+
[param.path]: {
|
|
250
|
+
...pre.properties?.[param.path],
|
|
251
|
+
uniqueItems: true,
|
|
252
|
+
oneOf: param.response || [],
|
|
272
253
|
},
|
|
273
|
-
}
|
|
274
|
-
});
|
|
254
|
+
},
|
|
255
|
+
}));
|
|
275
256
|
}
|
|
276
257
|
}
|