@m4l/layouts 9.4.0-AQ20260113.beta.1 → 9.4.0-AQ20260114.beta.1

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,35 @@
1
1
  import { GetLabelType } from '@m4l/core';
2
2
  export interface UseRefreshData<TRow> {
3
+ /**
4
+ * Function to refresh the data
5
+ */
3
6
  refreshPaginate: () => void;
7
+ /**
8
+ * Rows to refresh
9
+ */
4
10
  rows: TRow[];
11
+ /**
12
+ * Function to get the label
13
+ */
5
14
  getLabel: GetLabelType;
6
15
  }
16
+ /**
17
+ * fieldValue with generic that allow to use nested attributes from a interface or object
18
+ * example: 'fieldValue' = 'object.field1.field2'
19
+ */
20
+ export type DeepKeyOf<TRow> = TRow extends object ? {
21
+ [Key in keyof TRow & string]: NonNullable<TRow[Key]> extends object ? Key | `${Key}.${DeepKeyOf<NonNullable<TRow[Key]>>}` : Key;
22
+ }[keyof TRow & string] : never;
23
+ /**
24
+ * Interface to trigger the refresh when a specific attribute is equal to a specific value
25
+ */
26
+ export interface TriggerRefreshWhen<TRow> {
27
+ /**
28
+ * Attribute to check if it is equal to the value
29
+ */
30
+ attribute: DeepKeyOf<TRow>;
31
+ /**
32
+ * Value to compare with the attribute
33
+ */
34
+ equals: string | number | boolean;
35
+ }
@@ -1,11 +1,11 @@
1
1
  import { RowKey } from '@m4l/components';
2
- import { UseRefreshData } from './types';
2
+ import { TriggerRefreshWhen, UseRefreshData } from './types';
3
3
  /**
4
4
  * Hook that manages the refresh of the data and the selected rows.
5
5
  * Note: This hook could be use in every module that needs to refresh the data and the selected rows.
6
6
  */
7
7
  export declare const useRefreshData: <TRow>(useRefreshDataProps: UseRefreshData<TRow>) => {
8
- refresh: (idRowParam?: RowKey) => void;
8
+ refresh: (rowParam?: TRow | RowKey, triggerSelectedRowWhen?: TriggerRefreshWhen<TRow>) => void;
9
9
  onSelectedRowsChange: (newRowsSelectSet: ReadonlySet<RowKey>) => void;
10
10
  selectedRows: ReadonlySet<RowKey>;
11
11
  focusOnRowKey: RowKey | undefined;
@@ -31,17 +31,24 @@ const useRefreshData = (useRefreshDataProps) => {
31
31
  }
32
32
  }
33
33
  }, [rows]);
34
- const refresh = useCallback((idRowParam) => {
35
- if (idRowParam !== void 0 && (typeof idRowParam === "string" || typeof idRowParam === "number")) {
36
- setFocusOnRowKey(idRowParam);
37
- setSelectedRows(/* @__PURE__ */ new Set([idRowParam]));
38
- setValidateShowRowCreate({ show: true, idRow: idRowParam });
39
- } else {
40
- setValidateShowRowCreate({ show: false, idRow: void 0 });
41
- setFocusOnRowKey(void 0);
34
+ const getRowKey = useCallback((rowParam) => {
35
+ if (typeof rowParam === "string" || typeof rowParam === "number") {
36
+ return rowParam;
37
+ }
38
+ if (typeof rowParam === "object" && rowParam !== null && "id" in rowParam && (typeof rowParam?.id === "string" || typeof rowParam?.id === "number")) {
39
+ return rowParam?.id;
40
+ }
41
+ return void 0;
42
+ }, []);
43
+ const refresh = useCallback((rowParam, triggerSelectedRowWhen) => {
44
+ const idRow = getRowKey(rowParam);
45
+ setFocusOnRowKey(idRow);
46
+ setValidateShowRowCreate({ show: idRow !== void 0, idRow });
47
+ if (idRow !== void 0 && triggerSelectedRowWhen && typeof rowParam === "object" && Object.prototype.hasOwnProperty.call(rowParam, triggerSelectedRowWhen.attribute) && rowParam[triggerSelectedRowWhen.attribute] === triggerSelectedRowWhen.equals) {
48
+ setSelectedRows(/* @__PURE__ */ new Set([idRow]));
42
49
  }
43
50
  refreshPaginate();
44
- }, [refreshPaginate, setSelectedRows]);
51
+ }, [refreshPaginate, setSelectedRows, getRowKey]);
45
52
  return { refresh, onSelectedRowsChange, selectedRows, focusOnRowKey };
46
53
  };
47
54
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@m4l/layouts",
3
- "version": "9.4.0-AQ20260113.beta.1",
3
+ "version": "9.4.0-AQ20260114.beta.1",
4
4
  "license": "UNLICENSED",
5
5
  "author": "M4L Team",
6
6
  "lint-staged": {