@acvl/frontend-components 0.0.26 → 0.0.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/dist/cjs/index.js CHANGED
@@ -127,8 +127,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
127
127
  const NormalOrIcon = (props) => {
128
128
  const theme = material.useTheme();
129
129
  const belowLG = material.useMediaQuery(theme.breakpoints.down("lg"));
130
- if ((belowLG && !(props.type == "button")) || props.type == "icon")
131
- return (jsxRuntime.jsx(material.Tooltip, { title: props.buttonProps.children, children: jsxRuntime.jsx(material.IconButton, { ...props.buttonProps, children: props.buttonProps.startIcon }) }));
130
+ if ((belowLG && !(props.type == "button")) || props.type == "icon") {
131
+ const { startIcon, ...others } = props.buttonProps;
132
+ return (jsxRuntime.jsx(material.Tooltip, { title: props.buttonProps.children, children: jsxRuntime.jsx(material.IconButton, { ...others, children: startIcon }) }));
133
+ }
132
134
  return jsxRuntime.jsx(material.Button, { ...props.buttonProps });
133
135
  };
134
136
 
@@ -25760,8 +25762,7 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
25760
25762
  }
25761
25763
  else {
25762
25764
  forEach(object, (value, key2) => {
25763
- if (!includes(["id", "transporte.tarifa.cargos_adicionales"], key) &&
25764
- isEqual(get(data, `${key}.${key2}`), value))
25765
+ if (key2 !== "id" && isEqual(get(data, `${key}.${key2}`), value))
25765
25766
  return;
25766
25767
  typeSwitch({
25767
25768
  base_object: value,
@@ -25781,7 +25782,7 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
25781
25782
  break;
25782
25783
  }
25783
25784
  };
25784
- const jsonForm = ({ submitData, data, useLabel, props }) => {
25785
+ const jsonForm = ({ submitData, data, useLabel, props, }) => {
25785
25786
  const response = {};
25786
25787
  forEach(submitData, function (value, key) {
25787
25788
  if (key != "id" && isEqual(get(data, key), value))
@@ -25799,7 +25800,7 @@ const jsonForm = ({ submitData, data, useLabel, props }) => {
25799
25800
  });
25800
25801
  return response;
25801
25802
  };
25802
- const formDataForm = ({ submitData, data, useLabel, props }) => {
25803
+ const formDataForm = ({ submitData, data, useLabel, props, }) => {
25803
25804
  const formData = new FormData();
25804
25805
  forEach(submitData, function (value, key) {
25805
25806
  if (key != "id" && isEqual(get(data, key), value))
@@ -27365,11 +27366,12 @@ const EditGridWrapper = (props) => {
27365
27366
  }
27366
27367
  catch (e) {
27367
27368
  setErrors((prevState) => immer.produce(prevState, (draft) => {
27368
- draft[newRow.id] = lodash.get(e, "data");
27369
+ draft[newRow.id] = lodash.get(e, "data.invalid_params");
27369
27370
  }));
27370
27371
  notifications.show("Error actualizando información!", { severity: "error" });
27371
27372
  }
27372
27373
  };
27374
+ const handleProcessRowUpdateError = () => { };
27373
27375
  // ===== || KEYDOWN || ===== //
27374
27376
  const handleKeyPress = React.useCallback((event) => {
27375
27377
  if (props.permission) {
@@ -27450,6 +27452,7 @@ const EditGridWrapper = (props) => {
27450
27452
  rowModesModel: rowModesModel,
27451
27453
  onRowModesModelChange: setRowModesModel,
27452
27454
  processRowUpdate: processRowUpdate,
27455
+ onProcessRowUpdateError: handleProcessRowUpdateError,
27453
27456
  loadingParams: [loadingMutation],
27454
27457
  }, props.dataGridProps);
27455
27458
  const renderEditGrid = () => (jsxRuntime.jsx(core$1.DndContext, { sensors: sensors, collisionDetection: core$1.closestCenter, onDragEnd: handleDragEnd, modifiers: [modifiers.restrictToVerticalAxis, modifiers.restrictToWindowEdges, modifiers.restrictToParentElement], autoScroll: false, children: jsxRuntime.jsx(sortable.SortableContext, { items: rows ? rows.map((row) => row.id.toString()) : [], strategy: sortable.verticalListSortingStrategy, children: props.renderFunction({
@@ -27484,7 +27487,7 @@ const editColumn = (props) => {
27484
27487
  width: 80,
27485
27488
  cellClassName: "actions",
27486
27489
  getActions: ({ id, row }) => {
27487
- const canEdit = get(row, "obj_permissions.edit");
27490
+ const canEdit = get(row, "obj_permissions.edit", true);
27488
27491
  const isInEditMode = props.rowModesModel[id]?.mode === xDataGrid.GridRowModes.Edit;
27489
27492
  if (isInEditMode) {
27490
27493
  return [
@@ -27940,7 +27943,7 @@ const MyGridEditSingleSelect = (props) => {
27940
27943
  } }));
27941
27944
  };
27942
27945
 
27943
- const StyledTooltip = material.styled(({ className, ...props }) => (jsxRuntime.jsx(material.Tooltip, { ...props, placement: 'top', classes: { popper: className } })))(({ theme }) => ({
27946
+ const StyledTooltip = material.styled(({ className, ...props }) => (jsxRuntime.jsx(material.Tooltip, { ...props, placement: "top", classes: { popper: className } })))(({ theme }) => ({
27944
27947
  [`& .${material.tooltipClasses.tooltip}`]: {
27945
27948
  backgroundColor: theme.palette.error.main,
27946
27949
  color: theme.palette.error.contrastText,
@@ -27950,27 +27953,29 @@ const EditCellWithErrorTooltip = (props) => {
27950
27953
  const { error } = props;
27951
27954
  const renderCell = () => {
27952
27955
  switch (props.colDef.type) {
27953
- case 'boolean':
27956
+ case "boolean":
27954
27957
  return jsxRuntime.jsx(xDataGrid.GridEditBooleanCell, { ...props });
27955
- case 'singleSelect':
27958
+ case "singleSelect":
27956
27959
  return jsxRuntime.jsx(MyGridEditSingleSelect, { ...props });
27957
27960
  default:
27958
- return jsxRuntime.jsx(xDataGrid.GridEditInputCell, { ...props, slotProps: {
27961
+ return (jsxRuntime.jsx(xDataGrid.GridEditInputCell, { ...props, slotProps: {
27959
27962
  root: {
27960
27963
  onFocus: (e) => {
27961
- if (props.field == 'cotizacion__total')
27964
+ if (props.field == "cotizacion__total")
27962
27965
  return e.target.select();
27963
27966
  },
27964
- }
27965
- } });
27967
+ },
27968
+ } }));
27966
27969
  }
27967
27970
  };
27968
- return (jsxRuntime.jsx(StyledTooltip, { open: !!error, title: error, children: renderCell() }));
27971
+ return (jsxRuntime.jsx(StyledTooltip, { open: !!error, title: error?.reason.join(", "), children: jsxRuntime.jsx("div", { style: { display: "flex" }, children: renderCell() }) }));
27969
27972
  };
27970
27973
 
27971
27974
  function renderEditCellWithErrorTooltip(params, mutationErrors, path) {
27972
- const hasError = lodash.get(lodash.get(mutationErrors, params.id), path || params.field);
27973
- return jsxRuntime.jsx(EditCellWithErrorTooltip, { ...params, error: hasError });
27975
+ const error = lodash.find(lodash.get(mutationErrors, params.id), function (e) {
27976
+ return e.name == (path || params.field);
27977
+ });
27978
+ return jsxRuntime.jsx(EditCellWithErrorTooltip, { ...params, error: error });
27974
27979
  }
27975
27980
 
27976
27981
  const CoverPage = (props) => {
@@ -28100,60 +28105,81 @@ const Field = (props) => {
28100
28105
  };
28101
28106
 
28102
28107
  const EditToolbar = (props) => {
28103
- return (jsxRuntime.jsxs(xDataGrid.Toolbar, { children: [props.pageType != "detail" && (jsxRuntime.jsx(Tooltip, { title: "Crear", children: jsxRuntime.jsx(xDataGrid.ToolbarButton, { onClick: props.handleCreate, children: jsxRuntime.jsx(AddIcon, { fontSize: "small" }) }) })), !!props.selected && (jsxRuntime.jsx(Tooltip, { title: "Borrar", children: jsxRuntime.jsx(xDataGrid.ToolbarButton, { onClick: props.handleDelete, children: jsxRuntime.jsx(DeleteIcon, { fontSize: "small" }) }) }))] }));
28108
+ return (jsxRuntime.jsx(xDataGrid.Toolbar, { children: props.pageType != "detail" && (jsxRuntime.jsx(Tooltip, { title: "Crear", children: jsxRuntime.jsx(xDataGrid.ToolbarButton, { onClick: props.handleCreate, children: jsxRuntime.jsx(AddIcon, { fontSize: "small" }) }) })) }));
28104
28109
  };
28105
28110
  const FieldArrayField = (props) => {
28106
- const { fields, remove } = reactHookForm.useFieldArray({
28111
+ const detail = React.useMemo(() => props.pageType === "detail", [props.pageType]);
28112
+ const { fields, append, update, remove } = reactHookForm.useFieldArray({
28107
28113
  control: props.form.control,
28108
28114
  name: props.name,
28109
28115
  keyName: "_id",
28110
28116
  });
28111
- const [drawer, setDrawer] = React.useState({
28112
- open: false,
28113
- data: undefined,
28114
- });
28115
- const [rowSelectionModel, setRowSelectionModel] = React.useState({
28116
- type: "include",
28117
- ids: new Set(),
28118
- });
28117
+ const [rowModesModel, setRowModesModel] = React.useState({});
28119
28118
  const getIndex = React.useCallback((id) => lodash.findIndex(fields, function (field) {
28120
28119
  return field._id == id;
28121
28120
  }), [fields]);
28122
28121
  const handleCreate = () => {
28123
- setDrawer({ open: true, data: undefined });
28124
- };
28125
- const handleDelete = () => {
28126
- remove(Array.from(rowSelectionModel.ids).map((id) => getIndex(id)));
28122
+ append(props.defaultValues);
28127
28123
  };
28128
- const closeDrawer = () => {
28129
- setDrawer({ open: false, data: undefined });
28124
+ const handleDelete = (id) => {
28125
+ remove(getIndex(id));
28130
28126
  };
28131
- // const handleSave = () => {
28132
- // const index = getIndex(drawer.data?._id);
28133
- // closeDrawer();
28134
- // if (index > -1) {
28135
- // update(index, props.form.watch(`${props.name}.${index}`));
28136
- // } else {
28137
- // append(props.form.watch(`${props.name}.${index}`));
28138
- // }
28139
- //
28140
- // }
28141
- const handleRowClick = (e) => {
28142
- setDrawer({ open: true, data: e.row });
28127
+ const processRowUpdate = async (newRow, originalRow) => {
28128
+ const original_data = jsonForm({ submitData: originalRow, props: props.parser });
28129
+ const data = jsonForm({ submitData: newRow, props: props.parser });
28130
+ if (lodash.isEqual(data, original_data))
28131
+ return originalRow;
28132
+ const index = getIndex(data._id);
28133
+ update(index, data);
28134
+ return newRow;
28143
28135
  };
28144
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(material.Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...props.gridProps, children: [jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", fontWeight: "bold", children: props.label }) }), jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(xDataGrid.DataGrid, { ...props.dataGridProps, rows: fields, checkboxSelection: props.pageType != "detail", onRowSelectionModelChange: (newRowSelectionModel) => {
28145
- setRowSelectionModel(newRowSelectionModel);
28146
- }, showToolbar: true, slots: { toolbar: EditToolbar }, slotProps: {
28147
- toolbar: {
28148
- selected: rowSelectionModel.ids.size,
28149
- handleCreate: handleCreate,
28150
- handleDelete: handleDelete,
28151
- pageType: props.pageType,
28152
- },
28153
- }, disableRowSelectionOnClick: true, onRowClick: handleRowClick, getRowId: (row) => row._id }) })] }), jsxRuntime.jsx(MainDrawer, { open: drawer.open, drawerToggle: closeDrawer, title: "Cargo Adicional", children: jsxRuntime.jsx(material.Grid, { size: 12, container: true, children: props.fields.map((field) => {
28154
- const fieldName = `${props.name}.${getIndex(drawer.data?._id)}.${field.name}`;
28155
- return (jsxRuntime.jsx(Field, { ...field, form: props.form, name: fieldName, fieldData: lodash.get(drawer.data, field.name) }, fieldName));
28156
- }) }) })] }));
28136
+ const handleProcessRowUpdateError = () => { };
28137
+ const dataGridProps = mergeSettings({
28138
+ columns: !detail
28139
+ ? [
28140
+ ...editColumn({
28141
+ displayEdit: true,
28142
+ rowModesModel,
28143
+ setRowModesModel,
28144
+ }),
28145
+ {
28146
+ field: "delete",
28147
+ type: "actions",
28148
+ headerName: "Borrar",
28149
+ renderCell: (params) => (jsxRuntime.jsx(xDataGrid.GridActionsCell, { ...params, children: jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(DeleteIcon, {}), label: "Delete", color: "primary", onClick: () => handleDelete(params.row._id) }) })),
28150
+ },
28151
+ ]
28152
+ : [],
28153
+ rows: fields,
28154
+ disableRowSelectionOnClick: true,
28155
+ disableColumnSelector: true,
28156
+ showToolbar: !detail,
28157
+ slots: { toolbar: EditToolbar },
28158
+ slotProps: {
28159
+ toolbar: {
28160
+ handleCreate: handleCreate,
28161
+ handleDelete: handleDelete,
28162
+ pageType: props.pageType,
28163
+ },
28164
+ baseCheckbox: {
28165
+ size: "small",
28166
+ },
28167
+ },
28168
+ getRowId: (row) => row._id,
28169
+ getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ? "even" : "odd",
28170
+ density: "compact",
28171
+ onRowClick: undefined,
28172
+ editMode: "row",
28173
+ rowModesModel: rowModesModel,
28174
+ onRowModesModelChange: setRowModesModel,
28175
+ processRowUpdate: processRowUpdate,
28176
+ onProcessRowUpdateError: handleProcessRowUpdateError,
28177
+ onRowEditStart: ({ reason }, event) => {
28178
+ if (reason === xDataGrid.GridRowEditStartReasons.cellDoubleClick && detail)
28179
+ event.defaultMuiPrevented = true;
28180
+ },
28181
+ }, props.dataGridProps);
28182
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(material.Grid, { rowSpacing: 1, container: true, size: "grow", direction: "column", ...props.gridProps, children: [jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", fontWeight: "bold", children: props.label }) }), jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(xDataGrid.DataGrid, { ...dataGridProps }) })] }) }));
28157
28183
  };
28158
28184
 
28159
28185
  const Section = (props) => {
@@ -28400,7 +28426,11 @@ function DetailPage(props) {
28400
28426
  // ==============================|| SUBMIT ||============================== //
28401
28427
  const onSubmitHandler = (submitedData) => {
28402
28428
  const formData = "nativeEvent" in submitedData ? form.getValues() : submitedData;
28403
- const params = { submitData: formData, data: data, props: props.slotProps?.parser };
28429
+ const params = {
28430
+ submitData: formData,
28431
+ data: data,
28432
+ props: props.slotProps?.parser,
28433
+ };
28404
28434
  const dataToSend = props.edit.useFormData ? formDataForm(params) : jsonForm(params);
28405
28435
  mutation(props.edit.useFormData ? dataToSend : { ...dataToSend, ...props.api.mutate.args })
28406
28436
  .unwrap()
@@ -28426,6 +28456,7 @@ function DetailPage(props) {
28426
28456
  }
28427
28457
  });
28428
28458
  };
28459
+ const onError = (errors) => console.log("Validation Errors:", errors);
28429
28460
  // ==============================|| RENDER SECTIONS ||============================== //
28430
28461
  const renderContent = () => {
28431
28462
  let displayed_sections = -1;
@@ -28491,7 +28522,7 @@ function DetailPage(props) {
28491
28522
  }
28492
28523
  };
28493
28524
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ContentLayout, { button: renderButton(), badge: props.pageType == "detail" &&
28494
- badgeInfo && (jsxRuntime.jsx(StatusBadge, { title: badgeInfo["label"], severity: badgeInfo["value"] })), children: jsxRuntime.jsx(LoadingComponent, { height: 0.7, isLoading: isLoading || isFetching, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(material.Box, { id: "formulario", component: "form", autoComplete: "off", noValidate: true, onSubmit: form.handleSubmit(onSubmitHandler), width: "100%", position: "relative", children: renderContent() }) }) }) }), renderPostAction()] }));
28525
+ badgeInfo && (jsxRuntime.jsx(StatusBadge, { title: badgeInfo["label"], severity: badgeInfo["value"] })), children: jsxRuntime.jsx(LoadingComponent, { height: 0.7, isLoading: isLoading || isFetching, children: jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(material.Box, { id: "formulario", component: "form", autoComplete: "off", noValidate: true, onSubmit: form.handleSubmit(onSubmitHandler, onError), width: "100%", position: "relative", children: renderContent() }) }) }) }), renderPostAction()] }));
28495
28526
  }
28496
28527
 
28497
28528
  const ListPage = (props) => {
@@ -28502,7 +28533,6 @@ function SlideTransition(props) {
28502
28533
  return jsxRuntime.jsx(material.Slide, { ...props, direction: "left" });
28503
28534
  }
28504
28535
  const BaseProgressSnack = (props) => {
28505
- console.log(props);
28506
28536
  const dispatch = reactRedux.useDispatch();
28507
28537
  const handleClose = (e) => {
28508
28538
  if (e?.defaultMuiPrevented)