@dashadmin/dash-components 1.3.25 → 1.3.28
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/README.md +35 -0
- package/dist/components/AuditLog/AuditLog.js +345 -1
- package/dist/components/AuditLog/index.js +4 -1
- package/dist/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.js +630 -3
- package/dist/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.js +647 -3
- package/dist/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.js +53 -1
- package/dist/components/Json/Json.js +235 -1
- package/dist/components/JsonColorSelector/JsonColorSelector.js +1172 -1
- package/dist/components/JsonColorSelector/JsonColorSelectorEnhanced.js +863 -2
- package/dist/components/JsonColorSelector/JsonCssVarValues.js +738 -1
- package/dist/components/JsonColorSelector/components/ColorEditDialog.js +426 -1
- package/dist/components/JsonColorSelector/components/ColorPaletteItem.js +75 -1
- package/dist/components/JsonColorSelector/components/ImageColorExtractor.js +283 -1
- package/dist/components/JsonColorSelector/helpers/functions.js +101 -1
- package/dist/components/JsonColorSelector/useAsyncColorThief.js +105 -1
- package/dist/components/ListActive/ListActive.js +126 -1
- package/dist/components/ListActive/ListBoolean.js +124 -1
- package/dist/components/NotificationPreferences/NotificationPreferences.js +317 -1
- package/dist/components/NotificationPreferences/index.js +7 -1
- package/dist/components/SearchableSelects/RASearchableSelect.js +236 -1
- package/dist/components/SearchableSelects/RASearchableSelectCheckboxes.js +479 -1
- package/dist/components/SearchableSelects/RASearchableSelectChips.js +465 -1
- package/dist/components/SearchableSelects/RASearchableSelectChipsRecordContext.js +295 -1
- package/dist/components/SearchableSelects/SearchableSelect.js +202 -1
- package/dist/components/SearchableSelects/SearchableSelectCheckboxes.js +290 -1
- package/dist/components/SortableDataGrid/SortableDataGrid.js +72 -1
- package/dist/components/SortableDataGrid/SortableDataGridBody.js +167 -1
- package/dist/components/SortableDataGrid/SortableDataGridHeader.js +109 -1
- package/dist/components/SortableDataGrid/SortableDataGridRow.js +283 -1
- package/dist/components/Upload/SingleImageUploader.js +40 -1
- package/dist/components/custom/PackageCopyMethod.js +78 -1
- package/dist/components/custom/PackageRadioButtonGroup.js +45 -1
- package/dist/components/dialog/Basic.js +8 -1
- package/dist/components/dialog/Correct.js +14 -1
- package/dist/components/dialog/Error.js +14 -1
- package/dist/components/dialog/Info.js +14 -1
- package/dist/components/dialog/InfoV2.js +21 -1
- package/dist/components/dialog/NotFound.js +14 -1
- package/dist/components/dialog/QuickSearch.js +117 -1
- package/dist/components/notifications/NotificationsCenter.js +597 -1
- package/dist/components/notifications/index.js +24 -1
- package/dist/components/tables/PaginationComponent.js +36 -1
- package/dist/components/theme/AppLoadingFallback.js +38 -2
- package/dist/components/theme/ErrorBoundary.js +52 -1
- package/dist/components/theme/InitialLoader.js +13 -1
- package/dist/components/theme/NotFound.js +136 -1
- package/dist/components/theme/NotResults.js +38 -1
- package/dist/hooks/useDraggable.js +6 -1
- package/dist/hooks/useNotifications.js +8 -1
- package/dist/hooks/useQuickSearch.js +26 -1
- package/dist/index.js +66 -5567
- package/dist/utils/setNativeValue.js +17 -1
- package/package.json +148 -132
- package/src/components/AuditLog/AuditLog.tsx +476 -0
- package/src/components/AuditLog/index.ts +2 -0
- package/src/components/AutoCompleteArrayInput/AutoCompleteCheckBoxInput.tsx +917 -0
- package/src/components/AutoCompleteArrayInput/AutocompleteCheckBoxArrayInput.tsx +39 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutoCompleteCheckBoxInput.tsx +916 -0
- package/src/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayInput.tsx +44 -0
- package/src/components/Json/Json.tsx +312 -0
- package/src/components/JsonColorSelector/JsonColorSelector.tsx +1435 -0
- package/src/components/JsonColorSelector/JsonColorSelectorEnhanced.tsx +1029 -0
- package/src/components/JsonColorSelector/JsonCssVarValues.tsx +863 -0
- package/src/components/JsonColorSelector/components/ColorEditDialog.tsx +491 -0
- package/src/components/JsonColorSelector/components/ColorPaletteItem.tsx +80 -0
- package/src/components/JsonColorSelector/components/ImageColorExtractor.tsx +328 -0
- package/src/components/JsonColorSelector/helpers/functions.tsx +123 -0
- package/src/components/JsonColorSelector/interfaces/interfaces.tsx +22 -0
- package/src/components/JsonColorSelector/useAsyncColorThief.tsx +97 -0
- package/src/components/ListActive/ListActive.tsx +106 -0
- package/src/components/ListActive/ListBoolean.tsx +96 -0
- package/src/components/NotificationPreferences/NotificationPreferences.tsx +463 -0
- package/src/components/NotificationPreferences/index.tsx +2 -0
- package/src/components/SearchableSelects/RASearchableSelect.tsx +300 -0
- package/src/components/SearchableSelects/RASearchableSelectCheckboxes.tsx +604 -0
- package/src/components/SearchableSelects/RASearchableSelectChips.tsx +558 -0
- package/src/components/SearchableSelects/RASearchableSelectChipsRecordContext.tsx +362 -0
- package/src/components/SearchableSelects/SearchableSelect.tsx +321 -0
- package/src/components/SearchableSelects/SearchableSelectCheckboxes.tsx +355 -0
- package/src/components/SortableDataGrid/SortableDataGrid.tsx +56 -0
- package/src/components/SortableDataGrid/SortableDataGridBody.tsx +175 -0
- package/src/components/SortableDataGrid/SortableDataGridHeader.tsx +171 -0
- package/src/components/SortableDataGrid/SortableDataGridRow.tsx +247 -0
- package/src/components/Upload/SingleImageUploader.tsx +55 -0
- package/src/components/custom/PackageCopyMethod.tsx +109 -0
- package/src/components/custom/PackageRadioButtonGroup.tsx +47 -0
- package/src/components/dialog/Basic.tsx +11 -0
- package/src/components/dialog/Correct.tsx +16 -0
- package/src/components/dialog/Error.tsx +15 -0
- package/src/components/dialog/Info.tsx +15 -0
- package/src/components/dialog/InfoV2.tsx +35 -0
- package/src/components/dialog/NotFound.tsx +18 -0
- package/src/components/dialog/QuickSearch.tsx +115 -0
- package/src/components/notifications/NotificationsCenter.tsx +792 -0
- package/src/components/notifications/index.ts +42 -0
- package/src/components/tables/PaginationComponent.tsx +17 -0
- package/src/components/theme/AppLoadingFallback.tsx +42 -0
- package/src/components/theme/ErrorBoundary.tsx +57 -0
- package/src/components/theme/InitialLoader.tsx +16 -0
- package/src/components/theme/NotFound.tsx +124 -0
- package/src/components/theme/NotResults.tsx +54 -0
- package/src/hooks/useDraggable.ts +11 -0
- package/src/hooks/useNotifications.ts +14 -0
- package/src/hooks/useQuickSearch.tsx +29 -0
- package/src/index.tsx +77 -0
- package/src/utils/setNativeValue.tsx +23 -0
- package/dist/color-thief-CTwGFhOB.js +0 -272
- /package/{dist → src}/components/AutoCompleteArrayInputAutoSearch/AutocompleteCheckBoxArrayAutoSearch.tsx.wip +0 -0
- /package/{dist → src}/components/JsonColorSelector/JsonColorSelector.tsx.bkup +0 -0
- /package/{dist → src}/components/SortableDataGrid/README.md +0 -0
- /package/{dist → src}/styles/index.less +0 -0
|
@@ -1 +1,295 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
+
import {
|
|
34
|
+
Autocomplete,
|
|
35
|
+
Box,
|
|
36
|
+
Chip,
|
|
37
|
+
CircularProgress,
|
|
38
|
+
TextField
|
|
39
|
+
} from "@mui/material";
|
|
40
|
+
import { useEffect, useState } from "react";
|
|
41
|
+
import { useFormContext } from "react-hook-form";
|
|
42
|
+
import { useGetList } from "react-admin";
|
|
43
|
+
import { useRecordContext } from "react-admin";
|
|
44
|
+
import { LoadingIndicator } from "react-admin";
|
|
45
|
+
const SearchableSelectChipsControlRecordContextEdit = ({
|
|
46
|
+
method,
|
|
47
|
+
attribute,
|
|
48
|
+
isMultiple = false,
|
|
49
|
+
searchResults = 50,
|
|
50
|
+
minSearch = 3,
|
|
51
|
+
timerSearch = 500,
|
|
52
|
+
resource,
|
|
53
|
+
selectLabel,
|
|
54
|
+
renderText,
|
|
55
|
+
transformData = (val) => val,
|
|
56
|
+
queryFilter = "q",
|
|
57
|
+
defaultValues = void 0,
|
|
58
|
+
isEmpty = false,
|
|
59
|
+
filter,
|
|
60
|
+
isOptionEqualToValue = void 0,
|
|
61
|
+
viewAttribute = null,
|
|
62
|
+
valueKeyId = "id",
|
|
63
|
+
useBaseAttributeName = false,
|
|
64
|
+
useListAttributeForController = false,
|
|
65
|
+
transformOption
|
|
66
|
+
}) => {
|
|
67
|
+
const { setValue, watch } = useFormContext();
|
|
68
|
+
const record = useRecordContext();
|
|
69
|
+
const saveAttributeName = attribute.attribute;
|
|
70
|
+
const displayAttributeName = attribute.listAttribute || attribute.attribute;
|
|
71
|
+
console.log("Attribute config:", {
|
|
72
|
+
saveAttributeName,
|
|
73
|
+
displayAttributeName,
|
|
74
|
+
record: record ? {
|
|
75
|
+
[saveAttributeName]: record[saveAttributeName],
|
|
76
|
+
[displayAttributeName]: record[displayAttributeName]
|
|
77
|
+
} : null
|
|
78
|
+
});
|
|
79
|
+
const [open, setOpen] = useState(false);
|
|
80
|
+
const [fullyLoaded, setFullyLoaded] = useState(false);
|
|
81
|
+
const [parsedOptions, setParsedOptions] = useState([]);
|
|
82
|
+
const [q, setQ] = useState("");
|
|
83
|
+
const [selectedOptions, setSelectedOptions] = useState([]);
|
|
84
|
+
const [timeOutSearch, setTimeOutSearch] = useState(void 0);
|
|
85
|
+
const currentFormValue = watch(saveAttributeName);
|
|
86
|
+
const _transformOption = (option, caller) => {
|
|
87
|
+
if (typeof transformOption === "function") {
|
|
88
|
+
return transformOption(option, parsedOptions, caller);
|
|
89
|
+
}
|
|
90
|
+
return option;
|
|
91
|
+
};
|
|
92
|
+
const getIncludes = () => {
|
|
93
|
+
let recordValue = record == null ? void 0 : record[saveAttributeName];
|
|
94
|
+
if (!recordValue) return [];
|
|
95
|
+
if (!Array.isArray(recordValue)) {
|
|
96
|
+
recordValue = [recordValue];
|
|
97
|
+
}
|
|
98
|
+
return recordValue.filter(Boolean);
|
|
99
|
+
};
|
|
100
|
+
const includes = getIncludes();
|
|
101
|
+
const {
|
|
102
|
+
data: resourceSearchResults,
|
|
103
|
+
total: totalSearchResults,
|
|
104
|
+
isLoading: isResourceSearchLoading,
|
|
105
|
+
error: isResourceSearchErrored
|
|
106
|
+
} = useGetList(resource, {
|
|
107
|
+
meta: { removeSortFilters: true },
|
|
108
|
+
filter: __spreadProps(__spreadValues({ [queryFilter]: q }, filter), { includes })
|
|
109
|
+
});
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (resourceSearchResults) {
|
|
112
|
+
const resultsArray = Array.isArray(resourceSearchResults) ? resourceSearchResults : Object.values(resourceSearchResults);
|
|
113
|
+
const _parsedOptions = resultsArray.map((ele, index) => __spreadProps(__spreadValues({}, ele), {
|
|
114
|
+
key: `option-${ele[valueKeyId] || index}`
|
|
115
|
+
}));
|
|
116
|
+
setParsedOptions(_parsedOptions);
|
|
117
|
+
}
|
|
118
|
+
}, [resourceSearchResults, valueKeyId]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (fullyLoaded) return;
|
|
121
|
+
console.log("Initializing default values...");
|
|
122
|
+
let initialSelectedOptions = [];
|
|
123
|
+
let initialFormValue = isMultiple ? [] : null;
|
|
124
|
+
if (defaultValues === null && record) {
|
|
125
|
+
if (record[displayAttributeName] && Array.isArray(record[displayAttributeName])) {
|
|
126
|
+
initialSelectedOptions = record[displayAttributeName];
|
|
127
|
+
initialFormValue = record[displayAttributeName].map((item) => item[valueKeyId]);
|
|
128
|
+
} else if (record[saveAttributeName]) {
|
|
129
|
+
const ids = Array.isArray(record[saveAttributeName]) ? record[saveAttributeName] : [record[saveAttributeName]];
|
|
130
|
+
initialFormValue = isMultiple ? ids : ids[0];
|
|
131
|
+
}
|
|
132
|
+
} else if (defaultValues !== void 0 && defaultValues !== null) {
|
|
133
|
+
if (Array.isArray(defaultValues)) {
|
|
134
|
+
initialSelectedOptions = defaultValues;
|
|
135
|
+
initialFormValue = defaultValues.map(
|
|
136
|
+
(item) => typeof item === "object" ? item[valueKeyId] : item
|
|
137
|
+
);
|
|
138
|
+
} else {
|
|
139
|
+
initialSelectedOptions = [defaultValues];
|
|
140
|
+
initialFormValue = typeof defaultValues === "object" ? defaultValues[valueKeyId] : defaultValues;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
console.log("Initial values:", {
|
|
144
|
+
initialSelectedOptions,
|
|
145
|
+
initialFormValue
|
|
146
|
+
});
|
|
147
|
+
setSelectedOptions(initialSelectedOptions);
|
|
148
|
+
setValue(saveAttributeName, initialFormValue);
|
|
149
|
+
setFullyLoaded(true);
|
|
150
|
+
}, [record, defaultValues, fullyLoaded, saveAttributeName, displayAttributeName, valueKeyId, isMultiple]);
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (parsedOptions.length > 0 && selectedOptions.length === 0 && currentFormValue) {
|
|
153
|
+
const formValueArray = Array.isArray(currentFormValue) ? currentFormValue : [currentFormValue];
|
|
154
|
+
const matchedOptions = formValueArray.map(
|
|
155
|
+
(id) => parsedOptions.find((option) => option[valueKeyId] === id)
|
|
156
|
+
).filter(Boolean);
|
|
157
|
+
if (matchedOptions.length > 0) {
|
|
158
|
+
console.log("Setting selected options from parsed options:", matchedOptions);
|
|
159
|
+
setSelectedOptions(matchedOptions);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}, [parsedOptions, selectedOptions, currentFormValue, valueKeyId]);
|
|
163
|
+
const debounce = (fn, delay = 500) => {
|
|
164
|
+
clearTimeout(timeOutSearch);
|
|
165
|
+
setTimeOutSearch(
|
|
166
|
+
setTimeout(() => {
|
|
167
|
+
fn();
|
|
168
|
+
}, delay)
|
|
169
|
+
);
|
|
170
|
+
};
|
|
171
|
+
const updateFieldValue = (newSelectedOptions) => {
|
|
172
|
+
console.log("Updating field value:", newSelectedOptions);
|
|
173
|
+
setSelectedOptions(newSelectedOptions || []);
|
|
174
|
+
const idsToSave = (newSelectedOptions || []).map((option) => option[valueKeyId]);
|
|
175
|
+
const valueToSave = isMultiple ? idsToSave : idsToSave[0] || null;
|
|
176
|
+
console.log("Saving to form:", { attribute: saveAttributeName, value: valueToSave });
|
|
177
|
+
setValue(saveAttributeName, valueToSave);
|
|
178
|
+
};
|
|
179
|
+
if (!fullyLoaded) return /* @__PURE__ */ jsx(LoadingIndicator, {});
|
|
180
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
181
|
+
Autocomplete,
|
|
182
|
+
{
|
|
183
|
+
multiple: isMultiple,
|
|
184
|
+
loading: isResourceSearchLoading,
|
|
185
|
+
fullWidth: true,
|
|
186
|
+
freeSolo: false,
|
|
187
|
+
options: parsedOptions,
|
|
188
|
+
open,
|
|
189
|
+
onOpen: () => setOpen(true),
|
|
190
|
+
onClose: () => setOpen(false),
|
|
191
|
+
value: isMultiple ? selectedOptions : selectedOptions[0] || null,
|
|
192
|
+
isOptionEqualToValue,
|
|
193
|
+
autoHighlight: true,
|
|
194
|
+
getOptionLabel: (option) => {
|
|
195
|
+
if (!option) return "";
|
|
196
|
+
return renderText(_transformOption(option, "optionlabel"), "optionlabel") || "";
|
|
197
|
+
},
|
|
198
|
+
renderOption: (props, option) => {
|
|
199
|
+
const _a = props, { key } = _a, newProps = __objRest(_a, ["key"]);
|
|
200
|
+
return /* @__PURE__ */ jsx(
|
|
201
|
+
Box,
|
|
202
|
+
__spreadProps(__spreadValues({
|
|
203
|
+
component: "li",
|
|
204
|
+
sx: { "& > img": { mr: 2, flexShrink: 0 } }
|
|
205
|
+
}, newProps), {
|
|
206
|
+
children: renderText(_transformOption(option, "option"), "option")
|
|
207
|
+
}),
|
|
208
|
+
option.key || `option-${option[valueKeyId]}`
|
|
209
|
+
);
|
|
210
|
+
},
|
|
211
|
+
renderTags: (tagValue, getTagProps) => {
|
|
212
|
+
return tagValue.map((option, index) => /* @__PURE__ */ jsx(
|
|
213
|
+
Chip,
|
|
214
|
+
__spreadValues({
|
|
215
|
+
label: renderText(_transformOption(option, "chip"), "chip")
|
|
216
|
+
}, getTagProps({ index })),
|
|
217
|
+
`chip-${option[valueKeyId] || index}`
|
|
218
|
+
));
|
|
219
|
+
},
|
|
220
|
+
onChange: (event, rawValue) => {
|
|
221
|
+
const newValue = isMultiple ? rawValue : rawValue ? [rawValue] : [];
|
|
222
|
+
updateFieldValue(newValue);
|
|
223
|
+
},
|
|
224
|
+
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
225
|
+
TextField,
|
|
226
|
+
__spreadProps(__spreadValues({}, params), {
|
|
227
|
+
label: selectLabel,
|
|
228
|
+
variant: "outlined",
|
|
229
|
+
onChange: (ev) => {
|
|
230
|
+
const searchValue = ev.target.value;
|
|
231
|
+
if (searchValue && searchValue !== "" && searchValue.length >= minSearch) {
|
|
232
|
+
debounce(() => setQ(searchValue), timerSearch);
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
InputProps: __spreadProps(__spreadValues({}, params.InputProps), {
|
|
236
|
+
autoComplete: "new-password",
|
|
237
|
+
endAdornment: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
238
|
+
isResourceSearchLoading && /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }),
|
|
239
|
+
params.InputProps.endAdornment
|
|
240
|
+
] })
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
)
|
|
244
|
+
},
|
|
245
|
+
`autocomplete-${saveAttributeName}`
|
|
246
|
+
) });
|
|
247
|
+
};
|
|
248
|
+
const SearchableSelectChipsControlRecordContextView = ({
|
|
249
|
+
attribute,
|
|
250
|
+
resourceConfig
|
|
251
|
+
}) => {
|
|
252
|
+
const record = useRecordContext();
|
|
253
|
+
const values = Array.isArray(record[attribute.listAttribute || attribute.attribute]) ? record[attribute.listAttribute || attribute.attribute] : [record[attribute.listAttribute || attribute.attribute]];
|
|
254
|
+
return /* @__PURE__ */ jsx(Fragment, { children: record && /* @__PURE__ */ jsx(Box, { sx: { width: "100%" }, children: values.map((item) => /* @__PURE__ */ jsx(
|
|
255
|
+
Chip,
|
|
256
|
+
{
|
|
257
|
+
label: item.name,
|
|
258
|
+
sx: { margin: 0.5 }
|
|
259
|
+
},
|
|
260
|
+
item.id
|
|
261
|
+
)) }) });
|
|
262
|
+
};
|
|
263
|
+
const SearchableSelectChipsControlRecordContext = (_a) => {
|
|
264
|
+
var _b = _a, { method, attribute, resourceConfig } = _b, props = __objRest(_b, ["method", "attribute", "resourceConfig"]);
|
|
265
|
+
switch (method) {
|
|
266
|
+
case "edit":
|
|
267
|
+
case "create":
|
|
268
|
+
return /* @__PURE__ */ jsx(
|
|
269
|
+
SearchableSelectChipsControlRecordContextEdit,
|
|
270
|
+
__spreadValues({
|
|
271
|
+
resourceConfig,
|
|
272
|
+
attribute,
|
|
273
|
+
method
|
|
274
|
+
}, props)
|
|
275
|
+
);
|
|
276
|
+
case "view":
|
|
277
|
+
case "list":
|
|
278
|
+
return /* @__PURE__ */ jsx(
|
|
279
|
+
SearchableSelectChipsControlRecordContextView,
|
|
280
|
+
__spreadValues({
|
|
281
|
+
resourceConfig,
|
|
282
|
+
attribute,
|
|
283
|
+
method
|
|
284
|
+
}, props)
|
|
285
|
+
);
|
|
286
|
+
default:
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var RASearchableSelectChipsRecordContext_default = SearchableSelectChipsControlRecordContext;
|
|
291
|
+
export {
|
|
292
|
+
SearchableSelectChipsControlRecordContextEdit,
|
|
293
|
+
SearchableSelectChipsControlRecordContextView,
|
|
294
|
+
RASearchableSelectChipsRecordContext_default as default
|
|
295
|
+
};
|
|
@@ -1 +1,202 @@
|
|
|
1
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
33
|
+
import {
|
|
34
|
+
Autocomplete,
|
|
35
|
+
Box,
|
|
36
|
+
CircularProgress,
|
|
37
|
+
TextField
|
|
38
|
+
} from "@mui/material";
|
|
39
|
+
import { useEffect, useState } from "react";
|
|
40
|
+
import { useController } from "react-hook-form";
|
|
41
|
+
import { useGetList } from "react-admin";
|
|
42
|
+
import { isArray } from "lodash";
|
|
43
|
+
const SearchableSelect = function WrappedAutoComplete(_a) {
|
|
44
|
+
var props = __objRest(_a, []);
|
|
45
|
+
const {
|
|
46
|
+
isMultiple = false,
|
|
47
|
+
//pagination = true,
|
|
48
|
+
//searchResults = 50,
|
|
49
|
+
minSearch = 3,
|
|
50
|
+
timerSearch = 500,
|
|
51
|
+
resource,
|
|
52
|
+
selectLabel,
|
|
53
|
+
renderText,
|
|
54
|
+
transformData,
|
|
55
|
+
queryFilter = "q",
|
|
56
|
+
defaultValues = void 0,
|
|
57
|
+
elementKeyId = "id",
|
|
58
|
+
isEmpty = false,
|
|
59
|
+
filter,
|
|
60
|
+
isOptionEqualToValue = (option, value) => value === option,
|
|
61
|
+
renderAttribute = null,
|
|
62
|
+
name,
|
|
63
|
+
onChange,
|
|
64
|
+
renderInputTextFieldProps
|
|
65
|
+
//..._rest
|
|
66
|
+
} = props;
|
|
67
|
+
const [open, setOpen] = useState(false);
|
|
68
|
+
const [parsedOptions, setParsedOptions] = useState(null);
|
|
69
|
+
const [q, setQ] = useState("");
|
|
70
|
+
const field = useController({
|
|
71
|
+
name,
|
|
72
|
+
defaultValue: defaultValues ? defaultValues : null
|
|
73
|
+
});
|
|
74
|
+
const includes = defaultValues && isArray(defaultValues) ? defaultValues.map((element) => element[elementKeyId] ? element[elementKeyId] : element) : defaultValues;
|
|
75
|
+
const {
|
|
76
|
+
data: resourceData,
|
|
77
|
+
isLoading
|
|
78
|
+
} = useGetList(
|
|
79
|
+
resource,
|
|
80
|
+
{
|
|
81
|
+
filter: __spreadProps(__spreadValues({ [queryFilter]: q }, filter), { includes })
|
|
82
|
+
},
|
|
83
|
+
{ refetchOnWindowFocus: false }
|
|
84
|
+
);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (resourceData && !isLoading) {
|
|
87
|
+
if (parsedOptions)
|
|
88
|
+
setParsedOptions([
|
|
89
|
+
...parsedOptions,
|
|
90
|
+
...resourceData.map((ele) => {
|
|
91
|
+
return __spreadProps(__spreadValues({}, ele), { key: "option" + ele.id });
|
|
92
|
+
})
|
|
93
|
+
]);
|
|
94
|
+
setParsedOptions(
|
|
95
|
+
resourceData.map((ele) => {
|
|
96
|
+
return __spreadProps(__spreadValues({}, ele), { key: "option" + ele.id });
|
|
97
|
+
})
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return () => setParsedOptions([]);
|
|
101
|
+
}, [resourceData, isLoading]);
|
|
102
|
+
const [timeOutSearch, setTimeOutSearch] = useState(void 0);
|
|
103
|
+
const debounce = (fn, delay = 500) => {
|
|
104
|
+
clearTimeout(timeOutSearch);
|
|
105
|
+
setTimeOutSearch(
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
fn();
|
|
108
|
+
}, delay)
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
const calculateDefaultValue = () => {
|
|
112
|
+
let value = null;
|
|
113
|
+
if (isMultiple) value = [];
|
|
114
|
+
if (isMultiple && field.field.value && Array.isArray(field.field.value))
|
|
115
|
+
value = field.field.value;
|
|
116
|
+
if (isMultiple && field.field.value && !Array.isArray(field.field.value))
|
|
117
|
+
value = [field.field.value];
|
|
118
|
+
if (!isMultiple && field.field.value) value = field.field.value;
|
|
119
|
+
return value;
|
|
120
|
+
};
|
|
121
|
+
const defaultValue = calculateDefaultValue();
|
|
122
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
123
|
+
isLoading && !parsedOptions ? /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }) : /* @__PURE__ */ jsx(Fragment, {}),
|
|
124
|
+
parsedOptions && /* @__PURE__ */ jsx(
|
|
125
|
+
Autocomplete,
|
|
126
|
+
{
|
|
127
|
+
multiple: isMultiple,
|
|
128
|
+
loading: isLoading && open,
|
|
129
|
+
fullWidth: true,
|
|
130
|
+
freeSolo: true,
|
|
131
|
+
options: parsedOptions,
|
|
132
|
+
open,
|
|
133
|
+
onOpen: () => setOpen(true),
|
|
134
|
+
onClose: () => setOpen(false),
|
|
135
|
+
defaultValue,
|
|
136
|
+
isOptionEqualToValue,
|
|
137
|
+
autoHighlight: true,
|
|
138
|
+
getOptionLabel: (option) => {
|
|
139
|
+
const _option = !Array.isArray(option) ? parsedOptions && parsedOptions.find((ele) => isOptionEqualToValue(ele, field.field.value)) : option;
|
|
140
|
+
if (!_option) return q;
|
|
141
|
+
const r = renderAttribute && !renderText ? _option[renderAttribute] : renderText(_option);
|
|
142
|
+
if (!r) return q;
|
|
143
|
+
return r;
|
|
144
|
+
},
|
|
145
|
+
renderOption: (p, option) => {
|
|
146
|
+
const _a2 = p, { key } = _a2, newProps = __objRest(_a2, ["key"]);
|
|
147
|
+
return /* @__PURE__ */ jsx(
|
|
148
|
+
Box,
|
|
149
|
+
__spreadProps(__spreadValues({
|
|
150
|
+
component: "li",
|
|
151
|
+
sx: { "& > img": { mr: 2, flexShrink: 0 } }
|
|
152
|
+
}, newProps), {
|
|
153
|
+
children: renderAttribute && !renderText ? option[renderAttribute] : renderText(option)
|
|
154
|
+
}),
|
|
155
|
+
option.key
|
|
156
|
+
);
|
|
157
|
+
},
|
|
158
|
+
onChange: (event, rawValue) => {
|
|
159
|
+
let newValue = rawValue;
|
|
160
|
+
if (Array.isArray(rawValue)) {
|
|
161
|
+
newValue = isEmpty ? [...rawValue, ...field.field.value] : [...new Map(newValue.map((v) => [v.id, v])).values()];
|
|
162
|
+
}
|
|
163
|
+
if (transformData) {
|
|
164
|
+
field.field.onChange(transformData(newValue));
|
|
165
|
+
} else {
|
|
166
|
+
field.field.onChange(newValue);
|
|
167
|
+
}
|
|
168
|
+
if (onChange) {
|
|
169
|
+
onChange(newValue);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
renderInput: (params) => {
|
|
173
|
+
return /* @__PURE__ */ jsx(
|
|
174
|
+
TextField,
|
|
175
|
+
__spreadValues(__spreadProps(__spreadValues({}, params), {
|
|
176
|
+
label: selectLabel,
|
|
177
|
+
variant: "outlined",
|
|
178
|
+
onChange: (ev) => {
|
|
179
|
+
const searchValue = ev.target.value;
|
|
180
|
+
if (searchValue && searchValue !== "" && searchValue.length >= minSearch)
|
|
181
|
+
debounce(() => setQ(searchValue), timerSearch);
|
|
182
|
+
},
|
|
183
|
+
InputProps: __spreadProps(__spreadValues({}, params.InputProps), {
|
|
184
|
+
autoComplete: "new-password",
|
|
185
|
+
endAdornment: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
186
|
+
isLoading ? /* @__PURE__ */ jsx(CircularProgress, { color: "inherit", size: 20 }) : null,
|
|
187
|
+
params.InputProps.endAdornment
|
|
188
|
+
] })
|
|
189
|
+
})
|
|
190
|
+
}), renderInputTextFieldProps),
|
|
191
|
+
params.id
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
"autocomplete-" + name
|
|
196
|
+
)
|
|
197
|
+
] });
|
|
198
|
+
};
|
|
199
|
+
var SearchableSelect_default = SearchableSelect;
|
|
200
|
+
export {
|
|
201
|
+
SearchableSelect_default as default
|
|
202
|
+
};
|