@acvl/frontend-components 0.0.33 → 0.0.34

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.
@@ -1,6 +1,6 @@
1
1
  import { DrawerProps } from "@mui/material";
2
2
  import React, { ReactNode } from "react";
3
- interface MainDrawerProps {
3
+ export interface MainDrawerProps {
4
4
  open: boolean;
5
5
  drawerToggle: () => void;
6
6
  title: string;
@@ -14,5 +14,5 @@ export interface JSONFormProps {
14
14
  useLabel?: boolean;
15
15
  props?: JSONParserProps;
16
16
  }
17
- export declare const formParser: ({ type, submitData, data, useLabel, props }: JSONFormProps) => any;
17
+ export declare const formParser: ({ type, submitData, data, useLabel, props, }: JSONFormProps) => any;
18
18
  export declare const setErrors: (form: any, error: any) => void;
@@ -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
- handleCreate: () => void;
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;
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 === null || isEmpty(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")));
@@ -25757,7 +25757,7 @@ const typeSwitch = ({ base_object, base_key, response, submitData, useLabel, dat
25757
25757
  break;
25758
25758
  }
25759
25759
  };
25760
- const formParser = ({ type, submitData, data, useLabel, props }) => {
25760
+ const formParser = ({ type, submitData, data, useLabel, props, }) => {
25761
25761
  const t = type || "json";
25762
25762
  const response = t === "json" ? {} : new FormData();
25763
25763
  Object.entries(submitData).forEach(([key, value]) => {
@@ -28084,43 +28084,49 @@ const Field = (props) => {
28084
28084
  };
28085
28085
 
28086
28086
  const EditToolbar = (props) => {
28087
- return (jsx(Toolbar, { children: props.pageType != "detail" && (jsx(Tooltip$1, { title: "Crear", children: jsx(ToolbarButton, { onClick: props.handleCreate, children: jsx(AddIcon, { fontSize: "small" }) }) })) }));
28087
+ return (jsx(Toolbar, { children: props.pageType != "detail" && (jsx(Tooltip$1, { title: "Crear", children: jsx(ToolbarButton, { onClick: props.handleClick, children: jsx(AddIcon, { fontSize: "small" }) }) })) }));
28088
28088
  };
28089
28089
  const FieldArrayField = (props) => {
28090
28090
  const detail = useMemo(() => props.pageType === "detail", [props.pageType]);
28091
- const { fields, append, update, remove } = useFieldArray({
28091
+ const { fields, append, remove, update } = useFieldArray({
28092
28092
  control: props.form.control,
28093
28093
  name: props.name,
28094
28094
  keyName: "_id",
28095
28095
  });
28096
- const [rowModesModel, setRowModesModel] = useState({});
28096
+ // console.log(props.form?.watch(props.name));
28097
+ // console.log(fields);
28097
28098
  const getIndex = useCallback((id) => findIndex(fields, function (field) {
28098
28099
  return field._id == id;
28099
28100
  }), [fields]);
28101
+ const [drawer, setDrawer] = useState({
28102
+ index: 0,
28103
+ open: false,
28104
+ });
28100
28105
  const handleCreate = () => {
28101
28106
  append(props.defaultValues);
28107
+ setDrawer({ index: fields.length, open: true });
28108
+ };
28109
+ const handleRowClick = (params) => {
28110
+ const index = getIndex(params.id);
28111
+ setDrawer({ index, open: true });
28112
+ };
28113
+ const handleCloseDrawer = () => {
28114
+ setDrawer((prev) => ({ ...prev, open: false }));
28115
+ };
28116
+ const handleCancel = () => {
28117
+ update(drawer.index, fields[drawer.index]);
28118
+ handleCloseDrawer();
28119
+ };
28120
+ const handleSave = () => {
28121
+ update(drawer.index, props.form.watch(`${props.name}.${drawer.index}`));
28122
+ handleCloseDrawer();
28102
28123
  };
28103
28124
  const handleDelete = (id) => {
28104
28125
  remove(getIndex(id));
28105
28126
  };
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
28127
  const dataGridProps = mergeSettings({
28117
28128
  columns: !detail
28118
28129
  ? [
28119
- ...editColumn({
28120
- displayEdit: true,
28121
- rowModesModel,
28122
- setRowModesModel,
28123
- }),
28124
28130
  {
28125
28131
  field: "delete",
28126
28132
  type: "actions",
@@ -28136,8 +28142,7 @@ const FieldArrayField = (props) => {
28136
28142
  slots: { toolbar: EditToolbar },
28137
28143
  slotProps: {
28138
28144
  toolbar: {
28139
- handleCreate: handleCreate,
28140
- handleDelete: handleDelete,
28145
+ handleClick: handleCreate,
28141
28146
  pageType: props.pageType,
28142
28147
  },
28143
28148
  baseCheckbox: {
@@ -28147,23 +28152,21 @@ const FieldArrayField = (props) => {
28147
28152
  getRowId: (row) => row._id,
28148
28153
  getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ? "even" : "odd",
28149
28154
  density: "compact",
28150
- onRowClick: undefined,
28151
- editMode: "row",
28152
- rowModesModel: rowModesModel,
28153
- onRowModesModelChange: setRowModesModel,
28154
- processRowUpdate: processRowUpdate,
28155
- onProcessRowUpdateError: handleProcessRowUpdateError,
28156
- onRowEditStart: ({ reason }, event) => {
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
- }
28164
- },
28155
+ onRowClick: props.pageType == "edit" ? handleRowClick : undefined,
28165
28156
  }, props.dataGridProps);
28166
- return (jsx(Fragment, { children: 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 }) })] }) }));
28157
+ return (jsxs(Fragment, { children: [jsx(MainDrawer, { open: drawer.open, drawerToggle: handleCancel, title: "Trailer", slots: {
28158
+ button: (jsx(SaveCancelButton, { slotProps: {
28159
+ saveBtn: { onClick: handleSave, type: "button" },
28160
+ cancelBtn: { onClick: handleCancel },
28161
+ } })),
28162
+ }, ...props.slotProps?.drawer, children: jsx(Grid, { container: true, size: 12, children: props.fields.map((field, index) => {
28163
+ 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({
28164
+ name: `${props.name}.${drawer.index}.${field.name}`,
28165
+ control: props.form.control,
28166
+ fieldProps: field.fieldProps,
28167
+ extraProps: field.extraProps,
28168
+ }) })] }, `grid-${index}`));
28169
+ }) }) }), 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
28170
  };
28168
28171
 
28169
28172
  const Section = (props) => {
@@ -28396,7 +28399,7 @@ function DetailPage(props) {
28396
28399
  }
28397
28400
  }
28398
28401
  }, [data, dispatch, form, props.slots?.title]);
28399
- const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse }] = props.api.mutate.mutation();
28402
+ const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse },] = props.api.mutate.mutation();
28400
28403
  const handleCancel = () => {
28401
28404
  form.reset();
28402
28405
  navigate(-1);
@@ -28406,7 +28409,8 @@ function DetailPage(props) {
28406
28409
  // ==============================|| VALIDATION ||============================== //
28407
28410
  useValidateFieldData(props, form);
28408
28411
  // ==============================|| QUICK RETURN ||============================== //
28409
- if ((!canEdit && props.pageType == "edit") || (fetchError && fetchError.originalStatus == 403))
28412
+ if ((!canEdit && props.pageType == "edit") ||
28413
+ (fetchError && fetchError.originalStatus == 403))
28410
28414
  return jsx(NotAllowed, {});
28411
28415
  if (fetchError && fetchError.originalStatus == 404)
28412
28416
  return jsx(NotFound, {});
@@ -28420,7 +28424,9 @@ function DetailPage(props) {
28420
28424
  props: props.slotProps?.parser,
28421
28425
  };
28422
28426
  const dataToSend = formParser(params);
28423
- mutation(props.edit.useFormData ? dataToSend : { ...dataToSend, ...props.api.mutate.args })
28427
+ mutation(props.edit.useFormData
28428
+ ? dataToSend
28429
+ : { ...dataToSend, ...props.api.mutate.args })
28424
28430
  .unwrap()
28425
28431
  .then(() => {
28426
28432
  if (!props.slotProps?.button?.save?.disableNavBack)
@@ -28452,7 +28458,9 @@ function DetailPage(props) {
28452
28458
  if (!section.display)
28453
28459
  return null;
28454
28460
  if (typeof section.display == "object") {
28455
- const validateAgainst = form.watch(section.display.field)?.toString();
28461
+ const validateAgainst = form
28462
+ .watch(section.display.field)
28463
+ ?.toString();
28456
28464
  if (!section.display.method(validateAgainst, section.display.value))
28457
28465
  return null;
28458
28466
  }
@@ -28464,7 +28472,8 @@ function DetailPage(props) {
28464
28472
  if (props.api.mutate.postAction &&
28465
28473
  isSuccess &&
28466
28474
  "post_action" in mutationResponse &&
28467
- mutationResponse["post_action"]["type"] === props.api.mutate.postAction.type) {
28475
+ mutationResponse["post_action"]["type"] ===
28476
+ props.api.mutate.postAction.type) {
28468
28477
  switch (props.api.mutate.postAction.after) {
28469
28478
  // case 'create':
28470
28479
  // if (props.pageType === 'create') return addPropsToNode(props.api.mutate.postAction.node, mutationResponse);