@acvl/frontend-components 0.0.36 → 0.0.38

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
@@ -98,6 +98,7 @@ var DrawIcon = require('@mui/icons-material/Draw');
98
98
  var CloseIcon = require('@mui/icons-material/Close');
99
99
  var ErrorOutlineIcon = require('@mui/icons-material/ErrorOutline');
100
100
  var query$1 = require('@reduxjs/toolkit/query');
101
+ var OpenInNewIcon = require('@mui/icons-material/OpenInNew');
101
102
  var TabList = require('@mui/lab/TabList');
102
103
  var TabPanel = require('@mui/lab/TabPanel');
103
104
  var TabContext = require('@mui/lab/TabContext');
@@ -26538,7 +26539,19 @@ const VisuallyHiddenInput = material.styled("input")({
26538
26539
  });
26539
26540
  const ControlledFileField = (props) => {
26540
26541
  return (jsxRuntime.jsx(reactHookForm.Controller, { control: props.control, name: props.name, render: ({ field: { value, onChange, onBlur, ref }, fieldState: { error } }) => {
26541
- return (jsxRuntime.jsxs(material.FormGroup, { sx: { width: 1 }, color: "secondary", children: [value ? (jsxRuntime.jsxs(material.Stack, { direction: "row", spacing: 1, width: 1, alignItems: "center", children: [jsxRuntime.jsx(material.Typography, { children: value.name }), jsxRuntime.jsx(material.IconButton, { onClick: () => onChange(null), children: jsxRuntime.jsx(ClearIcon$1, { color: "error" }) })] })) : (jsxRuntime.jsxs(material.Button, { component: "label", variant: "contained", startIcon: jsxRuntime.jsx(UploadFileIcon, {}), sx: { maxWidth: 200 }, ...props.extraProps?.slotProps?.button, children: ["Cargar", jsxRuntime.jsx(VisuallyHiddenInput, { type: "file", accept: "image/*", ref: ref, onBlur: onBlur, onChange: (e) => onChange(e.target.files && e.target.files[0]), ...props.extraProps?.slotProps?.input })] })), jsxRuntime.jsx(material.FormHelperText, { error: !!error, children: error ? error.message : " " })] }));
26542
+ if (props.extraProps?.multiple) {
26543
+ const files = value ?? [];
26544
+ const handleAdd = (e) => {
26545
+ const incoming = e.target.files ? Array.from(e.target.files) : [];
26546
+ onChange([...files, ...incoming]);
26547
+ e.target.value = "";
26548
+ };
26549
+ const handleRemove = (index) => {
26550
+ onChange(files.filter((_, i) => i !== index));
26551
+ };
26552
+ return (jsxRuntime.jsxs(material.FormGroup, { sx: { width: 1 }, children: [jsxRuntime.jsxs(material.Stack, { spacing: 1, width: 1, children: [files.map((file, index) => (jsxRuntime.jsxs(material.Stack, { direction: "row", spacing: 1, alignItems: "center", sx: { minWidth: 0 }, children: [jsxRuntime.jsx(material.Typography, { noWrap: true, sx: { flex: 1 }, children: file.name }), jsxRuntime.jsx(material.IconButton, { onClick: () => handleRemove(index), children: jsxRuntime.jsx(ClearIcon$1, { color: "error" }) })] }, index))), jsxRuntime.jsxs(material.Button, { component: "label", variant: "contained", startIcon: jsxRuntime.jsx(UploadFileIcon, {}), sx: { maxWidth: 200 }, ...props.extraProps?.slotProps?.button, children: ["Cargar", jsxRuntime.jsx(VisuallyHiddenInput, { type: "file", multiple: true, accept: "image/*", ref: ref, onBlur: onBlur, onChange: handleAdd, ...props.extraProps?.slotProps?.input })] })] }), jsxRuntime.jsx(material.FormHelperText, { error: !!error, children: error ? error.message : " " })] }));
26553
+ }
26554
+ return (jsxRuntime.jsxs(material.FormGroup, { sx: { width: 1 }, color: "secondary", children: [value ? (jsxRuntime.jsxs(material.Stack, { direction: "row", spacing: 1, width: 1, alignItems: "center", sx: { minWidth: 0 }, children: [jsxRuntime.jsx(material.Typography, { noWrap: true, sx: { flex: 1 }, children: value.name }), jsxRuntime.jsx(material.IconButton, { onClick: () => onChange(null), children: jsxRuntime.jsx(ClearIcon$1, { color: "error" }) })] })) : (jsxRuntime.jsxs(material.Button, { component: "label", variant: "contained", startIcon: jsxRuntime.jsx(UploadFileIcon, {}), sx: { maxWidth: 200 }, ...props.extraProps?.slotProps?.button, children: ["Cargar", jsxRuntime.jsx(VisuallyHiddenInput, { type: "file", accept: "image/*", ref: ref, onBlur: onBlur, onChange: (e) => onChange(e.target.files && e.target.files[0]), ...props.extraProps?.slotProps?.input })] })), jsxRuntime.jsx(material.FormHelperText, { error: !!error, children: error ? error.message : " " })] }));
26542
26555
  } }));
26543
26556
  };
26544
26557
  ControlledFileField.displayName = "ControlledFileField";
@@ -28179,6 +28192,7 @@ const LinkField = ({ url, value, text }) => {
28179
28192
  return jsxRuntime.jsx(material.Link, { href: `${url}/${value}`, children: text });
28180
28193
  };
28181
28194
  const DetailField = (props) => {
28195
+ const [anchor, setAnchor] = React.useState(null);
28182
28196
  const hasLinkToViewPermission = useHasPermission(`${props.navigation?.permission}.view`);
28183
28197
  const value = React.useCallback(() => {
28184
28198
  const { fieldData, type, extraProps, detail_name } = props;
@@ -28198,7 +28212,7 @@ const DetailField = (props) => {
28198
28212
  ? dayjs(fieldData).format("YYYY-MM-DD HH:mm")
28199
28213
  : dayjs(fieldData).format("YYYY-MM-DD");
28200
28214
  case "ControlledFileField":
28201
- return fieldData ? "Archivo" : "N/A";
28215
+ return fieldData ? "Archivo(s)" : "N/A";
28202
28216
  default:
28203
28217
  if (!fieldData)
28204
28218
  return "N/A";
@@ -28216,7 +28230,13 @@ const DetailField = (props) => {
28216
28230
  return (jsxRuntime.jsx(LinkField, { url: props.navigation.url, value: lodash.get(props.fieldData, "value"), text: content }));
28217
28231
  }
28218
28232
  else if (props.type.displayName == "ControlledFileField" && content !== "N/A") {
28219
- return (jsxRuntime.jsx(material.Link, { href: props.fieldData, target: "_blank", rel: "noopener noreferrer", children: content }));
28233
+ const archivos = Array.isArray(props.fieldData)
28234
+ ? props.fieldData.filter(Boolean)
28235
+ : [props.fieldData];
28236
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(material.Badge, { badgeContent: archivos.length, color: "primary", sx: { "& .MuiBadge-badge": { fontSize: 10, minWidth: 16, height: 16 } }, children: jsxRuntime.jsx(material.Button, { size: "small", onClick: (e) => {
28237
+ e.stopPropagation();
28238
+ setAnchor(e.currentTarget);
28239
+ }, children: content }) }), jsxRuntime.jsx(material.Popover, { open: Boolean(anchor), anchorEl: anchor, onClose: () => setAnchor(null), anchorOrigin: { vertical: "bottom", horizontal: "center" }, transformOrigin: { vertical: "top", horizontal: "center" }, onClick: (e) => e.stopPropagation(), children: jsxRuntime.jsx(material.List, { dense: true, disablePadding: true, sx: { minWidth: 140 }, children: archivos.map((archivo, i) => (jsxRuntime.jsxs(material.ListItemButton, { component: "a", href: archivo.imagen ?? archivo, target: "_blank", rel: "noopener noreferrer", onClick: (e) => e.stopPropagation(), children: [jsxRuntime.jsx(material.ListItemText, { primary: `Archivo ${i + 1}` }), jsxRuntime.jsx(OpenInNewIcon, { fontSize: "small", sx: { ml: 1, opacity: 0.6 } })] }, i))) }) })] }));
28220
28240
  }
28221
28241
  else {
28222
28242
  if (Array.isArray(props.fieldData)) {
@@ -28264,6 +28284,8 @@ const Field = (props) => {
28264
28284
  const formData = props.form.watch();
28265
28285
  const show = React.useMemo(() => {
28266
28286
  if (props.dependantOn) {
28287
+ if (props.dependantOn.showOnDetail && props.pageType === "detail")
28288
+ return true;
28267
28289
  return props.dependantOn.method(lodash.get(props.data || formData, props.dependantOn.fieldName), props.dependantOn.value);
28268
28290
  }
28269
28291
  return true;
@@ -28292,6 +28314,7 @@ const FieldArrayField = (props) => {
28292
28314
  keyName: "_id",
28293
28315
  });
28294
28316
  const errors = props.form.formState.errors;
28317
+ const errorMessage = lodash.get(props.form.formState.errors, props.name + ".message");
28295
28318
  const getIndex = React.useCallback((id) => lodash.findIndex(fields, function (field) {
28296
28319
  return field._id == id;
28297
28320
  }), [fields]);
@@ -28372,31 +28395,27 @@ const FieldArrayField = (props) => {
28372
28395
  fieldProps: field.fieldProps,
28373
28396
  extraProps: field.extraProps,
28374
28397
  }) })] }, `grid-${index}`));
28375
- }) }) }), 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 }) })] })] }));
28398
+ }) }) }), 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 }) }), errorMessage && (jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "body1", color: "error", children: errorMessage }) })), jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(xDataGrid.DataGrid, { ...dataGridProps }) })] })] }));
28376
28399
  };
28377
28400
 
28378
28401
  const Section = (props) => {
28379
28402
  const [expanded, setExpanded] = React.useState(true);
28380
28403
  const handleExpandChange = () => {
28381
- setExpanded(prevState => !prevState);
28404
+ setExpanded((prevState) => !prevState);
28382
28405
  };
28383
28406
  const renderField = (field, index) => {
28384
28407
  if (props.first && index == 0)
28385
- lodash.merge(lodash.get(field, 'fieldProps', {}), { autoFocus: true });
28408
+ lodash.merge(lodash.get(field, "fieldProps", {}), { autoFocus: true });
28386
28409
  return (jsxRuntime.jsx(Field, { fieldData: props.data && lodash.get(props.data, field.name), ...field, readOnly:
28387
28410
  // props.validation?.readOnlyFields.includes(field.name) ||
28388
- (props.edit?.readOnlyFields?.names.includes(field.name) && props.edit.readOnlyFields.validator.method(lodash.get(props.data, props.edit.readOnlyFields.validator.field), props.edit.readOnlyFields.validator.value)), form: props.form, pageType: props.pageType, data: props.data }, `F-${index}`));
28411
+ props.edit?.readOnlyFields?.names.includes(field.name) &&
28412
+ props.edit.readOnlyFields.validator.method(lodash.get(props.data, props.edit.readOnlyFields.validator.field), props.edit.readOnlyFields.validator.value), form: props.form, pageType: props.pageType, data: props.data }, `F-${index}`));
28389
28413
  };
28390
28414
  const renderArrayField = (field, index) => (jsxRuntime.jsx(FieldArrayField, { ...field, form: props.form, pageType: props.pageType }, `FA-${index}`));
28391
- return (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 2, bgcolor: props.bgColor, p: 2, borderRadius: 1, children: [(props.title || props.description) &&
28392
- jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 0, children: [props.title &&
28393
- jsxRuntime.jsxs(material.Grid, { size: 12, container: true, onClick: handleExpandChange, sx: {
28394
- cursor: 'pointer'
28395
- }, children: [jsxRuntime.jsx(material.Grid, { children: expanded ? jsxRuntime.jsx(ExpandLessIcon, { fontSize: 'small' }) : jsxRuntime.jsx(ExpandMoreIcon, { fontSize: 'small' }) }), jsxRuntime.jsx(material.Grid, { children: jsxRuntime.jsx(material.Typography, { variant: 'h5', children: props.title }) })] }), props.description &&
28396
- jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: 'caption', color: 'secondary.main', children: props.description }) })] }), expanded &&
28397
- jsxRuntime.jsxs(material.Grid, { size: 12, container: true, direction: 'row', children: [props.fields &&
28398
- props.fields.map((field, index) => renderField(field, index)), props.arrayFields &&
28399
- props.arrayFields.map((arrayField, index) => renderArrayField(arrayField, index)), props.content && props.content(props.data)] })] }));
28415
+ return (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 2, bgcolor: props.bgColor, p: 2, borderRadius: 1, children: [(props.title || props.description) && (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, spacing: 0, children: [props.title && (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, onClick: handleExpandChange, sx: {
28416
+ cursor: "pointer",
28417
+ }, children: [jsxRuntime.jsx(material.Grid, { children: expanded ? (jsxRuntime.jsx(ExpandLessIcon, { fontSize: "small" })) : (jsxRuntime.jsx(ExpandMoreIcon, { fontSize: "small" })) }), jsxRuntime.jsx(material.Grid, { children: jsxRuntime.jsx(material.Typography, { variant: "h5", children: props.title }) })] })), props.description && (jsxRuntime.jsx(material.Grid, { size: 12, children: jsxRuntime.jsx(material.Typography, { variant: "caption", color: "secondary.main", children: props.description }) }))] })), expanded && (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, direction: "row", children: [props.fields && props.fields.map((field, index) => renderField(field, index)), props.arrayFields &&
28418
+ props.arrayFields.map((arrayField, index) => renderArrayField(arrayField, index)), props.content && props.content(props.data)] }))] }));
28400
28419
  };
28401
28420
 
28402
28421
  // ==============================|| VALIDATION ||============================== //
@@ -28605,7 +28624,7 @@ function DetailPage(props) {
28605
28624
  }
28606
28625
  }
28607
28626
  }, [data, dispatch, form, props.slots?.title]);
28608
- const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse },] = props.api.mutate.mutation();
28627
+ const [mutation, { isLoading: mutationIsLoading, isSuccess, data: mutationResponse }] = props.api.mutate.mutation();
28609
28628
  const handleCancel = () => {
28610
28629
  form.reset();
28611
28630
  navigate(-1);
@@ -28615,8 +28634,7 @@ function DetailPage(props) {
28615
28634
  // ==============================|| VALIDATION ||============================== //
28616
28635
  useValidateFieldData(props, form);
28617
28636
  // ==============================|| QUICK RETURN ||============================== //
28618
- if ((!canEdit && props.pageType == "edit") ||
28619
- (fetchError && fetchError.originalStatus == 403))
28637
+ if ((!canEdit && props.pageType == "edit") || (fetchError && fetchError.originalStatus == 403))
28620
28638
  return jsxRuntime.jsx(NotAllowed, {});
28621
28639
  if (fetchError && fetchError.originalStatus == 404)
28622
28640
  return jsxRuntime.jsx(NotFound, {});
@@ -28630,9 +28648,7 @@ function DetailPage(props) {
28630
28648
  props: props.slotProps?.parser,
28631
28649
  };
28632
28650
  const dataToSend = formParser(params);
28633
- mutation(props.edit.useFormData
28634
- ? dataToSend
28635
- : { ...dataToSend, ...props.api.mutate.args })
28651
+ mutation(props.edit.useFormData ? dataToSend : { ...dataToSend, ...props.api.mutate.args })
28636
28652
  .unwrap()
28637
28653
  .then(() => {
28638
28654
  if (!props.slotProps?.button?.save?.disableNavBack)
@@ -28658,17 +28674,26 @@ function DetailPage(props) {
28658
28674
  };
28659
28675
  const onError = (errors) => console.log("Validation Errors:", errors);
28660
28676
  // ==============================|| RENDER SECTIONS ||============================== //
28677
+ const validateDisplay = (field, method, value) => {
28678
+ const validateAgainst = form.watch(field)?.toString();
28679
+ return method(validateAgainst, value);
28680
+ };
28661
28681
  const renderContent = () => {
28662
28682
  let displayed_sections = -1;
28663
28683
  return (jsxRuntime.jsxs(material.Grid, { size: 12, container: true, direction: "column", position: "relative", pb: 2, children: [props.pageType == "detail" && data?.has_history && (jsxRuntime.jsx(HistorialDrawer, { ...props.slotProps?.historial })), props.sections.map((section, index) => {
28664
28684
  if (!section.display)
28665
28685
  return null;
28666
28686
  if (typeof section.display == "object") {
28667
- const validateAgainst = form
28668
- .watch(section.display.field)
28669
- ?.toString();
28670
- if (!section.display.method(validateAgainst, section.display.value))
28671
- return null;
28687
+ if (Array.isArray(section.display)) {
28688
+ if (!section.display
28689
+ .map((item) => validateDisplay(item.field, item.method, item.value))
28690
+ .every((item) => item == true))
28691
+ return null;
28692
+ }
28693
+ else {
28694
+ if (!validateDisplay(section.display.field, section.display.method, section.display.value))
28695
+ return null;
28696
+ }
28672
28697
  }
28673
28698
  displayed_sections += 1;
28674
28699
  return (jsxRuntime.jsx(Section, { data: data, form: form, bgColor: displayed_sections % 2 == 1 ? "white" : "#F7F7F7", pageType: props.pageType, ...section, first: displayed_sections == 0 }, index));
@@ -28678,8 +28703,7 @@ function DetailPage(props) {
28678
28703
  if (props.api.mutate.postAction &&
28679
28704
  isSuccess &&
28680
28705
  "post_action" in mutationResponse &&
28681
- mutationResponse["post_action"]["type"] ===
28682
- props.api.mutate.postAction.type) {
28706
+ mutationResponse["post_action"]["type"] === props.api.mutate.postAction.type) {
28683
28707
  switch (props.api.mutate.postAction.after) {
28684
28708
  // case 'create':
28685
28709
  // if (props.pageType === 'create') return addPropsToNode(props.api.mutate.postAction.node, mutationResponse);