@acvl/frontend-components 0.0.24 → 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 +175 -135
- 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 -1
- package/dist/esm/index.js +175 -135
- 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 -1
- package/dist/index.d.ts +20 -5
- 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,16 +25790,16 @@ 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
25799
|
const setErrors = (form, error) => {
|
|
25772
|
-
if (
|
|
25800
|
+
if ("invalid_params" in error.data) {
|
|
25773
25801
|
Object.values(error.data.invalid_params).forEach((entry) => {
|
|
25774
|
-
form.setError(entry.name, { message: entry.reason.join(
|
|
25802
|
+
form.setError(entry.name, { message: entry.reason.join(", ") });
|
|
25775
25803
|
});
|
|
25776
25804
|
}
|
|
25777
25805
|
};
|
|
@@ -25914,14 +25942,14 @@ const FileBox = (props) => {
|
|
|
25914
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, {}) }) })) })] }));
|
|
25915
25943
|
};
|
|
25916
25944
|
|
|
25917
|
-
const VisuallyHiddenInput = styled$1(
|
|
25918
|
-
clipPath:
|
|
25945
|
+
const VisuallyHiddenInput = styled$1("input")({
|
|
25946
|
+
clipPath: "inset(50%)",
|
|
25919
25947
|
height: 1,
|
|
25920
|
-
overflow:
|
|
25921
|
-
position:
|
|
25948
|
+
overflow: "hidden",
|
|
25949
|
+
position: "absolute",
|
|
25922
25950
|
bottom: 0,
|
|
25923
25951
|
left: 0,
|
|
25924
|
-
whiteSpace:
|
|
25952
|
+
whiteSpace: "nowrap",
|
|
25925
25953
|
width: 1,
|
|
25926
25954
|
});
|
|
25927
25955
|
const FileUploadBox = (props) => {
|
|
@@ -25932,68 +25960,76 @@ const FileUploadBox = (props) => {
|
|
|
25932
25960
|
const [removerCSV, { isLoading: removerLoading }] = api.useRemoverCSVMutation();
|
|
25933
25961
|
const Dropzone = ({ onChange, value }) => {
|
|
25934
25962
|
const onDrop = useCallback((acceptedFiles) => {
|
|
25935
|
-
acceptedFiles.map(file => {
|
|
25936
|
-
const data = formDataForm({ });
|
|
25937
|
-
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()
|
|
25938
25971
|
.then((response) => {
|
|
25939
|
-
onChange(
|
|
25972
|
+
onChange("archivo" in response ? response.archivo : acceptedFiles[0]);
|
|
25940
25973
|
setFile(acceptedFiles[0]);
|
|
25941
25974
|
props.setValid(true);
|
|
25942
25975
|
})
|
|
25943
25976
|
.catch((e) => {
|
|
25944
|
-
const columnas_inv = get(e.data,
|
|
25977
|
+
const columnas_inv = get(e.data, "columnas_invalidas");
|
|
25945
25978
|
if (columnas_inv)
|
|
25946
|
-
notifications.show(columnas_inv, { severity:
|
|
25979
|
+
notifications.show(columnas_inv, { severity: "error" });
|
|
25947
25980
|
props.setValid(false);
|
|
25948
25981
|
});
|
|
25949
25982
|
});
|
|
25950
25983
|
}, []);
|
|
25951
25984
|
const onDropRejected = useCallback(() => {
|
|
25952
|
-
notifications.show(
|
|
25985
|
+
notifications.show("Tipo de archivo inválido. Solo se aceptan CSVs.", {
|
|
25986
|
+
severity: "error",
|
|
25987
|
+
});
|
|
25953
25988
|
}, []);
|
|
25954
|
-
const { getRootProps, getInputProps, isDragActive
|
|
25989
|
+
const { getRootProps, getInputProps, isDragActive } = useDropzone({
|
|
25955
25990
|
onDrop,
|
|
25956
25991
|
onDropRejected,
|
|
25957
25992
|
accept: {
|
|
25958
|
-
|
|
25959
|
-
|
|
25993
|
+
"text/csv": [".csv"],
|
|
25994
|
+
"application/vnd.ms-excel": [".csv"],
|
|
25960
25995
|
},
|
|
25961
25996
|
maxFiles: 1,
|
|
25962
25997
|
multiple: false,
|
|
25963
25998
|
});
|
|
25964
25999
|
const handleRemove = () => {
|
|
25965
|
-
if (typeof value ==
|
|
26000
|
+
if (typeof value == "number") {
|
|
25966
26001
|
removerCSV({ id: value });
|
|
25967
26002
|
}
|
|
25968
26003
|
onChange(null);
|
|
25969
26004
|
setFile(null);
|
|
25970
26005
|
};
|
|
25971
|
-
return (jsx(Box$1, { width: 1, children: jsxs(Stack, { spacing: 2, children: [
|
|
25972
|
-
|
|
25973
|
-
|
|
25974
|
-
|
|
25975
|
-
|
|
25976
|
-
|
|
25977
|
-
|
|
25978
|
-
|
|
25979
|
-
|
|
25980
|
-
|
|
25981
|
-
|
|
25982
|
-
|
|
25983
|
-
|
|
25984
|
-
})] }) }));
|
|
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
|
+
})] }) }));
|
|
25985
26019
|
};
|
|
25986
26020
|
return (jsx(Controller, { name: props.name, control: props.control, render: ({ field: { onChange, value } }) => {
|
|
25987
|
-
return
|
|
26021
|
+
return jsx(Dropzone, { onChange: onChange, value: value });
|
|
25988
26022
|
} }));
|
|
25989
26023
|
};
|
|
25990
26024
|
|
|
25991
26025
|
const schema = z.object({
|
|
25992
|
-
archivo: z.any()
|
|
26026
|
+
archivo: z.any(),
|
|
25993
26027
|
});
|
|
25994
26028
|
const CSVUpload = (props) => {
|
|
25995
26029
|
const api = useAPI();
|
|
25996
26030
|
const notifications = useNotifications();
|
|
26031
|
+
const { pathname } = useLocation();
|
|
26032
|
+
const endpoint = props.data?.endpoint || pathname;
|
|
25997
26033
|
const [valid, setValid] = useState(false);
|
|
25998
26034
|
const defaultValues = {
|
|
25999
26035
|
archivo: null,
|
|
@@ -26002,29 +26038,30 @@ const CSVUpload = (props) => {
|
|
|
26002
26038
|
resolver: zodResolver(schema),
|
|
26003
26039
|
defaultValues: defaultValues,
|
|
26004
26040
|
});
|
|
26005
|
-
const archivo = form.watch(
|
|
26041
|
+
const archivo = form.watch("archivo");
|
|
26006
26042
|
const [subirCSV, { isLoading }] = api.useSubirCSVMutation();
|
|
26007
26043
|
const handleClose = () => {
|
|
26008
26044
|
props.drawerToggle();
|
|
26009
26045
|
form.reset();
|
|
26010
26046
|
};
|
|
26011
|
-
const tag = useMemo(() =>
|
|
26047
|
+
const tag = useMemo(() => endpoint.split("/").at(-1), [endpoint]);
|
|
26012
26048
|
const onSubmitHandler = (submitData) => {
|
|
26013
|
-
const data = formDataForm(submitData);
|
|
26014
|
-
subirCSV({ endpoint
|
|
26049
|
+
const data = formDataForm({ submitData });
|
|
26050
|
+
subirCSV({ endpoint, tagType: tag, data, custom: props.data?.custom })
|
|
26051
|
+
.unwrap()
|
|
26015
26052
|
.then((response) => {
|
|
26016
26053
|
if (props.postAction)
|
|
26017
26054
|
props.postAction(response);
|
|
26018
26055
|
handleClose();
|
|
26019
|
-
notifications.show(
|
|
26056
|
+
notifications.show("Archivo subido exitosamente!", { severity: "success" });
|
|
26020
26057
|
})
|
|
26021
26058
|
.catch(() => {
|
|
26022
|
-
notifications.show(
|
|
26059
|
+
notifications.show("Error!", { severity: "error" });
|
|
26023
26060
|
});
|
|
26024
26061
|
};
|
|
26025
26062
|
const onError = (errors) => {
|
|
26026
26063
|
console.log(errors);
|
|
26027
|
-
notifications.show(`Error en: ${Object.keys(errors).join(
|
|
26064
|
+
notifications.show(`Error en: ${Object.keys(errors).join(", ")}!`, { severity: "error" });
|
|
26028
26065
|
};
|
|
26029
26066
|
const handleDownload = () => {
|
|
26030
26067
|
const link = document.createElement("a");
|
|
@@ -26032,7 +26069,7 @@ const CSVUpload = (props) => {
|
|
|
26032
26069
|
link.href = `/plantillas/plantilla_${tag}.xlsx`;
|
|
26033
26070
|
link.click();
|
|
26034
26071
|
};
|
|
26035
|
-
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: {
|
|
26036
26073
|
button: (jsx(SaveCancelButton, { slotProps: {
|
|
26037
26074
|
saveBtn: {
|
|
26038
26075
|
loading: isLoading,
|
|
@@ -26040,11 +26077,11 @@ const CSVUpload = (props) => {
|
|
|
26040
26077
|
},
|
|
26041
26078
|
cancelBtn: {
|
|
26042
26079
|
onClick: handleClose,
|
|
26043
|
-
}
|
|
26044
|
-
} }))
|
|
26045
|
-
}, children: [jsxs(Box, { px: 2, py: 3, bgcolor: grey[50], borderRadius:
|
|
26046
|
-
minWidth: 120
|
|
26047
|
-
}, 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 }) })] }));
|
|
26048
26085
|
};
|
|
26049
26086
|
|
|
26050
26087
|
const mergeSettings = (baseSettings, mergingSettings) => {
|
|
@@ -26668,7 +26705,6 @@ const StyledMenu = styled$1((props) => (jsx(Menu, { elevation: 0, anchorOrigin:
|
|
|
26668
26705
|
}));
|
|
26669
26706
|
|
|
26670
26707
|
const CreateButtonWithMenuOptions = (props) => {
|
|
26671
|
-
// const permission = useHasPermission_v2(`${props.permission}.add`);
|
|
26672
26708
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
26673
26709
|
const open = Boolean(anchorEl);
|
|
26674
26710
|
const handleClick = () => {
|
|
@@ -26684,7 +26720,8 @@ const CreateButtonWithMenuOptions = (props) => {
|
|
|
26684
26720
|
const handleToggleClose = () => {
|
|
26685
26721
|
setCSV({ open: false });
|
|
26686
26722
|
};
|
|
26687
|
-
|
|
26723
|
+
if (!props.permission)
|
|
26724
|
+
return null;
|
|
26688
26725
|
return (jsxs(Fragment, { children: [jsx(CreateButtonBase, { open: open, handleClick: handleClick }), jsxs(StyledMenu, { id: 'create-menu', MenuListProps: {
|
|
26689
26726
|
'aria-labelledby': 'create-menu-button',
|
|
26690
26727
|
}, anchorEl: anchorEl, open: open, onClose: handleClose, children: [props.csv_upload?.enable && ([
|
|
@@ -27104,37 +27141,33 @@ const FiltersButton = (props) => {
|
|
|
27104
27141
|
};
|
|
27105
27142
|
|
|
27106
27143
|
const ExportCSV = (props) => {
|
|
27107
|
-
|
|
27108
|
-
|
|
27109
|
-
|
|
27110
|
-
|
|
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();
|
|
27111
27149
|
const handleClick = () => {
|
|
27112
27150
|
const extraItems = { variant: props.slots?.variant };
|
|
27113
27151
|
if (props.rowSelectionModel.ids.size > 0)
|
|
27114
27152
|
extraItems[`${props.slots?.column_key || 'id'}__in`] = Array.from(props.rowSelectionModel.ids).join(',');
|
|
27115
|
-
|
|
27116
|
-
|
|
27117
|
-
|
|
27118
|
-
|
|
27119
|
-
|
|
27120
|
-
|
|
27121
|
-
|
|
27122
|
-
|
|
27123
|
-
|
|
27124
|
-
|
|
27125
|
-
|
|
27126
|
-
|
|
27127
|
-
|
|
27128
|
-
|
|
27129
|
-
|
|
27130
|
-
|
|
27131
|
-
// })
|
|
27132
|
-
// .catch((error) => {
|
|
27133
|
-
// console.log(error)
|
|
27134
|
-
// notifications.show('Error al descargar CSV.', {severity: 'error'});
|
|
27135
|
-
// })
|
|
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
|
+
});
|
|
27136
27169
|
};
|
|
27137
|
-
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'));
|
|
27138
27171
|
};
|
|
27139
27172
|
|
|
27140
27173
|
const ExportButton = (props) => {
|
|
@@ -27154,11 +27187,10 @@ const ExportButton = (props) => {
|
|
|
27154
27187
|
handleClick: () => setExportMenuOpen(false),
|
|
27155
27188
|
filterModel: props.filterModel,
|
|
27156
27189
|
sortModel: props.sortModel,
|
|
27190
|
+
rowSelectionModel: props.rowSelectionModel,
|
|
27157
27191
|
csvExport: {
|
|
27158
|
-
rowSelectionModel: props.rowSelectionModel,
|
|
27159
27192
|
...csvExport,
|
|
27160
27193
|
},
|
|
27161
|
-
endpoint: props.csvProps?.endpoint,
|
|
27162
27194
|
...remainingProps,
|
|
27163
27195
|
}));
|
|
27164
27196
|
})] })] }));
|
|
@@ -27560,14 +27592,20 @@ const Base = (props) => {
|
|
|
27560
27592
|
setFilterModel: setFilterModel,
|
|
27561
27593
|
}));
|
|
27562
27594
|
// ========================= || PAGINADO || ========================= //
|
|
27563
|
-
const [paginationModel, setPaginationModel] = useState({
|
|
27595
|
+
const [paginationModel, setPaginationModel] = useState({
|
|
27596
|
+
page: 0,
|
|
27597
|
+
pageSize: 50,
|
|
27598
|
+
});
|
|
27564
27599
|
// ========================= || ORDENADO || ========================= //
|
|
27565
27600
|
const [sortModel, setSortModel] = useState([]);
|
|
27566
27601
|
// ========================= || FILTRADO || ========================= //
|
|
27567
|
-
const [filterModel, setFilterModel] = useState({
|
|
27602
|
+
const [filterModel, setFilterModel] = useState({
|
|
27603
|
+
items: {},
|
|
27604
|
+
quickFilterValues: "",
|
|
27605
|
+
});
|
|
27568
27606
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27569
27607
|
const setQuickSearchValue = useCallback(debounce$1((quickSearch) => {
|
|
27570
|
-
setFilterModel(prevState => ({ ...prevState, quickFilterValues: quickSearch }));
|
|
27608
|
+
setFilterModel((prevState) => ({ ...prevState, quickFilterValues: quickSearch }));
|
|
27571
27609
|
}, 500), []);
|
|
27572
27610
|
// ========================= || COLUMNAS || ========================= //
|
|
27573
27611
|
const getTogglableColumns = (columns) => {
|
|
@@ -27575,7 +27613,7 @@ const Base = (props) => {
|
|
|
27575
27613
|
return [];
|
|
27576
27614
|
return columns
|
|
27577
27615
|
.filter((column) => {
|
|
27578
|
-
return ![
|
|
27616
|
+
return !["__check__", "actions"].includes(column.field);
|
|
27579
27617
|
})
|
|
27580
27618
|
.map((column) => column.field);
|
|
27581
27619
|
};
|
|
@@ -27587,7 +27625,7 @@ const Base = (props) => {
|
|
|
27587
27625
|
// ========================= || LAZY QUERY || ========================= //
|
|
27588
27626
|
const [query, { data, isLoading, isFetching, isError, isUninitialized }] = props.api.data.query(props.api.data.options || {});
|
|
27589
27627
|
// ========================= || INITIAL STATE || ========================= //
|
|
27590
|
-
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]);
|
|
27591
27629
|
const internalFilterRef = useRef(filterModel);
|
|
27592
27630
|
const filterRef = props.slotProps?.filtersRef || internalFilterRef;
|
|
27593
27631
|
useEffect(() => {
|
|
@@ -27597,28 +27635,30 @@ const Base = (props) => {
|
|
|
27597
27635
|
const saveSnapshot = useCallback(() => {
|
|
27598
27636
|
if (apiRef?.current?.exportState && localStorage && !props.slotProps?.dontSaveState) {
|
|
27599
27637
|
const currentState = apiRef.current.exportState();
|
|
27600
|
-
set$1(currentState,
|
|
27638
|
+
set$1(currentState, "filters.filterModel", filterRef.current);
|
|
27601
27639
|
setWithExpiry(localStoreName, currentState, 86400000);
|
|
27602
27640
|
}
|
|
27603
27641
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27604
27642
|
}, [apiRef, props.pathname]);
|
|
27605
27643
|
useLayoutEffect(() => {
|
|
27606
27644
|
const stateFromLocalStorage = getWithExpiry(localStoreName);
|
|
27607
|
-
const init = stateFromLocalStorage
|
|
27608
|
-
|
|
27609
|
-
|
|
27610
|
-
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);
|
|
27611
27651
|
setPaginationModel(pagination);
|
|
27612
27652
|
setSortModel(sorting);
|
|
27613
27653
|
setFilterModel(filters);
|
|
27614
|
-
setColumnVisibilityModel(get(init,
|
|
27654
|
+
setColumnVisibilityModel(get(init, "columns.columnVisibilityModel", columnVisibilityModel));
|
|
27615
27655
|
// handle refresh and navigating away/refreshing
|
|
27616
|
-
window.addEventListener(
|
|
27656
|
+
window.addEventListener("beforeunload", saveSnapshot);
|
|
27617
27657
|
// console.log(getQueryArgs(pagination, sorting, filters, props.api.data.args))
|
|
27618
27658
|
query(getQueryArgs(pagination, sorting, filters, props.api.data.args));
|
|
27619
27659
|
return () => {
|
|
27620
27660
|
// in case of an SPA remove the event-listener
|
|
27621
|
-
window.removeEventListener(
|
|
27661
|
+
window.removeEventListener("beforeunload", saveSnapshot);
|
|
27622
27662
|
saveSnapshot();
|
|
27623
27663
|
};
|
|
27624
27664
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -27637,8 +27677,8 @@ const Base = (props) => {
|
|
|
27637
27677
|
};
|
|
27638
27678
|
// ========================= || SELECCIÓN || ========================= //
|
|
27639
27679
|
const [rowSelectionModel, setRowSelectionModel] = useState({
|
|
27640
|
-
type:
|
|
27641
|
-
ids: new Set()
|
|
27680
|
+
type: "include",
|
|
27681
|
+
ids: new Set(),
|
|
27642
27682
|
});
|
|
27643
27683
|
const handleRowSelectionModelChange = (newSelection) => {
|
|
27644
27684
|
setRowSelectionModel(newSelection);
|
|
@@ -27656,13 +27696,13 @@ const Base = (props) => {
|
|
|
27656
27696
|
const handleRowClick = ({ id }, event) => {
|
|
27657
27697
|
const link_to = `${props.slotProps?.navigation != undefined ? props.slotProps?.navigation : props.pathname}/${id}`;
|
|
27658
27698
|
if (event.ctrlKey) {
|
|
27659
|
-
const newTab = document.createElement(
|
|
27699
|
+
const newTab = document.createElement("a");
|
|
27660
27700
|
newTab.href = link_to;
|
|
27661
|
-
newTab.target =
|
|
27701
|
+
newTab.target = "_blank";
|
|
27662
27702
|
newTab.click();
|
|
27663
27703
|
}
|
|
27664
27704
|
else {
|
|
27665
|
-
navigate(`${props.slotProps?.navigation ? props.slotProps?.navigation : props.pathname}/${id}`);
|
|
27705
|
+
navigate(`${props.slotProps?.navigation || props.slotProps?.navigation === "" ? props.slotProps?.navigation : props.pathname}/${id}`);
|
|
27666
27706
|
}
|
|
27667
27707
|
};
|
|
27668
27708
|
const handleRowEditStop = (params, event) => {
|
|
@@ -27681,13 +27721,13 @@ const Base = (props) => {
|
|
|
27681
27721
|
},
|
|
27682
27722
|
slotProps: {
|
|
27683
27723
|
baseCheckbox: {
|
|
27684
|
-
size:
|
|
27724
|
+
size: "small",
|
|
27685
27725
|
},
|
|
27686
27726
|
toolbar: {
|
|
27687
27727
|
filters: {
|
|
27688
27728
|
filterModel: filterModel,
|
|
27689
27729
|
setFilterModel: setFilterModel,
|
|
27690
|
-
setQuickSearchValue: setQuickSearchValue
|
|
27730
|
+
setQuickSearchValue: setQuickSearchValue,
|
|
27691
27731
|
},
|
|
27692
27732
|
protectFilters: props.api.data.protectFilters,
|
|
27693
27733
|
columnsFilter: props.slotProps?.columnsFilter,
|
|
@@ -27698,27 +27738,27 @@ const Base = (props) => {
|
|
|
27698
27738
|
buttons: {
|
|
27699
27739
|
refresh: {
|
|
27700
27740
|
refetch: handleRefetch,
|
|
27701
|
-
}
|
|
27702
|
-
}
|
|
27741
|
+
},
|
|
27742
|
+
},
|
|
27703
27743
|
},
|
|
27704
27744
|
columnsManagement: {
|
|
27705
27745
|
getTogglableColumns: getTogglableColumns,
|
|
27706
27746
|
},
|
|
27707
27747
|
},
|
|
27708
27748
|
}, props.dataGridProps);
|
|
27709
|
-
const renderDataGrid = ({ dataGridProps: renderDataGridProps }) => {
|
|
27749
|
+
const renderDataGrid = ({ dataGridProps: renderDataGridProps, }) => {
|
|
27710
27750
|
// console.log(dataGridProps)
|
|
27711
27751
|
return (jsx(Box, { width: 1, minHeight: 300, height: 1,
|
|
27712
27752
|
// maxHeight={'calc(100% - 30px)'}
|
|
27713
|
-
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) {
|
|
27714
27754
|
return x;
|
|
27715
27755
|
}),
|
|
27716
27756
|
// paginado //
|
|
27717
|
-
pagination: true, paginationMode:
|
|
27757
|
+
pagination: true, paginationMode: "server", paginationModel: paginationModel, onPaginationModelChange: setPaginationModel, pageSizeOptions: [50, 100, { value: -1, label: "Todos" }],
|
|
27718
27758
|
// ordenado
|
|
27719
|
-
sortingMode:
|
|
27759
|
+
sortingMode: "server", sortModel: sortModel, onSortModelChange: setSortModel,
|
|
27720
27760
|
// filtrado
|
|
27721
|
-
filterMode:
|
|
27761
|
+
filterMode: "server",
|
|
27722
27762
|
// onFilterModelChange={handleFilterChange}
|
|
27723
27763
|
disableColumnFilter: true, showToolbar: true,
|
|
27724
27764
|
// selection
|
|
@@ -27736,13 +27776,13 @@ const Base = (props) => {
|
|
|
27736
27776
|
// row count
|
|
27737
27777
|
rowCount: rowCount,
|
|
27738
27778
|
// settings
|
|
27739
|
-
density:
|
|
27779
|
+
density: "compact",
|
|
27740
27780
|
// striping
|
|
27741
|
-
getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ?
|
|
27742
|
-
columnHeaderSortIconLabel:
|
|
27743
|
-
columnMenuSortAsc:
|
|
27744
|
-
columnMenuSortDesc:
|
|
27745
|
-
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ú",
|
|
27746
27786
|
}, ...renderDataGridProps }) }) }));
|
|
27747
27787
|
};
|
|
27748
27788
|
// ========================= || RETURN || ========================= //
|
|
@@ -27756,7 +27796,7 @@ const Base = (props) => {
|
|
|
27756
27796
|
pathname: props.pathname,
|
|
27757
27797
|
navigation: props.slotProps?.navigation,
|
|
27758
27798
|
...renderProps,
|
|
27759
|
-
...props.api.create
|
|
27799
|
+
...props.api.create,
|
|
27760
27800
|
};
|
|
27761
27801
|
renderFunction = CreateGridWrapper;
|
|
27762
27802
|
}
|
|
@@ -27767,7 +27807,7 @@ const Base = (props) => {
|
|
|
27767
27807
|
renderFunctionProps: renderProps,
|
|
27768
27808
|
dataGridProps: dataGridProps,
|
|
27769
27809
|
baseGridRef: apiRef,
|
|
27770
|
-
...props.api.edit
|
|
27810
|
+
...props.api.edit,
|
|
27771
27811
|
};
|
|
27772
27812
|
renderFunction = EditGridWrapper;
|
|
27773
27813
|
}
|
|
@@ -27777,7 +27817,7 @@ const Base = (props) => {
|
|
|
27777
27817
|
renderFunction: renderFunction,
|
|
27778
27818
|
renderFunctionProps: renderProps,
|
|
27779
27819
|
dataGridProps: dataGridProps,
|
|
27780
|
-
...props.api.delete
|
|
27820
|
+
...props.api.delete,
|
|
27781
27821
|
});
|
|
27782
27822
|
}
|
|
27783
27823
|
return renderFunction(renderProps);
|
|
@@ -28654,5 +28694,5 @@ const theme = () => {
|
|
|
28654
28694
|
return themes;
|
|
28655
28695
|
};
|
|
28656
28696
|
|
|
28657
|
-
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,
|
|
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 };
|
|
28658
28698
|
//# sourceMappingURL=index.js.map
|