@acvl/frontend-components 0.0.23 → 0.0.25
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 +180 -150
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/src/components/v1/buttons/CreateButton/CreateButtonWithMenuOptions.d.ts +2 -2
- package/dist/cjs/types/src/components/v1/datagrids/Base/index.d.ts +1 -1
- package/dist/cjs/types/src/components/v1/datagrids/custom_slots/CustomToolbar/slots/ExportButton/ExportCSV.d.ts +1 -1
- package/dist/cjs/types/src/components/v1/datagrids/custom_slots/index.d.ts +1 -0
- package/dist/cjs/types/src/components/v1/datagrids/index.d.ts +1 -0
- package/dist/cjs/types/src/components/v1/layout/pages/DetailPage/types.d.ts +1 -0
- package/dist/cjs/types/src/components/v1/layout/pages/index.d.ts +1 -0
- package/dist/esm/index.js +180 -151
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/src/components/v1/buttons/CreateButton/CreateButtonWithMenuOptions.d.ts +2 -2
- package/dist/esm/types/src/components/v1/datagrids/Base/index.d.ts +1 -1
- package/dist/esm/types/src/components/v1/datagrids/custom_slots/CustomToolbar/slots/ExportButton/ExportCSV.d.ts +1 -1
- package/dist/esm/types/src/components/v1/datagrids/custom_slots/index.d.ts +1 -0
- package/dist/esm/types/src/components/v1/datagrids/index.d.ts +1 -0
- package/dist/esm/types/src/components/v1/layout/pages/DetailPage/types.d.ts +1 -0
- package/dist/esm/types/src/components/v1/layout/pages/index.d.ts +1 -0
- package/dist/index.d.ts +31 -15
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -25644,9 +25644,9 @@ dayjs.locale(es);
|
|
|
25644
25644
|
dayjs.extend(duration);
|
|
25645
25645
|
|
|
25646
25646
|
// ==============================|| JSON ||============================== //
|
|
25647
|
-
const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, data, props, formType }) => {
|
|
25647
|
+
const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, data, props, formType, }) => {
|
|
25648
25648
|
const ignore = get$1(props, `${base_key}.ignore`, false);
|
|
25649
|
-
if (ignore || [
|
|
25649
|
+
if (ignore || ["obj_permissions", "has_history"].includes(base_key))
|
|
25650
25650
|
return;
|
|
25651
25651
|
const altered_key = invoke(props, `${base_key}.alter_key`, base_key);
|
|
25652
25652
|
const key = altered_key || base_key;
|
|
@@ -25664,7 +25664,7 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
|
|
|
25664
25664
|
case "string":
|
|
25665
25665
|
if (invoke(props, `${base_key}.extra_validation`, object))
|
|
25666
25666
|
return;
|
|
25667
|
-
setValue(response, key, isEmpty(object) ?
|
|
25667
|
+
setValue(response, key, isEmpty(object) ? "" : object);
|
|
25668
25668
|
break;
|
|
25669
25669
|
case "number":
|
|
25670
25670
|
setValue(response, key, object);
|
|
@@ -25674,28 +25674,37 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
|
|
|
25674
25674
|
break;
|
|
25675
25675
|
case "object":
|
|
25676
25676
|
if (isNull(object) || isEmpty(object)) {
|
|
25677
|
-
if (includes(key,
|
|
25678
|
-
setValue(response, key,
|
|
25677
|
+
if (includes(key, "after") || includes(key, "before"))
|
|
25678
|
+
setValue(response, key, "");
|
|
25679
25679
|
else
|
|
25680
25680
|
setValue(response, key, object);
|
|
25681
25681
|
}
|
|
25682
|
+
else if (object instanceof File) {
|
|
25683
|
+
setValue(response, key, object);
|
|
25684
|
+
}
|
|
25682
25685
|
else if (object instanceof dayjs) {
|
|
25683
|
-
setValue(response, key, object.format(get$1(props, `${key}.format`,
|
|
25686
|
+
setValue(response, key, object.format(get$1(props, `${key}.format`, "YYYY-MM-DD")));
|
|
25684
25687
|
}
|
|
25685
|
-
else if (
|
|
25688
|
+
else if ("label" in object && "value" in object) {
|
|
25686
25689
|
if (useLabel)
|
|
25687
|
-
setValue(response, key, object[
|
|
25690
|
+
setValue(response, key, object["label"]);
|
|
25688
25691
|
else
|
|
25689
|
-
setValue(response, key, object[
|
|
25692
|
+
setValue(response, key, object["value"]);
|
|
25690
25693
|
}
|
|
25691
|
-
else if (Array.isArray(object)) {
|
|
25692
|
-
|
|
25693
|
-
|
|
25694
|
+
else if (Array.isArray(object)) {
|
|
25695
|
+
// it is an array
|
|
25696
|
+
if (object.length &&
|
|
25697
|
+
typeof object[0] == "object" &&
|
|
25698
|
+
!Array.isArray(object[0]) &&
|
|
25699
|
+
"value" in object[0] &&
|
|
25700
|
+
object[0]["value"] == "all") {
|
|
25701
|
+
// for data grid filters
|
|
25702
|
+
setValue(response, key, "");
|
|
25694
25703
|
}
|
|
25695
25704
|
else {
|
|
25696
25705
|
forEach(object, (arrayItem, idx) => {
|
|
25697
|
-
if (typeof arrayItem ==
|
|
25698
|
-
if (
|
|
25706
|
+
if (typeof arrayItem == "object") {
|
|
25707
|
+
if ("label" in arrayItem) {
|
|
25699
25708
|
setValue(response, `${key}.${idx}`, function (item) {
|
|
25700
25709
|
if (useLabel)
|
|
25701
25710
|
return item.label;
|
|
@@ -25703,7 +25712,16 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
|
|
|
25703
25712
|
return item.value;
|
|
25704
25713
|
});
|
|
25705
25714
|
}
|
|
25706
|
-
typeSwitch({
|
|
25715
|
+
typeSwitch({
|
|
25716
|
+
base_object: arrayItem,
|
|
25717
|
+
base_key: `${key}.${idx}`,
|
|
25718
|
+
response: response,
|
|
25719
|
+
useLabel: useLabel,
|
|
25720
|
+
data: data,
|
|
25721
|
+
submitData: submitData,
|
|
25722
|
+
props: props,
|
|
25723
|
+
formType: formType,
|
|
25724
|
+
});
|
|
25707
25725
|
}
|
|
25708
25726
|
else {
|
|
25709
25727
|
const keyArray = get$1(response, key);
|
|
@@ -25720,9 +25738,19 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
|
|
|
25720
25738
|
}
|
|
25721
25739
|
else {
|
|
25722
25740
|
forEach(object, (value, key2) => {
|
|
25723
|
-
if (!includes([
|
|
25741
|
+
if (!includes(["id", "transporte.tarifa.cargos_adicionales"], key) &&
|
|
25742
|
+
isEqual(get$1(data, `${key}.${key2}`), value))
|
|
25724
25743
|
return;
|
|
25725
|
-
typeSwitch({
|
|
25744
|
+
typeSwitch({
|
|
25745
|
+
base_object: value,
|
|
25746
|
+
base_key: `${key}.${key2}`,
|
|
25747
|
+
response: response,
|
|
25748
|
+
useLabel: useLabel,
|
|
25749
|
+
data: data,
|
|
25750
|
+
submitData: submitData,
|
|
25751
|
+
props: props,
|
|
25752
|
+
formType: formType,
|
|
25753
|
+
});
|
|
25726
25754
|
});
|
|
25727
25755
|
}
|
|
25728
25756
|
break;
|
|
@@ -25734,7 +25762,7 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
|
|
|
25734
25762
|
const jsonForm = ({ submitData, data, useLabel, props }) => {
|
|
25735
25763
|
const response = {};
|
|
25736
25764
|
forEach(submitData, function (value, key) {
|
|
25737
|
-
if (key !=
|
|
25765
|
+
if (key != "id" && isEqual(get$1(data, key), value))
|
|
25738
25766
|
return;
|
|
25739
25767
|
typeSwitch({
|
|
25740
25768
|
base_object: value,
|
|
@@ -25744,7 +25772,7 @@ const jsonForm = ({ submitData, data, useLabel, props }) => {
|
|
|
25744
25772
|
data: data,
|
|
25745
25773
|
props: props,
|
|
25746
25774
|
submitData: submitData,
|
|
25747
|
-
formType:
|
|
25775
|
+
formType: "json",
|
|
25748
25776
|
});
|
|
25749
25777
|
});
|
|
25750
25778
|
return response;
|
|
@@ -25752,7 +25780,7 @@ const jsonForm = ({ submitData, data, useLabel, props }) => {
|
|
|
25752
25780
|
const formDataForm = ({ submitData, data, useLabel, props }) => {
|
|
25753
25781
|
const formData = new FormData();
|
|
25754
25782
|
forEach(submitData, function (value, key) {
|
|
25755
|
-
if (key !=
|
|
25783
|
+
if (key != "id" && isEqual(get$1(data, key), value))
|
|
25756
25784
|
return;
|
|
25757
25785
|
typeSwitch({
|
|
25758
25786
|
base_object: value,
|
|
@@ -25762,26 +25790,18 @@ const formDataForm = ({ submitData, data, useLabel, props }) => {
|
|
|
25762
25790
|
data: data,
|
|
25763
25791
|
props: props,
|
|
25764
25792
|
submitData: submitData,
|
|
25765
|
-
formType:
|
|
25793
|
+
formType: "formData",
|
|
25766
25794
|
});
|
|
25767
25795
|
});
|
|
25768
25796
|
return formData;
|
|
25769
25797
|
};
|
|
25770
25798
|
// ==============================|| ERRORS ||============================== //
|
|
25771
|
-
const
|
|
25772
|
-
if (
|
|
25773
|
-
Object.
|
|
25774
|
-
|
|
25799
|
+
const setErrors = (form, error) => {
|
|
25800
|
+
if ("invalid_params" in error.data) {
|
|
25801
|
+
Object.values(error.data.invalid_params).forEach((entry) => {
|
|
25802
|
+
form.setError(entry.name, { message: entry.reason.join(", ") });
|
|
25775
25803
|
});
|
|
25776
25804
|
}
|
|
25777
|
-
else {
|
|
25778
|
-
form.setError(key, { message: errorObj });
|
|
25779
|
-
}
|
|
25780
|
-
};
|
|
25781
|
-
const setErrors = (form, error) => {
|
|
25782
|
-
Object.keys(error.data).forEach(x => {
|
|
25783
|
-
errorLoop(form, error.data[x], x);
|
|
25784
|
-
});
|
|
25785
25805
|
};
|
|
25786
25806
|
|
|
25787
25807
|
const valueLabel = object({
|
|
@@ -25922,14 +25942,14 @@ const FileBox = (props) => {
|
|
|
25922
25942
|
return (jsxs(Box, { bgcolor: grey[200], borderRadius: '12px', p: 2, display: 'flex', children: [jsx(Box, { flexGrow: 0.8, display: 'flex', justifyContent: 'left', alignItems: 'center', children: jsx(Typography$1, { fontWeight: 'bold', children: props.file.name.split('.')[0] }) }), jsx(Box, { flexGrow: 0.2, display: 'flex', justifyContent: 'right', alignItems: 'center', children: props.loadingRemove ? (jsx(CircularProgress, { size: '18px' })) : (jsx(Tooltip, { title: 'Remove', children: jsx(IconButton, { color: 'error', sx: { p: 0 }, onClick: props.handleRemove, children: jsx(DeleteIcon, {}) }) })) })] }));
|
|
25923
25943
|
};
|
|
25924
25944
|
|
|
25925
|
-
const VisuallyHiddenInput = styled$1(
|
|
25926
|
-
clipPath:
|
|
25945
|
+
const VisuallyHiddenInput = styled$1("input")({
|
|
25946
|
+
clipPath: "inset(50%)",
|
|
25927
25947
|
height: 1,
|
|
25928
|
-
overflow:
|
|
25929
|
-
position:
|
|
25948
|
+
overflow: "hidden",
|
|
25949
|
+
position: "absolute",
|
|
25930
25950
|
bottom: 0,
|
|
25931
25951
|
left: 0,
|
|
25932
|
-
whiteSpace:
|
|
25952
|
+
whiteSpace: "nowrap",
|
|
25933
25953
|
width: 1,
|
|
25934
25954
|
});
|
|
25935
25955
|
const FileUploadBox = (props) => {
|
|
@@ -25940,68 +25960,76 @@ const FileUploadBox = (props) => {
|
|
|
25940
25960
|
const [removerCSV, { isLoading: removerLoading }] = api.useRemoverCSVMutation();
|
|
25941
25961
|
const Dropzone = ({ onChange, value }) => {
|
|
25942
25962
|
const onDrop = useCallback((acceptedFiles) => {
|
|
25943
|
-
acceptedFiles.map(file => {
|
|
25944
|
-
const data = formDataForm({ });
|
|
25945
|
-
validarCSV({
|
|
25963
|
+
acceptedFiles.map((file) => {
|
|
25964
|
+
const data = formDataForm({ submitData: { archivo: file } });
|
|
25965
|
+
validarCSV({
|
|
25966
|
+
endpoint: props.csvProps.endpoint || "",
|
|
25967
|
+
data: data,
|
|
25968
|
+
custom: props.csvProps.custom,
|
|
25969
|
+
})
|
|
25970
|
+
.unwrap()
|
|
25946
25971
|
.then((response) => {
|
|
25947
|
-
onChange(
|
|
25972
|
+
onChange("archivo" in response ? response.archivo : acceptedFiles[0]);
|
|
25948
25973
|
setFile(acceptedFiles[0]);
|
|
25949
25974
|
props.setValid(true);
|
|
25950
25975
|
})
|
|
25951
25976
|
.catch((e) => {
|
|
25952
|
-
const columnas_inv = get(e.data,
|
|
25977
|
+
const columnas_inv = get(e.data, "columnas_invalidas");
|
|
25953
25978
|
if (columnas_inv)
|
|
25954
|
-
notifications.show(columnas_inv, { severity:
|
|
25979
|
+
notifications.show(columnas_inv, { severity: "error" });
|
|
25955
25980
|
props.setValid(false);
|
|
25956
25981
|
});
|
|
25957
25982
|
});
|
|
25958
25983
|
}, []);
|
|
25959
25984
|
const onDropRejected = useCallback(() => {
|
|
25960
|
-
notifications.show(
|
|
25985
|
+
notifications.show("Tipo de archivo inválido. Solo se aceptan CSVs.", {
|
|
25986
|
+
severity: "error",
|
|
25987
|
+
});
|
|
25961
25988
|
}, []);
|
|
25962
|
-
const { getRootProps, getInputProps, isDragActive
|
|
25989
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
25963
25990
|
onDrop,
|
|
25964
25991
|
onDropRejected,
|
|
25965
25992
|
accept: {
|
|
25966
|
-
|
|
25967
|
-
|
|
25993
|
+
"text/csv": [".csv"],
|
|
25994
|
+
"application/vnd.ms-excel": [".csv"],
|
|
25968
25995
|
},
|
|
25969
25996
|
maxFiles: 1,
|
|
25970
25997
|
multiple: false,
|
|
25971
25998
|
});
|
|
25972
25999
|
const handleRemove = () => {
|
|
25973
|
-
if (typeof value ==
|
|
26000
|
+
if (typeof value == "number") {
|
|
25974
26001
|
removerCSV({ id: value });
|
|
25975
26002
|
}
|
|
25976
26003
|
onChange(null);
|
|
25977
26004
|
setFile(null);
|
|
25978
26005
|
};
|
|
25979
|
-
return (jsx(Box$1, { width: 1, children: jsxs(Stack, { spacing: 2, children: [
|
|
25980
|
-
|
|
25981
|
-
|
|
25982
|
-
|
|
25983
|
-
|
|
25984
|
-
|
|
25985
|
-
|
|
25986
|
-
|
|
25987
|
-
|
|
25988
|
-
|
|
25989
|
-
|
|
25990
|
-
|
|
25991
|
-
|
|
25992
|
-
})] }) }));
|
|
26006
|
+
return (jsx(Box$1, { width: 1, children: jsxs(Stack, { spacing: 2, children: [!file && !isLoading && (jsxs(Box$1, { component: "div", width: 1, display: "flex", justifyContent: "center", alignItems: "center", border: "1.5px dashed", borderRadius: "12px", py: 4, px: 2, borderColor: grey[800], bgcolor: grey[50], ...getRootProps(), children: [jsx(VisuallyHiddenInput, { id: "file-upload", type: "file", ...getInputProps() }), jsx(FileUploadIcon, { sx: {
|
|
26007
|
+
color: grey[800],
|
|
26008
|
+
pr: 1,
|
|
26009
|
+
} }), jsx(Typography, { variant: "body2", sx: { color: grey[800] }, children: isDragActive
|
|
26010
|
+
? "Soltar archivo aquí."
|
|
26011
|
+
: "Arrastra un archivo aquí o haz clic para seleccionar uno." })] })), isLoading && (jsx(Box$1, { children: jsx(LinearProgress, { sx: { height: 5 } }) })), file && (jsx(FileBox, { file: file, handleRemove: handleRemove, loadingRemove: removerLoading })), error &&
|
|
26012
|
+
"data" in error &&
|
|
26013
|
+
Object.keys(error.data).map((row) => {
|
|
26014
|
+
if (typeof error.data[row] == "object") {
|
|
26015
|
+
return jsx(RowErrors, { row: row, data: error.data }, row);
|
|
26016
|
+
}
|
|
26017
|
+
return null;
|
|
26018
|
+
})] }) }));
|
|
25993
26019
|
};
|
|
25994
26020
|
return (jsx(Controller, { name: props.name, control: props.control, render: ({ field: { onChange, value } }) => {
|
|
25995
|
-
return
|
|
26021
|
+
return jsx(Dropzone, { onChange: onChange, value: value });
|
|
25996
26022
|
} }));
|
|
25997
26023
|
};
|
|
25998
26024
|
|
|
25999
26025
|
const schema = z.object({
|
|
26000
|
-
archivo: z.any()
|
|
26026
|
+
archivo: z.any(),
|
|
26001
26027
|
});
|
|
26002
26028
|
const CSVUpload = (props) => {
|
|
26003
26029
|
const api = useAPI();
|
|
26004
26030
|
const notifications = useNotifications();
|
|
26031
|
+
const { pathname } = useLocation();
|
|
26032
|
+
const endpoint = props.data?.endpoint || pathname;
|
|
26005
26033
|
const [valid, setValid] = useState(false);
|
|
26006
26034
|
const defaultValues = {
|
|
26007
26035
|
archivo: null,
|
|
@@ -26010,29 +26038,30 @@ const CSVUpload = (props) => {
|
|
|
26010
26038
|
resolver: zodResolver(schema),
|
|
26011
26039
|
defaultValues: defaultValues,
|
|
26012
26040
|
});
|
|
26013
|
-
const archivo = form.watch(
|
|
26041
|
+
const archivo = form.watch("archivo");
|
|
26014
26042
|
const [subirCSV, { isLoading }] = api.useSubirCSVMutation();
|
|
26015
26043
|
const handleClose = () => {
|
|
26016
26044
|
props.drawerToggle();
|
|
26017
26045
|
form.reset();
|
|
26018
26046
|
};
|
|
26019
|
-
const tag = useMemo(() =>
|
|
26047
|
+
const tag = useMemo(() => endpoint.split("/").at(-1), [endpoint]);
|
|
26020
26048
|
const onSubmitHandler = (submitData) => {
|
|
26021
|
-
const data = formDataForm(submitData);
|
|
26022
|
-
subirCSV({ endpoint
|
|
26049
|
+
const data = formDataForm({ submitData });
|
|
26050
|
+
subirCSV({ endpoint, tagType: tag, data, custom: props.data?.custom })
|
|
26051
|
+
.unwrap()
|
|
26023
26052
|
.then((response) => {
|
|
26024
26053
|
if (props.postAction)
|
|
26025
26054
|
props.postAction(response);
|
|
26026
26055
|
handleClose();
|
|
26027
|
-
notifications.show(
|
|
26056
|
+
notifications.show("Archivo subido exitosamente!", { severity: "success" });
|
|
26028
26057
|
})
|
|
26029
26058
|
.catch(() => {
|
|
26030
|
-
notifications.show(
|
|
26059
|
+
notifications.show("Error!", { severity: "error" });
|
|
26031
26060
|
});
|
|
26032
26061
|
};
|
|
26033
26062
|
const onError = (errors) => {
|
|
26034
26063
|
console.log(errors);
|
|
26035
|
-
notifications.show(`Error en: ${Object.keys(errors).join(
|
|
26064
|
+
notifications.show(`Error en: ${Object.keys(errors).join(", ")}!`, { severity: "error" });
|
|
26036
26065
|
};
|
|
26037
26066
|
const handleDownload = () => {
|
|
26038
26067
|
const link = document.createElement("a");
|
|
@@ -26040,7 +26069,7 @@ const CSVUpload = (props) => {
|
|
|
26040
26069
|
link.href = `/plantillas/plantilla_${tag}.xlsx`;
|
|
26041
26070
|
link.click();
|
|
26042
26071
|
};
|
|
26043
|
-
return (jsxs(MainDrawer, { open: props.open, drawerToggle: handleClose, title: props.data?.title ||
|
|
26072
|
+
return (jsxs(MainDrawer, { open: props.open, drawerToggle: handleClose, title: props.data?.title || "CSV", slots: {
|
|
26044
26073
|
button: (jsx(SaveCancelButton, { slotProps: {
|
|
26045
26074
|
saveBtn: {
|
|
26046
26075
|
loading: isLoading,
|
|
@@ -26048,11 +26077,11 @@ const CSVUpload = (props) => {
|
|
|
26048
26077
|
},
|
|
26049
26078
|
cancelBtn: {
|
|
26050
26079
|
onClick: handleClose,
|
|
26051
|
-
}
|
|
26052
|
-
} }))
|
|
26053
|
-
}, children: [jsxs(Box, { px: 2, py: 3, bgcolor: grey[50], borderRadius:
|
|
26054
|
-
minWidth: 120
|
|
26055
|
-
}, children: "Descargar" })] })] }), jsx(Box, { id:
|
|
26080
|
+
},
|
|
26081
|
+
} })),
|
|
26082
|
+
}, children: [jsxs(Box, { px: 2, py: 3, bgcolor: grey[50], borderRadius: "12px", children: [jsx(Typography$1, { fontWeight: "bold", children: "Archivo de Muestra" }), jsxs(Stack, { direction: "row", spacing: 2, children: [jsx(Typography$1, { variant: "body2", children: "Puede descargar el ejemplo adjunto y utilizarlo como punto de partida para su propio archivo." }), jsx(Button, { variant: "contained", startIcon: jsx(DownloadIcon, {}), onClick: handleDownload, sx: {
|
|
26083
|
+
minWidth: 120,
|
|
26084
|
+
}, children: "Descargar" })] })] }), jsx(Box, { id: "formulario", component: "form", width: 1, autoComplete: "off", noValidate: true, onSubmit: form.handleSubmit(onSubmitHandler, onError), children: jsx(FileUploadBox, { name: "archivo", control: form.control, setValid: setValid, csvProps: props.data }) })] }));
|
|
26056
26085
|
};
|
|
26057
26086
|
|
|
26058
26087
|
const mergeSettings = (baseSettings, mergingSettings) => {
|
|
@@ -26676,7 +26705,6 @@ const StyledMenu = styled$1((props) => (jsx(Menu, { elevation: 0, anchorOrigin:
|
|
|
26676
26705
|
}));
|
|
26677
26706
|
|
|
26678
26707
|
const CreateButtonWithMenuOptions = (props) => {
|
|
26679
|
-
// const permission = useHasPermission_v2(`${props.permission}.add`);
|
|
26680
26708
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
26681
26709
|
const open = Boolean(anchorEl);
|
|
26682
26710
|
const handleClick = () => {
|
|
@@ -26692,7 +26720,8 @@ const CreateButtonWithMenuOptions = (props) => {
|
|
|
26692
26720
|
const handleToggleClose = () => {
|
|
26693
26721
|
setCSV({ open: false });
|
|
26694
26722
|
};
|
|
26695
|
-
|
|
26723
|
+
if (!props.permission)
|
|
26724
|
+
return null;
|
|
26696
26725
|
return (jsxs(Fragment, { children: [jsx(CreateButtonBase, { open: open, handleClick: handleClick }), jsxs(StyledMenu, { id: 'create-menu', MenuListProps: {
|
|
26697
26726
|
'aria-labelledby': 'create-menu-button',
|
|
26698
26727
|
}, anchorEl: anchorEl, open: open, onClose: handleClose, children: [props.csv_upload?.enable && ([
|
|
@@ -27112,37 +27141,33 @@ const FiltersButton = (props) => {
|
|
|
27112
27141
|
};
|
|
27113
27142
|
|
|
27114
27143
|
const ExportCSV = (props) => {
|
|
27115
|
-
|
|
27116
|
-
|
|
27117
|
-
|
|
27118
|
-
|
|
27144
|
+
const { pathname } = useLocation();
|
|
27145
|
+
const endpoint = props.slots?.endpoint || pathname;
|
|
27146
|
+
const notifications = useNotifications();
|
|
27147
|
+
const api = useAPI();
|
|
27148
|
+
const [descargarCSV, { isLoading }] = api.useLazyDescargarCSVQuery();
|
|
27119
27149
|
const handleClick = () => {
|
|
27120
27150
|
const extraItems = { variant: props.slots?.variant };
|
|
27121
27151
|
if (props.rowSelectionModel.ids.size > 0)
|
|
27122
27152
|
extraItems[`${props.slots?.column_key || 'id'}__in`] = Array.from(props.rowSelectionModel.ids).join(',');
|
|
27123
|
-
|
|
27124
|
-
|
|
27125
|
-
|
|
27126
|
-
|
|
27127
|
-
|
|
27128
|
-
|
|
27129
|
-
|
|
27130
|
-
|
|
27131
|
-
|
|
27132
|
-
|
|
27133
|
-
|
|
27134
|
-
|
|
27135
|
-
|
|
27136
|
-
|
|
27137
|
-
|
|
27138
|
-
|
|
27139
|
-
// })
|
|
27140
|
-
// .catch((error) => {
|
|
27141
|
-
// console.log(error)
|
|
27142
|
-
// notifications.show('Error al descargar CSV.', {severity: 'error'});
|
|
27143
|
-
// })
|
|
27153
|
+
const filters = merge$2({}, omit(props.filterModel, map(props.ignore?.filters, function (filter) { return `items.${filter}`; }) || []), { items: extraItems });
|
|
27154
|
+
descargarCSV({
|
|
27155
|
+
endpoint: endpoint, filterModel: filters, sortModel: props.sortModel, ignoreSort: props.ignore?.sort,
|
|
27156
|
+
}).unwrap()
|
|
27157
|
+
.then((response) => {
|
|
27158
|
+
const file = document.createElement("a");
|
|
27159
|
+
file.href = response.file;
|
|
27160
|
+
file.download = response.filename;
|
|
27161
|
+
file.click();
|
|
27162
|
+
notifications.show('CSV descargado!', { severity: 'success' });
|
|
27163
|
+
props.handleClick();
|
|
27164
|
+
})
|
|
27165
|
+
.catch((error) => {
|
|
27166
|
+
console.log(error);
|
|
27167
|
+
notifications.show('Error al descargar CSV.', { severity: 'error' });
|
|
27168
|
+
});
|
|
27144
27169
|
};
|
|
27145
|
-
return (jsx(MenuItemWithLoading, { handleClick: handleClick, isLoading:
|
|
27170
|
+
return (jsx(MenuItemWithLoading, { handleClick: handleClick, isLoading: isLoading, disabled: props.disabledWithoutSelection && !props.rowSelectionModel.ids.size, children: props.slots?.title || 'Descargar como CSV' }, 'export-dg-csv'));
|
|
27146
27171
|
};
|
|
27147
27172
|
|
|
27148
27173
|
const ExportButton = (props) => {
|
|
@@ -27162,11 +27187,10 @@ const ExportButton = (props) => {
|
|
|
27162
27187
|
handleClick: () => setExportMenuOpen(false),
|
|
27163
27188
|
filterModel: props.filterModel,
|
|
27164
27189
|
sortModel: props.sortModel,
|
|
27190
|
+
rowSelectionModel: props.rowSelectionModel,
|
|
27165
27191
|
csvExport: {
|
|
27166
|
-
rowSelectionModel: props.rowSelectionModel,
|
|
27167
27192
|
...csvExport,
|
|
27168
27193
|
},
|
|
27169
|
-
endpoint: props.csvProps?.endpoint,
|
|
27170
27194
|
...remainingProps,
|
|
27171
27195
|
}));
|
|
27172
27196
|
})] })] }));
|
|
@@ -27568,14 +27592,20 @@ const Base = (props) => {
|
|
|
27568
27592
|
setFilterModel: setFilterModel,
|
|
27569
27593
|
}));
|
|
27570
27594
|
// ========================= || PAGINADO || ========================= //
|
|
27571
|
-
const [paginationModel, setPaginationModel] = useState({
|
|
27595
|
+
const [paginationModel, setPaginationModel] = useState({
|
|
27596
|
+
page: 0,
|
|
27597
|
+
pageSize: 50,
|
|
27598
|
+
});
|
|
27572
27599
|
// ========================= || ORDENADO || ========================= //
|
|
27573
27600
|
const [sortModel, setSortModel] = useState([]);
|
|
27574
27601
|
// ========================= || FILTRADO || ========================= //
|
|
27575
|
-
const [filterModel, setFilterModel] = useState({
|
|
27602
|
+
const [filterModel, setFilterModel] = useState({
|
|
27603
|
+
items: {},
|
|
27604
|
+
quickFilterValues: "",
|
|
27605
|
+
});
|
|
27576
27606
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27577
27607
|
const setQuickSearchValue = useCallback(debounce$1((quickSearch) => {
|
|
27578
|
-
setFilterModel(prevState => ({ ...prevState, quickFilterValues: quickSearch }));
|
|
27608
|
+
setFilterModel((prevState) => ({ ...prevState, quickFilterValues: quickSearch }));
|
|
27579
27609
|
}, 500), []);
|
|
27580
27610
|
// ========================= || COLUMNAS || ========================= //
|
|
27581
27611
|
const getTogglableColumns = (columns) => {
|
|
@@ -27583,7 +27613,7 @@ const Base = (props) => {
|
|
|
27583
27613
|
return [];
|
|
27584
27614
|
return columns
|
|
27585
27615
|
.filter((column) => {
|
|
27586
|
-
return ![
|
|
27616
|
+
return !["__check__", "actions"].includes(column.field);
|
|
27587
27617
|
})
|
|
27588
27618
|
.map((column) => column.field);
|
|
27589
27619
|
};
|
|
@@ -27595,7 +27625,7 @@ const Base = (props) => {
|
|
|
27595
27625
|
// ========================= || LAZY QUERY || ========================= //
|
|
27596
27626
|
const [query, { data, isLoading, isFetching, isError, isUninitialized }] = props.api.data.query(props.api.data.options || {});
|
|
27597
27627
|
// ========================= || INITIAL STATE || ========================= //
|
|
27598
|
-
const localStoreName = useMemo(() => `${props.pathname}${props.slotProps?.tab ? `_${props.slotProps?.tab}` :
|
|
27628
|
+
const localStoreName = useMemo(() => `${props.pathname}${props.slotProps?.tab ? `_${props.slotProps?.tab}` : ""}_DG`, [props.pathname, props.slotProps?.tab]);
|
|
27599
27629
|
const internalFilterRef = useRef(filterModel);
|
|
27600
27630
|
const filterRef = props.slotProps?.filtersRef || internalFilterRef;
|
|
27601
27631
|
useEffect(() => {
|
|
@@ -27605,28 +27635,30 @@ const Base = (props) => {
|
|
|
27605
27635
|
const saveSnapshot = useCallback(() => {
|
|
27606
27636
|
if (apiRef?.current?.exportState && localStorage && !props.slotProps?.dontSaveState) {
|
|
27607
27637
|
const currentState = apiRef.current.exportState();
|
|
27608
|
-
set$1(currentState,
|
|
27638
|
+
set$1(currentState, "filters.filterModel", filterRef.current);
|
|
27609
27639
|
setWithExpiry(localStoreName, currentState, 86400000);
|
|
27610
27640
|
}
|
|
27611
27641
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27612
27642
|
}, [apiRef, props.pathname]);
|
|
27613
27643
|
useLayoutEffect(() => {
|
|
27614
27644
|
const stateFromLocalStorage = getWithExpiry(localStoreName);
|
|
27615
|
-
const init = stateFromLocalStorage
|
|
27616
|
-
|
|
27617
|
-
|
|
27618
|
-
const
|
|
27645
|
+
const init = stateFromLocalStorage
|
|
27646
|
+
? stateFromLocalStorage
|
|
27647
|
+
: get(props, "dataGridProps.initialState", {});
|
|
27648
|
+
const pagination = get(init, "pagination.paginationModel", paginationModel);
|
|
27649
|
+
const sorting = get(init, "sorting.sortModel", sortModel);
|
|
27650
|
+
const filters = get(init, "filters.filterModel", filterModel);
|
|
27619
27651
|
setPaginationModel(pagination);
|
|
27620
27652
|
setSortModel(sorting);
|
|
27621
27653
|
setFilterModel(filters);
|
|
27622
|
-
setColumnVisibilityModel(get(init,
|
|
27654
|
+
setColumnVisibilityModel(get(init, "columns.columnVisibilityModel", columnVisibilityModel));
|
|
27623
27655
|
// handle refresh and navigating away/refreshing
|
|
27624
|
-
window.addEventListener(
|
|
27656
|
+
window.addEventListener("beforeunload", saveSnapshot);
|
|
27625
27657
|
// console.log(getQueryArgs(pagination, sorting, filters, props.api.data.args))
|
|
27626
27658
|
query(getQueryArgs(pagination, sorting, filters, props.api.data.args));
|
|
27627
27659
|
return () => {
|
|
27628
27660
|
// in case of an SPA remove the event-listener
|
|
27629
|
-
window.removeEventListener(
|
|
27661
|
+
window.removeEventListener("beforeunload", saveSnapshot);
|
|
27630
27662
|
saveSnapshot();
|
|
27631
27663
|
};
|
|
27632
27664
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -27645,8 +27677,8 @@ const Base = (props) => {
|
|
|
27645
27677
|
};
|
|
27646
27678
|
// ========================= || SELECCIÓN || ========================= //
|
|
27647
27679
|
const [rowSelectionModel, setRowSelectionModel] = useState({
|
|
27648
|
-
type:
|
|
27649
|
-
ids: new Set()
|
|
27680
|
+
type: "include",
|
|
27681
|
+
ids: new Set(),
|
|
27650
27682
|
});
|
|
27651
27683
|
const handleRowSelectionModelChange = (newSelection) => {
|
|
27652
27684
|
setRowSelectionModel(newSelection);
|
|
@@ -27664,13 +27696,13 @@ const Base = (props) => {
|
|
|
27664
27696
|
const handleRowClick = ({ id }, event) => {
|
|
27665
27697
|
const link_to = `${props.slotProps?.navigation != undefined ? props.slotProps?.navigation : props.pathname}/${id}`;
|
|
27666
27698
|
if (event.ctrlKey) {
|
|
27667
|
-
const newTab = document.createElement(
|
|
27699
|
+
const newTab = document.createElement("a");
|
|
27668
27700
|
newTab.href = link_to;
|
|
27669
|
-
newTab.target =
|
|
27701
|
+
newTab.target = "_blank";
|
|
27670
27702
|
newTab.click();
|
|
27671
27703
|
}
|
|
27672
27704
|
else {
|
|
27673
|
-
navigate(`${props.slotProps?.navigation ? props.slotProps?.navigation : props.pathname}/${id}`);
|
|
27705
|
+
navigate(`${props.slotProps?.navigation || props.slotProps?.navigation === "" ? props.slotProps?.navigation : props.pathname}/${id}`);
|
|
27674
27706
|
}
|
|
27675
27707
|
};
|
|
27676
27708
|
const handleRowEditStop = (params, event) => {
|
|
@@ -27689,13 +27721,13 @@ const Base = (props) => {
|
|
|
27689
27721
|
},
|
|
27690
27722
|
slotProps: {
|
|
27691
27723
|
baseCheckbox: {
|
|
27692
|
-
size:
|
|
27724
|
+
size: "small",
|
|
27693
27725
|
},
|
|
27694
27726
|
toolbar: {
|
|
27695
27727
|
filters: {
|
|
27696
27728
|
filterModel: filterModel,
|
|
27697
27729
|
setFilterModel: setFilterModel,
|
|
27698
|
-
setQuickSearchValue: setQuickSearchValue
|
|
27730
|
+
setQuickSearchValue: setQuickSearchValue,
|
|
27699
27731
|
},
|
|
27700
27732
|
protectFilters: props.api.data.protectFilters,
|
|
27701
27733
|
columnsFilter: props.slotProps?.columnsFilter,
|
|
@@ -27706,27 +27738,27 @@ const Base = (props) => {
|
|
|
27706
27738
|
buttons: {
|
|
27707
27739
|
refresh: {
|
|
27708
27740
|
refetch: handleRefetch,
|
|
27709
|
-
}
|
|
27710
|
-
}
|
|
27741
|
+
},
|
|
27742
|
+
},
|
|
27711
27743
|
},
|
|
27712
27744
|
columnsManagement: {
|
|
27713
27745
|
getTogglableColumns: getTogglableColumns,
|
|
27714
27746
|
},
|
|
27715
27747
|
},
|
|
27716
27748
|
}, props.dataGridProps);
|
|
27717
|
-
const renderDataGrid = ({ dataGridProps: renderDataGridProps }) => {
|
|
27749
|
+
const renderDataGrid = ({ dataGridProps: renderDataGridProps, }) => {
|
|
27718
27750
|
// console.log(dataGridProps)
|
|
27719
27751
|
return (jsx(Box, { width: 1, minHeight: 300, height: 1,
|
|
27720
27752
|
// maxHeight={'calc(100% - 30px)'}
|
|
27721
|
-
display:
|
|
27753
|
+
display: "flex", flexDirection: "column", pb: 0, children: jsx(NoSsr, { children: jsx(DataGrid, { apiRef: apiRef, rows: data?.results || [], loading: some(get(renderDataGridProps, "loadingParams", []), function (x) {
|
|
27722
27754
|
return x;
|
|
27723
27755
|
}),
|
|
27724
27756
|
// paginado //
|
|
27725
|
-
pagination: true, paginationMode:
|
|
27757
|
+
pagination: true, paginationMode: "server", paginationModel: paginationModel, onPaginationModelChange: setPaginationModel, pageSizeOptions: [50, 100, { value: -1, label: "Todos" }],
|
|
27726
27758
|
// ordenado
|
|
27727
|
-
sortingMode:
|
|
27759
|
+
sortingMode: "server", sortModel: sortModel, onSortModelChange: setSortModel,
|
|
27728
27760
|
// filtrado
|
|
27729
|
-
filterMode:
|
|
27761
|
+
filterMode: "server",
|
|
27730
27762
|
// onFilterModelChange={handleFilterChange}
|
|
27731
27763
|
disableColumnFilter: true, showToolbar: true,
|
|
27732
27764
|
// selection
|
|
@@ -27744,13 +27776,13 @@ const Base = (props) => {
|
|
|
27744
27776
|
// row count
|
|
27745
27777
|
rowCount: rowCount,
|
|
27746
27778
|
// settings
|
|
27747
|
-
density:
|
|
27779
|
+
density: "compact",
|
|
27748
27780
|
// striping
|
|
27749
|
-
getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ?
|
|
27750
|
-
columnHeaderSortIconLabel:
|
|
27751
|
-
columnMenuSortAsc:
|
|
27752
|
-
columnMenuSortDesc:
|
|
27753
|
-
columnMenuLabel:
|
|
27781
|
+
getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ? "even" : "odd", localeText: {
|
|
27782
|
+
columnHeaderSortIconLabel: "Ordenar",
|
|
27783
|
+
columnMenuSortAsc: "Ordenar de menor a mayor",
|
|
27784
|
+
columnMenuSortDesc: "Ordenar de mayor a menor",
|
|
27785
|
+
columnMenuLabel: "Menú",
|
|
27754
27786
|
}, ...renderDataGridProps }) }) }));
|
|
27755
27787
|
};
|
|
27756
27788
|
// ========================= || RETURN || ========================= //
|
|
@@ -27764,7 +27796,7 @@ const Base = (props) => {
|
|
|
27764
27796
|
pathname: props.pathname,
|
|
27765
27797
|
navigation: props.slotProps?.navigation,
|
|
27766
27798
|
...renderProps,
|
|
27767
|
-
...props.api.create
|
|
27799
|
+
...props.api.create,
|
|
27768
27800
|
};
|
|
27769
27801
|
renderFunction = CreateGridWrapper;
|
|
27770
27802
|
}
|
|
@@ -27775,7 +27807,7 @@ const Base = (props) => {
|
|
|
27775
27807
|
renderFunctionProps: renderProps,
|
|
27776
27808
|
dataGridProps: dataGridProps,
|
|
27777
27809
|
baseGridRef: apiRef,
|
|
27778
|
-
...props.api.edit
|
|
27810
|
+
...props.api.edit,
|
|
27779
27811
|
};
|
|
27780
27812
|
renderFunction = EditGridWrapper;
|
|
27781
27813
|
}
|
|
@@ -27785,7 +27817,7 @@ const Base = (props) => {
|
|
|
27785
27817
|
renderFunction: renderFunction,
|
|
27786
27818
|
renderFunctionProps: renderProps,
|
|
27787
27819
|
dataGridProps: dataGridProps,
|
|
27788
|
-
...props.api.delete
|
|
27820
|
+
...props.api.delete,
|
|
27789
27821
|
});
|
|
27790
27822
|
}
|
|
27791
27823
|
return renderFunction(renderProps);
|
|
@@ -28309,15 +28341,12 @@ function DetailPage(props) {
|
|
|
28309
28341
|
else {
|
|
28310
28342
|
console.log(error);
|
|
28311
28343
|
setErrors(form, error);
|
|
28312
|
-
notifications.show((
|
|
28313
|
-
error.data.
|
|
28344
|
+
notifications.show((error.data.detail ?
|
|
28345
|
+
error.data.detail.join(', ') :
|
|
28314
28346
|
`Error ${props.pageType == 'edit' ? 'actualizando' : 'creando'} ${props.object.name}!`), { severity: 'error' });
|
|
28315
28347
|
}
|
|
28316
28348
|
});
|
|
28317
28349
|
};
|
|
28318
|
-
const onError = (errors) => {
|
|
28319
|
-
console.log(errors);
|
|
28320
|
-
};
|
|
28321
28350
|
// ==============================|| RENDER SECTIONS ||============================== //
|
|
28322
28351
|
const renderContent = () => {
|
|
28323
28352
|
let displayed_sections = -1;
|
|
@@ -28373,7 +28402,7 @@ function DetailPage(props) {
|
|
|
28373
28402
|
}
|
|
28374
28403
|
};
|
|
28375
28404
|
return (jsxs(Fragment, { children: [jsx(ContentLayout, { button: renderButton(), badge: props.pageType == 'detail' && badgeInfo &&
|
|
28376
|
-
jsx(StatusBadge, { title: badgeInfo['label'], severity: badgeInfo['value'] }), children: jsx(LoadingComponent, { height: 0.7, isLoading: isLoading || isFetching, children: jsx(FormProvider, { ...form, children: jsx(Box, { id: 'formulario', component: 'form', autoComplete: "off", noValidate: true, onSubmit: form.handleSubmit(onSubmitHandler
|
|
28405
|
+
jsx(StatusBadge, { title: badgeInfo['label'], severity: badgeInfo['value'] }), children: jsx(LoadingComponent, { height: 0.7, isLoading: isLoading || isFetching, children: jsx(FormProvider, { ...form, children: jsx(Box, { id: 'formulario', component: 'form', autoComplete: "off", noValidate: true, onSubmit: form.handleSubmit(onSubmitHandler), width: '100%', position: 'relative', children: renderContent() }) }) }) }), renderPostAction()] }));
|
|
28377
28406
|
}
|
|
28378
28407
|
|
|
28379
28408
|
const ListPage = (props) => {
|
|
@@ -28665,5 +28694,5 @@ const theme = () => {
|
|
|
28665
28694
|
return themes;
|
|
28666
28695
|
};
|
|
28667
28696
|
|
|
28668
|
-
export { APIContext, APIProvider, ActiveCell, Base, ButtonWithDrawer, CSVUpload, ContentLayout, ControlledDate, ControlledDropdown, FileUploadBox as ControlledFileUploadBox, ControlledNumber, ControlledPhoneNumber, ControlledPhotoField, ControlledSelect, ControlledSlider as ControlledSimpleSlider, ControlledSlider$1 as ControlledSlider, ControlledSwitch, ControlledText, ControlledTimePicker, ControlledToggleButtons, CoverPage, CreateButtonBase, CreateButtonWithMenuOptions, DeleteButton, DeleteConfirmationDialog, DetailPage, EditButton, HistorialDrawer, ListPage, Loadable, LoadingComponent, Logo, MainDrawer, MenuItemWithLoading, ModuleCard, MyGridEditSingleSelect, NavigationContext, NavigationProvider, NormalOrIcon, NotAllowed, NotFound, ObjectProgressStack, SaveCancelButton, StatusBadge, StyledMenu, Tabs, Transitions, UncontrolledText, changeTitle, closeProgressSnack, dayjs, deleteColumn, editColumn, filterQuery, formDataForm, header as headerReducer, jsonForm, manualCacheRefresh, mergeSettings, openProgressSnack, query, renderEditCellWithErrorTooltip, setErrors, snackProgress_default as snackProgressReducer, tags, theme, updateProgressSnackData, useAPI, useHasPermission, useNavigation, valueLabel };
|
|
28697
|
+
export { APIContext, APIProvider, ActiveCell, Base, ButtonWithDrawer, CSVUpload, ContentLayout, ControlledDate, ControlledDropdown, FileUploadBox as ControlledFileUploadBox, ControlledNumber, ControlledPhoneNumber, ControlledPhotoField, ControlledSelect, ControlledSlider as ControlledSimpleSlider, ControlledSlider$1 as ControlledSlider, ControlledSwitch, ControlledText, ControlledTimePicker, ControlledToggleButtons, CoverPage, CreateButtonBase, CreateButtonWithMenuOptions, DeleteButton, DeleteConfirmationDialog, DetailPage, EditButton, ExportCSV, HistorialDrawer, ListPage, Loadable, LoadingComponent, Logo, MainDrawer, MenuItemWithLoading, ModuleCard, MyGridEditSingleSelect, NavigationContext, NavigationProvider, NormalOrIcon, NotAllowed, NotFound, ObjectProgressStack, SaveCancelButton, StatusBadge, StyledMenu, Tabs, Transitions, UncontrolledText, changeTitle, closeProgressSnack, dayjs, deleteColumn, editColumn, filterQuery, formDataForm, header as headerReducer, jsonForm, manualCacheRefresh, mergeSettings, openProgressSnack, query, renderEditCellWithErrorTooltip, setErrors, snackProgress_default as snackProgressReducer, tags, theme, updateProgressSnackData, useAPI, useHasPermission, useNavigation, valueLabel };
|
|
28669
28698
|
//# sourceMappingURL=index.js.map
|