@m4l/components 9.4.20 → 9.4.21

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.
@@ -12,3 +12,4 @@ export { getViewSpecificConfig } from './shared/getViewSpecificConfig';
12
12
  export { getViewSuffix } from './shared/getViewSuffix';
13
13
  export { getInitialColumnsConfig } from './shared/getInitialColumnsConfig';
14
14
  export { getDataGridRowsFromSet } from './shared/getDataGridRowsFromSet';
15
+ export { getDefaultAction } from './shared/getDefaultAction';
@@ -0,0 +1,8 @@
1
+ import { DataGridRowAction, DataGridMenuItemAction } from '../../../types';
2
+ /**
3
+ * Busca la acción marcada como default (isDefault: true) en un array de DataGridRowAction.
4
+ * Se usa para determinar qué acción ejecutar en el double click de una fila.
5
+ * @param actions - Array de acciones del DataGrid
6
+ * @returns La acción default si existe, undefined si no hay ninguna
7
+ */
8
+ export declare const getDefaultAction: (actions: DataGridRowAction[]) => DataGridMenuItemAction | undefined;
@@ -0,0 +1,12 @@
1
+ const getDefaultAction = (actions) => {
2
+ return actions.find(
3
+ (action) => (
4
+ // Verifica que sea un menuItem (type es 'menuItem' o undefined por defecto)
5
+ (action.type === "menuItem" || action.type === void 0) && // Verifica que tenga la propiedad isDefault y sea true
6
+ "isDefault" in action && action.isDefault === true
7
+ )
8
+ );
9
+ };
10
+ export {
11
+ getDefaultAction as g
12
+ };
@@ -0,0 +1 @@
1
+ export { getDefaultAction } from './getDefaultAction';
@@ -2,7 +2,7 @@ export { DataGrid } from './components/DataGridMain';
2
2
  export { TreeDataGrid } from './components/TreeDataGrid';
3
3
  export * from './formatters';
4
4
  export type { Column, RenderEditCellProps, RenderCellProps, } from 'react-data-grid';
5
- export type { RowKey, ChangeConfig, ChangeUserColumn, RowActionsGetter, RowKeyGetter, TreeProps, TreeDataGridProps, } from './types';
5
+ export type { RowKey, ChangeConfig, ChangeUserColumn, RowActionsGetter, RowKeyGetter, TreeProps, TreeDataGridProps, DataGridRowAction, } from './types';
6
6
  export type { IGridConfigExtended, BaseConfigColumn, } from './contexts/DataGridContext/types';
7
7
  export type { IGridConfig } from './helpers/persistence/getColumnsWidth/types';
8
8
  export { getDataGridComponentsDictionary } from './dictionary';
@@ -1,7 +1,7 @@
1
1
  import { Maybe } from '@m4l/core';
2
2
  import { Theme } from '@mui/material/styles';
3
3
  import { Column, RowsChangeData, RenderCellProps, DataGridProps as NativeDataGridProps } from 'react-data-grid';
4
- import { MenuAction } from '../MenuActions/types';
4
+ import { MenuAction, MenuItemAction } from '../MenuActions/types';
5
5
  import { ActionsSlots, ColumnIconFormatterSlots, ColumnsConfigSlots, ControlNavigateSlots, DataGridSlots, RowsCountSlots, TableSlots, TextEditorSlots } from './slots/DataGridEnum';
6
6
  import { OverridesStyleRules } from '@mui/material/styles/overrides';
7
7
  import { DATAGRID_PREFIX_NAME } from './constants';
@@ -139,7 +139,22 @@ export interface FilterSettings {
139
139
  filtersApplied: FilterApplied[];
140
140
  onChange: (event: FilterChangeEvent) => void;
141
141
  }
142
- export type RowActionsGetter<TRow> = (row: TRow) => MenuAction[];
142
+ /**
143
+ * Tipo extendido de MenuItemAction específico para DataGrid.
144
+ * Agrega la propiedad `isDefault` para acciones que se ejecutan al hacer double-click en una fila.
145
+ */
146
+ export interface DataGridMenuItemAction extends MenuItemAction {
147
+ /**
148
+ * Si true, esta acción se ejecutará al hacer double-click en la fila del DataGrid.
149
+ * Solo una acción debe tener isDefault: true por fila.
150
+ */
151
+ isDefault?: boolean;
152
+ }
153
+ /**
154
+ * Tipo de acciones para DataGrid. Igual que MenuAction pero con soporte para isDefault.
155
+ */
156
+ export type DataGridRowAction = DataGridMenuItemAction | Exclude<MenuAction, MenuItemAction>;
157
+ export type RowActionsGetter<TRow> = (row: TRow) => DataGridRowAction[];
143
158
  export type RowKeyGetter<TRow, TKey extends RowKey = RowKey> = (row: TRow) => TKey;
144
159
  /**--------------------Termina tipado de filtros-------------------------------------------- */
145
160
  export interface GridProps<TRow, TSummaryRow, TKey extends RowKey = RowKey> extends Omit<NativeDataGridProps<TRow, TSummaryRow>, 'rowKeyGetter' | 'rows' | 'columns' | 'onRowsChange' | 'selectedRows' | 'onSelectedRowsChange' | 'renderers'> {
@@ -5,6 +5,8 @@ import { deepEqual } from "fast-equals";
5
5
  import { u as useCardContent } from "../../hooks/useCardContent/useCardContent.js";
6
6
  import { C as CardHeader } from "./subcomponents/CardHeader/CardHeader.js";
7
7
  import { L as LazyLoadCard } from "./subcomponents/LazyLoadCard/LazyLoadCard.js";
8
+ import { g as getDefaultAction } from "../../../../helpers/shared/getDefaultAction/getDefaultAction.js";
9
+ import { u as useDataGrid } from "../../../../hooks/shared/useDataGrid/useDataGrid.js";
8
10
  function CardRowComponent({
9
11
  row,
10
12
  rows,
@@ -23,6 +25,7 @@ function CardRowComponent({
23
25
  onCheckedRowsChange,
24
26
  onOpenDetail
25
27
  }) {
28
+ const { rowActionsGetter } = useDataGrid();
26
29
  const hasCustomRender = customRender !== void 0;
27
30
  const { cardContent } = useCardContent({
28
31
  row,
@@ -75,6 +78,23 @@ function CardRowComponent({
75
78
  onSelectedRowsChange(mySet);
76
79
  }
77
80
  };
81
+ const onCardDoubleClick = (e) => {
82
+ const target = e.target;
83
+ const isInteractiveElement = target.closest(
84
+ 'input, button, a, [role="button"], .MuiCheckbox-root, .MuiIconButton-root'
85
+ );
86
+ if (isInteractiveElement) {
87
+ return;
88
+ }
89
+ if (!rowActionsGetter) {
90
+ return;
91
+ }
92
+ const actions = rowActionsGetter(row);
93
+ const defaultAction = getDefaultAction(actions);
94
+ if (defaultAction?.onClick) {
95
+ defaultAction.onClick(row);
96
+ }
97
+ };
78
98
  return /* @__PURE__ */ jsx(LazyLoadCard, { threshold: 200, minHeight, rowKey: rowKeyGetter(row), children: /* @__PURE__ */ jsx(
79
99
  CardStyled,
80
100
  {
@@ -85,6 +105,7 @@ function CardRowComponent({
85
105
  selected: selectedRows?.has(rowKeyGetter(row))
86
106
  },
87
107
  onClick: onCardClick,
108
+ onDoubleClick: onCardDoubleClick,
88
109
  "data-testid": "data-grid-card",
89
110
  "data-row-key": rowKeyGetter(row),
90
111
  children: content
@@ -10,6 +10,7 @@ import { d as defaultRowGrouper } from "./helpers/defaultRowGrouper/defaultRowGr
10
10
  import { u as useHeaderMenuActions } from "./hooks/useHeaderMenuActions/useHeaderMenuActions.js";
11
11
  import { f as filterHeight } from "./subcomponents/SelectColumn/SelectColumn.js";
12
12
  import { H as HeaderRenderClick } from "./subcomponents/HeaderRenderClick/HeaderRenderClick.js";
13
+ import { g as getDefaultAction } from "../../helpers/shared/getDefaultAction/getDefaultAction.js";
13
14
  import { u as useFilters } from "../../hooks/shared/useFilters/useFilters.js";
14
15
  import { u as useDataGrid } from "../../hooks/shared/useDataGrid/useDataGrid.js";
15
16
  import { C as CheckboxFormatter } from "./subcomponents/CheckboxFormatter/CheckboxFormatter.js";
@@ -65,7 +66,8 @@ function TableView(props) {
65
66
  size,
66
67
  sortColumns,
67
68
  setSortColumns,
68
- columnsConfig
69
+ columnsConfig,
70
+ rowActionsGetter
69
71
  } = useDataGrid();
70
72
  const groupBy = useMemo(() => {
71
73
  if (!treeProps) {
@@ -102,6 +104,16 @@ function TableView(props) {
102
104
  onSelectedRowsChange(mySet);
103
105
  }
104
106
  };
107
+ const onCellDoubleClick = ({ row }) => {
108
+ if (!rowActionsGetter) {
109
+ return;
110
+ }
111
+ const actions = rowActionsGetter(row);
112
+ const defaultAction = getDefaultAction(actions);
113
+ if (defaultAction?.onClick) {
114
+ defaultAction.onClick(row);
115
+ }
116
+ };
105
117
  useEffect(() => {
106
118
  let columnIndice = 0;
107
119
  for (const column of finalColumns) {
@@ -176,6 +188,7 @@ function TableView(props) {
176
188
  selectedRows,
177
189
  onSelectedRowsChange,
178
190
  onCellClick,
191
+ onCellDoubleClick,
179
192
  rowHeight: currentRowHeight,
180
193
  rowKeyGetter,
181
194
  renderers: {
@@ -203,6 +216,7 @@ function TableView(props) {
203
216
  selectedRows,
204
217
  onSelectedRowsChange,
205
218
  onCellClick,
219
+ onCellDoubleClick,
206
220
  rowHeight: currentRowHeight,
207
221
  rowKeyGetter,
208
222
  renderers: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/components",
3
- "version": "9.4.20",
3
+ "version": "9.4.21",
4
4
  "license": "UNLICENSED",
5
5
  "description": "M4L Components",
6
6
  "lint-staged": {