@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
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ISearchableSelect for AutoAdmin for ReactAdmin
|
|
3
|
+
* @author Franisco Aranda <francisco.aranda@sudo.cl> <faranda@gmail.com>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Autocomplete,
|
|
8
|
+
Box,
|
|
9
|
+
CircularProgress,
|
|
10
|
+
InputLabel,
|
|
11
|
+
TextField,
|
|
12
|
+
} from "@mui/material";
|
|
13
|
+
import React, { useEffect, useState } from "react";
|
|
14
|
+
import { useController } from "react-hook-form";
|
|
15
|
+
import { useGetList } from "react-admin";
|
|
16
|
+
|
|
17
|
+
import { useRecordContext } from "react-admin";
|
|
18
|
+
import { Loading } from "react-admin";
|
|
19
|
+
import { isArray } from "lodash";
|
|
20
|
+
import { IDashAutoAdminCustomFieldComponent } from "dash-auto-admin";
|
|
21
|
+
|
|
22
|
+
interface ISearchableSelect extends IDashAutoAdminCustomFieldComponent {
|
|
23
|
+
name?: string;
|
|
24
|
+
resource?: string;
|
|
25
|
+
selectLabel?: string;
|
|
26
|
+
title?: string;
|
|
27
|
+
renderText?: (object: any) => any;
|
|
28
|
+
transformData?: (val: string) => any;
|
|
29
|
+
defaultValues?: any;
|
|
30
|
+
isMultiple?: boolean;
|
|
31
|
+
//pagination?: boolean,
|
|
32
|
+
minSearch?: number;
|
|
33
|
+
searchResults?: number;
|
|
34
|
+
timerSearch?: number;
|
|
35
|
+
isEmpty?: boolean;
|
|
36
|
+
filter?: { [x: string]: any };
|
|
37
|
+
queryFilter?: string;
|
|
38
|
+
isOptionEqualToValue?: (option, value) => boolean;
|
|
39
|
+
viewAttribute: string;
|
|
40
|
+
elementKeyId?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const SearchableSelect: React.FC<ISearchableSelect> = ({
|
|
44
|
+
method,
|
|
45
|
+
attribute,
|
|
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 = undefined,
|
|
57
|
+
isEmpty = false,
|
|
58
|
+
filter,
|
|
59
|
+
isOptionEqualToValue = undefined,
|
|
60
|
+
viewAttribute = null,
|
|
61
|
+
elementKeyId = "id",
|
|
62
|
+
}) => {
|
|
63
|
+
//const element_key = "system_marketplace_category_id";
|
|
64
|
+
const [open, setOpen] = useState(true);
|
|
65
|
+
/* parsedOptions se setea null, esto para que el control no aparezca hasta que se obtenga la data */
|
|
66
|
+
const [parsedOptions, setParsedOptions] = useState(null);
|
|
67
|
+
const [q, setQ] = useState("");
|
|
68
|
+
const record = useRecordContext();
|
|
69
|
+
const field = useController({
|
|
70
|
+
name: attribute.attribute,
|
|
71
|
+
defaultValue: record ? record[attribute.attribute] : null,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const includes =
|
|
75
|
+
record &&
|
|
76
|
+
record[attribute.attribute] &&
|
|
77
|
+
isArray(record[attribute.attribute])
|
|
78
|
+
? record[attribute.attribute].map((element) =>
|
|
79
|
+
element.hasOwnProperty(elementKeyId)
|
|
80
|
+
? element[elementKeyId]
|
|
81
|
+
: element
|
|
82
|
+
)
|
|
83
|
+
: record[attribute.attribute];
|
|
84
|
+
|
|
85
|
+
const {
|
|
86
|
+
data: resourceData,
|
|
87
|
+
total,
|
|
88
|
+
isLoading,
|
|
89
|
+
error,
|
|
90
|
+
} = useGetList(
|
|
91
|
+
resource,
|
|
92
|
+
{
|
|
93
|
+
filter: { [queryFilter]: q, ...filter, includes: includes },
|
|
94
|
+
},
|
|
95
|
+
{ refetchOnWindowFocus: false }
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (resourceData && !isLoading) {
|
|
100
|
+
//Le agrega el key, para evitar el warning de react.
|
|
101
|
+
//setParsedOptions([...parsedOptions,...resourceData.map(ele => { return {...ele,key:"option"+ele.id}})])
|
|
102
|
+
if (parsedOptions)
|
|
103
|
+
setParsedOptions([
|
|
104
|
+
...parsedOptions,
|
|
105
|
+
...resourceData.map((ele) => {
|
|
106
|
+
return { ...ele, key: "option" + ele.id };
|
|
107
|
+
}),
|
|
108
|
+
]);
|
|
109
|
+
setParsedOptions(
|
|
110
|
+
resourceData.map((ele) => {
|
|
111
|
+
return { ...ele, key: "option" + ele.id };
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
} /*else {
|
|
115
|
+
// Setea la data a un arreglo vacío, ya que si es null, se ocultará el componente.
|
|
116
|
+
//setParsedOptions([]);
|
|
117
|
+
}*/
|
|
118
|
+
return () => setParsedOptions([]);
|
|
119
|
+
// TODO! reset callback, empty parsedOptions.
|
|
120
|
+
}, [resourceData, isLoading]);
|
|
121
|
+
|
|
122
|
+
const [timeOutSearch, setTimeOutSearch] = useState(undefined);
|
|
123
|
+
|
|
124
|
+
const debounce = (fn: Function, delay = 500) => {
|
|
125
|
+
clearTimeout(timeOutSearch);
|
|
126
|
+
setTimeOutSearch(
|
|
127
|
+
setTimeout(() => {
|
|
128
|
+
fn();
|
|
129
|
+
}, delay)
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<>
|
|
135
|
+
{parsedOptions && (
|
|
136
|
+
<Autocomplete
|
|
137
|
+
key={"autocomplete-" + attribute.attribute}
|
|
138
|
+
multiple={isMultiple}
|
|
139
|
+
loading={isLoading && open}
|
|
140
|
+
//sx={{ width: 373 }}
|
|
141
|
+
fullWidth
|
|
142
|
+
freeSolo={true}
|
|
143
|
+
//options={!resourceData ? [] : !defaultValues ? resourceData : resourceData}
|
|
144
|
+
//options={resourceData ? resourceData.map(ele => { return {...ele,key:ele.id}} ) : []}
|
|
145
|
+
options={parsedOptions}
|
|
146
|
+
open={open}
|
|
147
|
+
onOpen={() => setOpen(true)}
|
|
148
|
+
onClose={() => setOpen(false)}
|
|
149
|
+
/*defaultValue={field.field?.value && field.field.value.map(item => parsedOptions.find(
|
|
150
|
+
(element) => {
|
|
151
|
+
|
|
152
|
+
return element.id === item.id
|
|
153
|
+
}))}*/
|
|
154
|
+
//value={isOptionEqualToValue && parsedOptions ? parsedOptions.find(ele => isOptionEqualToValue(ele,field.field.value))[viewAttribute] : field.field.value}
|
|
155
|
+
|
|
156
|
+
defaultValue={field.field?.value}
|
|
157
|
+
//value={field.field.value}
|
|
158
|
+
|
|
159
|
+
isOptionEqualToValue={isOptionEqualToValue}
|
|
160
|
+
autoHighlight
|
|
161
|
+
//{...(!isEmpty && { value: field.field.value })}
|
|
162
|
+
//{...(isEmpty && { renderTags: (value, getTagProps) => <></> })}
|
|
163
|
+
// 8
|
|
164
|
+
|
|
165
|
+
getOptionLabel={(option: any) => {
|
|
166
|
+
const _option = !Array.isArray(option) // si es un numero como 'id', busca la opción en los valores con isOptionEqualToValue, sino devuelve el objeto original.
|
|
167
|
+
? parsedOptions &&
|
|
168
|
+
parsedOptions.find((ele) =>
|
|
169
|
+
isOptionEqualToValue(ele, field.field.value)
|
|
170
|
+
)
|
|
171
|
+
: option;
|
|
172
|
+
if (!_option) return q; //es posbile que no se haya encontrado en parsedOptions o que parsedOptions aún no esté definido.
|
|
173
|
+
const r =
|
|
174
|
+
viewAttribute && !renderText
|
|
175
|
+
? _option[viewAttribute]
|
|
176
|
+
: renderText(_option);
|
|
177
|
+
console.log(
|
|
178
|
+
"getOptionLabel",
|
|
179
|
+
parsedOptions.find((ele) =>
|
|
180
|
+
isOptionEqualToValue(ele, field.field.value)
|
|
181
|
+
),
|
|
182
|
+
r
|
|
183
|
+
);
|
|
184
|
+
if (!r) return q;
|
|
185
|
+
return r;
|
|
186
|
+
}}
|
|
187
|
+
//getOptionLabel={(option: any) => option}
|
|
188
|
+
|
|
189
|
+
renderOption={(props, option: any) => {
|
|
190
|
+
const { key, ...newProps } = props as any;
|
|
191
|
+
|
|
192
|
+
return (
|
|
193
|
+
<Box
|
|
194
|
+
key={option.key}
|
|
195
|
+
component="li"
|
|
196
|
+
sx={{ "& > img": { mr: 2, flexShrink: 0 } }}
|
|
197
|
+
{...newProps}
|
|
198
|
+
>
|
|
199
|
+
{viewAttribute && !renderText
|
|
200
|
+
? option[viewAttribute]
|
|
201
|
+
: renderText(option)}
|
|
202
|
+
</Box>
|
|
203
|
+
);
|
|
204
|
+
}}
|
|
205
|
+
onChange={(event: any, rawValue) => {
|
|
206
|
+
console.log("onChange", event, rawValue);
|
|
207
|
+
let newValue = rawValue;
|
|
208
|
+
|
|
209
|
+
if (Array.isArray(rawValue)) {
|
|
210
|
+
newValue = isEmpty
|
|
211
|
+
? [...rawValue, ...field.field.value]
|
|
212
|
+
: [
|
|
213
|
+
...new Map(
|
|
214
|
+
newValue.map((v) => [v.id, v])
|
|
215
|
+
).values(),
|
|
216
|
+
];
|
|
217
|
+
}
|
|
218
|
+
transformData
|
|
219
|
+
? field.field.onChange(transformData(newValue))
|
|
220
|
+
: field.field.onChange(newValue);
|
|
221
|
+
}}
|
|
222
|
+
renderInput={(params) => {
|
|
223
|
+
console.log("renderInput", params.id);
|
|
224
|
+
return (
|
|
225
|
+
<TextField
|
|
226
|
+
key={params.id}
|
|
227
|
+
{...params}
|
|
228
|
+
label={selectLabel}
|
|
229
|
+
variant="outlined"
|
|
230
|
+
onChange={(ev) => {
|
|
231
|
+
// dont fire API if the user delete or not entered anything
|
|
232
|
+
let searchValue = ev.target.value;
|
|
233
|
+
//onSearch={(searchValue) => {}
|
|
234
|
+
|
|
235
|
+
if (
|
|
236
|
+
searchValue &&
|
|
237
|
+
searchValue !== "" &&
|
|
238
|
+
searchValue.length >= minSearch
|
|
239
|
+
)
|
|
240
|
+
debounce(
|
|
241
|
+
() => setQ(searchValue),
|
|
242
|
+
timerSearch
|
|
243
|
+
);
|
|
244
|
+
|
|
245
|
+
/*if (ev.target.value !== "" || ev.target.value !== null) {
|
|
246
|
+
setQ(ev.target.value);
|
|
247
|
+
}*/
|
|
248
|
+
}}
|
|
249
|
+
//onBlur={() => setQ('')}
|
|
250
|
+
InputProps={{
|
|
251
|
+
...params.InputProps,
|
|
252
|
+
autoComplete: "new-password",
|
|
253
|
+
endAdornment: (
|
|
254
|
+
<>
|
|
255
|
+
{isLoading ? (
|
|
256
|
+
<CircularProgress
|
|
257
|
+
color="inherit"
|
|
258
|
+
size={20}
|
|
259
|
+
/>
|
|
260
|
+
) : null}
|
|
261
|
+
{params.InputProps.endAdornment}
|
|
262
|
+
</>
|
|
263
|
+
),
|
|
264
|
+
}}
|
|
265
|
+
/>
|
|
266
|
+
);
|
|
267
|
+
}}
|
|
268
|
+
/>
|
|
269
|
+
)}
|
|
270
|
+
</>
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const RASearchableSelect = ({
|
|
275
|
+
method,
|
|
276
|
+
attribute,
|
|
277
|
+
...props
|
|
278
|
+
}: ISearchableSelect) => {
|
|
279
|
+
switch (method) {
|
|
280
|
+
case "edit":
|
|
281
|
+
case "create":
|
|
282
|
+
return (
|
|
283
|
+
<SearchableSelect
|
|
284
|
+
attribute={attribute}
|
|
285
|
+
method={method}
|
|
286
|
+
{...props}
|
|
287
|
+
/>
|
|
288
|
+
);
|
|
289
|
+
case "view":
|
|
290
|
+
return (
|
|
291
|
+
<SearchableSelect
|
|
292
|
+
attribute={attribute}
|
|
293
|
+
method={method}
|
|
294
|
+
{...props}
|
|
295
|
+
/>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
export default RASearchableSelect;
|