@acvl/frontend-components 0.0.33 → 0.0.35
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/cjs/index.js +117 -79
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/v1/drawers/MainDrawer/index.d.ts +1 -1
- package/dist/cjs/types/src/components/v1/layout/pages/DetailPage/FieldArrayField/index.d.ts +7 -2
- package/dist/cjs/types/src/components/v1/theme/compStyleOverride.d.ts +15 -12
- package/dist/esm/index.js +117 -79
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/v1/drawers/MainDrawer/index.d.ts +1 -1
- package/dist/esm/types/src/components/v1/layout/pages/DetailPage/FieldArrayField/index.d.ts +7 -2
- package/dist/esm/types/src/components/v1/theme/compStyleOverride.d.ts +15 -12
- package/dist/index.d.ts +19 -16
- package/package.json +1 -1
|
@@ -2,10 +2,11 @@ import { DataGridProps } from "@mui/x-data-grid";
|
|
|
2
2
|
import { GridProps } from "@mui/material";
|
|
3
3
|
import { PageType } from "../../../../types";
|
|
4
4
|
import { JSONParserProps } from "../../../../forms";
|
|
5
|
+
import { FieldProps } from "../Field";
|
|
6
|
+
import { MainDrawerProps } from "../../../../drawers/MainDrawer";
|
|
5
7
|
declare module "@mui/x-data-grid" {
|
|
6
8
|
interface ToolbarPropsOverrides {
|
|
7
|
-
|
|
8
|
-
handleDelete: () => void;
|
|
9
|
+
handleClick: () => void;
|
|
9
10
|
pageType: PageType;
|
|
10
11
|
}
|
|
11
12
|
}
|
|
@@ -20,6 +21,10 @@ export interface ArrayFieldProps {
|
|
|
20
21
|
gridProps?: GridProps;
|
|
21
22
|
pageType?: PageType;
|
|
22
23
|
parser?: JSONParserProps;
|
|
24
|
+
fields: FieldProps[];
|
|
25
|
+
slotProps?: {
|
|
26
|
+
drawer?: Partial<MainDrawerProps>;
|
|
27
|
+
};
|
|
23
28
|
}
|
|
24
29
|
declare const FieldArrayField: (props: ArrayFieldProps) => import("react/jsx-runtime").JSX.Element;
|
|
25
30
|
export default FieldArrayField;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Cambia el diseño default de ciertos componentes de Material UI
|
|
3
|
-
**/
|
|
3
|
+
**/
|
|
4
4
|
export default function componentStyleOverrides(theme: any): {
|
|
5
5
|
MuiAlert: {
|
|
6
6
|
defaultProps: {
|
|
@@ -10,12 +10,12 @@ export default function componentStyleOverrides(theme: any): {
|
|
|
10
10
|
MuiListItemButton: {
|
|
11
11
|
styleOverrides: {
|
|
12
12
|
root: {
|
|
13
|
-
|
|
13
|
+
"&:hover": {
|
|
14
14
|
backgroundColor: string;
|
|
15
|
-
|
|
15
|
+
"& .MuiTypography-root": {
|
|
16
16
|
color: string;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
"& .MuiSvgIcon-root": {
|
|
19
19
|
color: string;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
@@ -25,35 +25,38 @@ export default function componentStyleOverrides(theme: any): {
|
|
|
25
25
|
MuiDataGrid: {
|
|
26
26
|
styleOverrides: {
|
|
27
27
|
columnHeader: {
|
|
28
|
-
|
|
28
|
+
"& .MuiDataGrid-columnHeaderTitle": {
|
|
29
29
|
fontWeight: string;
|
|
30
30
|
};
|
|
31
|
-
|
|
31
|
+
"&:focus": {
|
|
32
32
|
outline: string;
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
row: {
|
|
36
|
+
"&.row-error": {
|
|
37
|
+
backgroundColor: "#ffcdd2";
|
|
38
|
+
};
|
|
36
39
|
"&.even": {
|
|
37
40
|
backgroundColor: "#fafafa";
|
|
38
41
|
};
|
|
39
|
-
|
|
42
|
+
"&:hover": {
|
|
40
43
|
backgroundColor: string;
|
|
41
|
-
|
|
44
|
+
"@media (hover: none)": {
|
|
42
45
|
backgroundColor: string;
|
|
43
46
|
};
|
|
44
47
|
};
|
|
45
48
|
};
|
|
46
49
|
cell: {
|
|
47
|
-
|
|
50
|
+
"& .MuiOutlinedInput-notchedOutline": {
|
|
48
51
|
border: string;
|
|
49
52
|
};
|
|
50
|
-
|
|
53
|
+
"&.MuiDataGrid-cell--editing": {
|
|
51
54
|
backgroundColor: string;
|
|
52
|
-
|
|
55
|
+
"& .MuiInputBase-root": {
|
|
53
56
|
height: string;
|
|
54
57
|
};
|
|
55
58
|
};
|
|
56
|
-
|
|
59
|
+
"& .Mui-error": {
|
|
57
60
|
backgroundColor: string;
|
|
58
61
|
color: string;
|
|
59
62
|
fontWeight: string;
|
package/dist/esm/index.js
CHANGED
|
@@ -25673,14 +25673,14 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
|
|
|
25673
25673
|
setValue(formType, response, key, object);
|
|
25674
25674
|
break;
|
|
25675
25675
|
case "object":
|
|
25676
|
-
if (object
|
|
25676
|
+
if (object instanceof File) {
|
|
25677
|
+
setValue(formType, response, key, object);
|
|
25678
|
+
}
|
|
25679
|
+
else if (object === null || isEmpty(object)) {
|
|
25677
25680
|
if (key.includes("after") || key.includes("before"))
|
|
25678
25681
|
setValue(formType, response, key, "");
|
|
25679
25682
|
else
|
|
25680
|
-
setValue(formType, response, key, object);
|
|
25681
|
-
}
|
|
25682
|
-
else if (object instanceof File) {
|
|
25683
|
-
setValue(formType, response, key, object);
|
|
25683
|
+
setValue(formType, response, key, formType == "json" ? object : "");
|
|
25684
25684
|
}
|
|
25685
25685
|
else if (dayjs.isDayjs(object)) {
|
|
25686
25686
|
setValue(formType, response, key, object.format(get$1(props, `${key}.format`, "YYYY-MM-DD")));
|
|
@@ -25778,9 +25778,27 @@ const formParser = ({ type, submitData, data, useLabel, props }) => {
|
|
|
25778
25778
|
};
|
|
25779
25779
|
// ==============================|| ERRORS ||============================== //
|
|
25780
25780
|
const setErrors = (form, error) => {
|
|
25781
|
+
const iterateDeep = (obj) => {
|
|
25782
|
+
if (Array.isArray(obj.reason)) {
|
|
25783
|
+
if (obj.reason.every((item) => typeof item === "object" && item !== null && !Array.isArray(item))) {
|
|
25784
|
+
obj.reason.forEach((obj2, index) => {
|
|
25785
|
+
Object.entries(obj2).forEach(([key3, val3]) => {
|
|
25786
|
+
form.setError(`${obj.name}.${index}.${key3}`, { message: val3.join(", ") });
|
|
25787
|
+
});
|
|
25788
|
+
});
|
|
25789
|
+
}
|
|
25790
|
+
else {
|
|
25791
|
+
form.setError(obj.name, { message: obj.reason.join(", ") });
|
|
25792
|
+
}
|
|
25793
|
+
}
|
|
25794
|
+
else {
|
|
25795
|
+
form.setError(obj.name, { message: obj.reason });
|
|
25796
|
+
}
|
|
25797
|
+
};
|
|
25781
25798
|
if ("invalid_params" in error.data) {
|
|
25782
25799
|
Object.values(error.data.invalid_params).forEach((entry) => {
|
|
25783
|
-
|
|
25800
|
+
iterateDeep(entry);
|
|
25801
|
+
// form.setError(entry.name, { message: entry.reason.join(", ") });
|
|
25784
25802
|
});
|
|
25785
25803
|
}
|
|
25786
25804
|
};
|
|
@@ -28084,43 +28102,48 @@ const Field = (props) => {
|
|
|
28084
28102
|
};
|
|
28085
28103
|
|
|
28086
28104
|
const EditToolbar = (props) => {
|
|
28087
|
-
return (jsx(Toolbar, { children: props.pageType != "detail" && (jsx(Tooltip$1, { title: "Crear", children: jsx(ToolbarButton, { onClick: props.
|
|
28105
|
+
return (jsx(Toolbar, { children: props.pageType != "detail" && (jsx(Tooltip$1, { title: "Crear", children: jsx(ToolbarButton, { onClick: props.handleClick, children: jsx(AddIcon, { fontSize: "small" }) }) })) }));
|
|
28088
28106
|
};
|
|
28089
28107
|
const FieldArrayField = (props) => {
|
|
28090
28108
|
const detail = useMemo(() => props.pageType === "detail", [props.pageType]);
|
|
28091
|
-
const { fields, append,
|
|
28092
|
-
control: props.form
|
|
28109
|
+
const { fields, append, remove, update } = useFieldArray({
|
|
28110
|
+
control: props.form?.control,
|
|
28093
28111
|
name: props.name,
|
|
28094
28112
|
keyName: "_id",
|
|
28095
28113
|
});
|
|
28096
|
-
const
|
|
28114
|
+
const errors = props.form.formState.errors;
|
|
28097
28115
|
const getIndex = useCallback((id) => findIndex(fields, function (field) {
|
|
28098
28116
|
return field._id == id;
|
|
28099
28117
|
}), [fields]);
|
|
28118
|
+
const [drawer, setDrawer] = useState({
|
|
28119
|
+
index: 0,
|
|
28120
|
+
open: false,
|
|
28121
|
+
});
|
|
28100
28122
|
const handleCreate = () => {
|
|
28101
28123
|
append(props.defaultValues);
|
|
28124
|
+
setDrawer({ index: fields.length, open: true });
|
|
28125
|
+
};
|
|
28126
|
+
const handleRowClick = (params) => {
|
|
28127
|
+
const index = getIndex(params.id);
|
|
28128
|
+
setDrawer({ index, open: true });
|
|
28129
|
+
};
|
|
28130
|
+
const handleCloseDrawer = () => {
|
|
28131
|
+
setDrawer((prev) => ({ ...prev, open: false }));
|
|
28132
|
+
};
|
|
28133
|
+
const handleCancel = () => {
|
|
28134
|
+
update(drawer.index, fields[drawer.index]);
|
|
28135
|
+
handleCloseDrawer();
|
|
28136
|
+
};
|
|
28137
|
+
const handleSave = () => {
|
|
28138
|
+
update(drawer.index, props.form.watch(`${props.name}.${drawer.index}`));
|
|
28139
|
+
handleCloseDrawer();
|
|
28102
28140
|
};
|
|
28103
28141
|
const handleDelete = (id) => {
|
|
28104
28142
|
remove(getIndex(id));
|
|
28105
28143
|
};
|
|
28106
|
-
const processRowUpdate = async (newRow, originalRow) => {
|
|
28107
|
-
const original_data = formParser({ submitData: originalRow, props: props.parser });
|
|
28108
|
-
const data = formParser({ submitData: newRow, props: props.parser });
|
|
28109
|
-
if (isEqual$1(data, original_data))
|
|
28110
|
-
return originalRow;
|
|
28111
|
-
const index = getIndex(data._id);
|
|
28112
|
-
update(index, data);
|
|
28113
|
-
return newRow;
|
|
28114
|
-
};
|
|
28115
|
-
const handleProcessRowUpdateError = () => { };
|
|
28116
28144
|
const dataGridProps = mergeSettings({
|
|
28117
28145
|
columns: !detail
|
|
28118
28146
|
? [
|
|
28119
|
-
...editColumn({
|
|
28120
|
-
displayEdit: true,
|
|
28121
|
-
rowModesModel,
|
|
28122
|
-
setRowModesModel,
|
|
28123
|
-
}),
|
|
28124
28147
|
{
|
|
28125
28148
|
field: "delete",
|
|
28126
28149
|
type: "actions",
|
|
@@ -28136,8 +28159,7 @@ const FieldArrayField = (props) => {
|
|
|
28136
28159
|
slots: { toolbar: EditToolbar },
|
|
28137
28160
|
slotProps: {
|
|
28138
28161
|
toolbar: {
|
|
28139
|
-
|
|
28140
|
-
handleDelete: handleDelete,
|
|
28162
|
+
handleClick: handleCreate,
|
|
28141
28163
|
pageType: props.pageType,
|
|
28142
28164
|
},
|
|
28143
28165
|
baseCheckbox: {
|
|
@@ -28145,25 +28167,32 @@ const FieldArrayField = (props) => {
|
|
|
28145
28167
|
},
|
|
28146
28168
|
},
|
|
28147
28169
|
getRowId: (row) => row._id,
|
|
28148
|
-
getRowClassName: (params) =>
|
|
28149
|
-
|
|
28150
|
-
|
|
28151
|
-
|
|
28152
|
-
|
|
28153
|
-
|
|
28154
|
-
|
|
28155
|
-
|
|
28156
|
-
|
|
28157
|
-
if (reason === GridRowEditStartReasons.cellDoubleClick && detail)
|
|
28158
|
-
event.defaultMuiPrevented = true;
|
|
28159
|
-
},
|
|
28160
|
-
onRowEditStop: (params, event) => {
|
|
28161
|
-
if (params.reason === GridRowEditStopReasons.rowFocusOut) {
|
|
28162
|
-
event.defaultMuiPrevented = true;
|
|
28163
|
-
}
|
|
28170
|
+
getRowClassName: (params) => {
|
|
28171
|
+
const hasError = !!(errors &&
|
|
28172
|
+
props.name in errors &&
|
|
28173
|
+
errors[props.name][getIndex(params.row._id)]);
|
|
28174
|
+
return hasError
|
|
28175
|
+
? "row-error"
|
|
28176
|
+
: params.indexRelativeToCurrentPage % 2 === 0
|
|
28177
|
+
? "even"
|
|
28178
|
+
: "odd";
|
|
28164
28179
|
},
|
|
28180
|
+
density: "compact",
|
|
28181
|
+
onRowClick: props.pageType != "detail" ? handleRowClick : undefined,
|
|
28165
28182
|
}, props.dataGridProps);
|
|
28166
|
-
return (
|
|
28183
|
+
return (jsxs(Fragment, { children: [jsx(MainDrawer, { open: drawer.open, drawerToggle: handleCancel, title: "Trailer", slots: {
|
|
28184
|
+
button: (jsx(SaveCancelButton, { slotProps: {
|
|
28185
|
+
saveBtn: { onClick: handleSave, type: "button" },
|
|
28186
|
+
cancelBtn: { onClick: handleCancel },
|
|
28187
|
+
} })),
|
|
28188
|
+
}, ...props.slotProps?.drawer, children: jsx(Grid, { container: true, size: 12, children: props.fields.map((field, index) => {
|
|
28189
|
+
return (jsxs(Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...field.gridProps, children: [jsx(Grid, { size: 12, children: jsx(Typography$1, { variant: "body1", fontWeight: "bold", children: field.label }) }), jsx(Grid, { size: 12, children: field.type({
|
|
28190
|
+
name: `${props.name}.${drawer.index}.${field.name}`,
|
|
28191
|
+
control: props.form.control,
|
|
28192
|
+
fieldProps: field.fieldProps,
|
|
28193
|
+
extraProps: field.extraProps,
|
|
28194
|
+
}) })] }, `grid-${index}`));
|
|
28195
|
+
}) }) }), jsxs(Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...props.gridProps, children: [jsx(Grid, { size: 12, children: jsx(Typography$1, { variant: "body1", fontWeight: "bold", children: props.label }) }), jsx(Grid, { size: 12, children: jsx(DataGrid, { ...dataGridProps }) })] })] }));
|
|
28167
28196
|
};
|
|
28168
28197
|
|
|
28169
28198
|
const Section = (props) => {
|
|
@@ -28396,7 +28425,7 @@ function DetailPage(props) {
|
|
|
28396
28425
|
}
|
|
28397
28426
|
}
|
|
28398
28427
|
}, [data, dispatch, form, props.slots?.title]);
|
|
28399
|
-
const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse }] = props.api.mutate.mutation();
|
|
28428
|
+
const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse },] = props.api.mutate.mutation();
|
|
28400
28429
|
const handleCancel = () => {
|
|
28401
28430
|
form.reset();
|
|
28402
28431
|
navigate(-1);
|
|
@@ -28406,7 +28435,8 @@ function DetailPage(props) {
|
|
|
28406
28435
|
// ==============================|| VALIDATION ||============================== //
|
|
28407
28436
|
useValidateFieldData(props, form);
|
|
28408
28437
|
// ==============================|| QUICK RETURN ||============================== //
|
|
28409
|
-
if ((!canEdit && props.pageType == "edit") ||
|
|
28438
|
+
if ((!canEdit && props.pageType == "edit") ||
|
|
28439
|
+
(fetchError && fetchError.originalStatus == 403))
|
|
28410
28440
|
return jsx(NotAllowed, {});
|
|
28411
28441
|
if (fetchError && fetchError.originalStatus == 404)
|
|
28412
28442
|
return jsx(NotFound, {});
|
|
@@ -28420,7 +28450,9 @@ function DetailPage(props) {
|
|
|
28420
28450
|
props: props.slotProps?.parser,
|
|
28421
28451
|
};
|
|
28422
28452
|
const dataToSend = formParser(params);
|
|
28423
|
-
mutation(props.edit.useFormData
|
|
28453
|
+
mutation(props.edit.useFormData
|
|
28454
|
+
? dataToSend
|
|
28455
|
+
: { ...dataToSend, ...props.api.mutate.args })
|
|
28424
28456
|
.unwrap()
|
|
28425
28457
|
.then(() => {
|
|
28426
28458
|
if (!props.slotProps?.button?.save?.disableNavBack)
|
|
@@ -28452,7 +28484,9 @@ function DetailPage(props) {
|
|
|
28452
28484
|
if (!section.display)
|
|
28453
28485
|
return null;
|
|
28454
28486
|
if (typeof section.display == "object") {
|
|
28455
|
-
const validateAgainst = form
|
|
28487
|
+
const validateAgainst = form
|
|
28488
|
+
.watch(section.display.field)
|
|
28489
|
+
?.toString();
|
|
28456
28490
|
if (!section.display.method(validateAgainst, section.display.value))
|
|
28457
28491
|
return null;
|
|
28458
28492
|
}
|
|
@@ -28464,7 +28498,8 @@ function DetailPage(props) {
|
|
|
28464
28498
|
if (props.api.mutate.postAction &&
|
|
28465
28499
|
isSuccess &&
|
|
28466
28500
|
"post_action" in mutationResponse &&
|
|
28467
|
-
mutationResponse["post_action"]["type"] ===
|
|
28501
|
+
mutationResponse["post_action"]["type"] ===
|
|
28502
|
+
props.api.mutate.postAction.type) {
|
|
28468
28503
|
switch (props.api.mutate.postAction.after) {
|
|
28469
28504
|
// case 'create':
|
|
28470
28505
|
// if (props.pageType === 'create') return addPropsToNode(props.api.mutate.postAction.node, mutationResponse);
|
|
@@ -28701,67 +28736,70 @@ function themeTypography() {
|
|
|
28701
28736
|
// ==============================|| PERSONALIZADO DE COMPONENTES DE MUI ||============================== //
|
|
28702
28737
|
/**
|
|
28703
28738
|
* Cambia el diseño default de ciertos componentes de Material UI
|
|
28704
|
-
**/
|
|
28739
|
+
**/
|
|
28705
28740
|
function componentStyleOverrides(theme) {
|
|
28706
28741
|
return {
|
|
28707
28742
|
MuiAlert: {
|
|
28708
28743
|
defaultProps: {
|
|
28709
|
-
variant:
|
|
28744
|
+
variant: "filled",
|
|
28710
28745
|
},
|
|
28711
28746
|
},
|
|
28712
28747
|
MuiListItemButton: {
|
|
28713
28748
|
styleOverrides: {
|
|
28714
28749
|
root: {
|
|
28715
|
-
|
|
28750
|
+
"&:hover": {
|
|
28716
28751
|
backgroundColor: `${theme.palette.primary.main} !important`,
|
|
28717
|
-
|
|
28718
|
-
color:
|
|
28752
|
+
"& .MuiTypography-root": {
|
|
28753
|
+
color: "white !important",
|
|
28719
28754
|
},
|
|
28720
|
-
|
|
28721
|
-
color:
|
|
28722
|
-
}
|
|
28723
|
-
}
|
|
28724
|
-
}
|
|
28725
|
-
}
|
|
28755
|
+
"& .MuiSvgIcon-root": {
|
|
28756
|
+
color: "white !important",
|
|
28757
|
+
},
|
|
28758
|
+
},
|
|
28759
|
+
},
|
|
28760
|
+
},
|
|
28726
28761
|
},
|
|
28727
28762
|
MuiDataGrid: {
|
|
28728
28763
|
styleOverrides: {
|
|
28729
28764
|
columnHeader: {
|
|
28730
|
-
|
|
28731
|
-
fontWeight:
|
|
28765
|
+
"& .MuiDataGrid-columnHeaderTitle": {
|
|
28766
|
+
fontWeight: "bold",
|
|
28732
28767
|
},
|
|
28733
|
-
|
|
28734
|
-
outline:
|
|
28768
|
+
"&:focus": {
|
|
28769
|
+
outline: "none",
|
|
28735
28770
|
},
|
|
28736
28771
|
},
|
|
28737
28772
|
row: {
|
|
28773
|
+
[`&.row-error`]: {
|
|
28774
|
+
backgroundColor: red[100],
|
|
28775
|
+
},
|
|
28738
28776
|
[`&.even`]: {
|
|
28739
28777
|
backgroundColor: grey[50],
|
|
28740
28778
|
},
|
|
28741
|
-
|
|
28779
|
+
"&:hover": {
|
|
28742
28780
|
backgroundColor: alpha$1(theme.palette.primary.main, 0.2),
|
|
28743
|
-
|
|
28744
|
-
backgroundColor:
|
|
28781
|
+
"@media (hover: none)": {
|
|
28782
|
+
backgroundColor: "transparent",
|
|
28745
28783
|
},
|
|
28746
|
-
}
|
|
28784
|
+
},
|
|
28747
28785
|
},
|
|
28748
28786
|
cell: {
|
|
28749
|
-
|
|
28750
|
-
border:
|
|
28787
|
+
"& .MuiOutlinedInput-notchedOutline": {
|
|
28788
|
+
border: "none",
|
|
28751
28789
|
},
|
|
28752
|
-
|
|
28753
|
-
backgroundColor:
|
|
28754
|
-
|
|
28755
|
-
height:
|
|
28790
|
+
"&.MuiDataGrid-cell--editing": {
|
|
28791
|
+
backgroundColor: "rgb(217 243 190)",
|
|
28792
|
+
"& .MuiInputBase-root": {
|
|
28793
|
+
height: "100%",
|
|
28756
28794
|
},
|
|
28757
28795
|
},
|
|
28758
|
-
|
|
28759
|
-
backgroundColor:
|
|
28760
|
-
color:
|
|
28761
|
-
fontWeight:
|
|
28796
|
+
"& .Mui-error": {
|
|
28797
|
+
backgroundColor: "rgba(234,27,43,0.2)",
|
|
28798
|
+
color: "#ef1a2b",
|
|
28799
|
+
fontWeight: "bold",
|
|
28762
28800
|
},
|
|
28763
28801
|
},
|
|
28764
|
-
}
|
|
28802
|
+
},
|
|
28765
28803
|
},
|
|
28766
28804
|
};
|
|
28767
28805
|
}
|