@m4l/layouts 9.4.0-AQ20260113.beta.1 → 9.4.0-AQ20260115.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,39 @@
|
|
|
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;
|
|
15
|
+
/**
|
|
16
|
+
* Trigger to select the row when a specific attribute is equal to a specific value
|
|
17
|
+
*/
|
|
18
|
+
triggerSelectedRowWhen?: TriggerRefreshWhen<TRow>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* fieldValue with generic that allow to use nested attributes from a interface or object
|
|
22
|
+
* example: 'fieldValue' = 'object.field1.field2'
|
|
23
|
+
*/
|
|
24
|
+
export type DeepKeyOf<TRow> = TRow extends object ? {
|
|
25
|
+
[Key in keyof TRow & string]: NonNullable<TRow[Key]> extends object ? Key | `${Key}.${DeepKeyOf<NonNullable<TRow[Key]>>}` : Key;
|
|
26
|
+
}[keyof TRow & string] : never;
|
|
27
|
+
/**
|
|
28
|
+
* Interface to trigger the refresh when a specific attribute is equal to a specific value
|
|
29
|
+
*/
|
|
30
|
+
export interface TriggerRefreshWhen<TRow> {
|
|
31
|
+
/**
|
|
32
|
+
* Attribute to check if it is equal to the value
|
|
33
|
+
*/
|
|
34
|
+
attribute: DeepKeyOf<TRow>;
|
|
35
|
+
/**
|
|
36
|
+
* Value to compare with the attribute
|
|
37
|
+
*/
|
|
38
|
+
equals: string | number | boolean;
|
|
6
39
|
}
|
|
@@ -5,7 +5,7 @@ import { UseRefreshData } from './types';
|
|
|
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: (
|
|
8
|
+
refresh: (rowParam?: TRow | RowKey) => void;
|
|
9
9
|
onSelectedRowsChange: (newRowsSelectSet: ReadonlySet<RowKey>) => void;
|
|
10
10
|
selectedRows: ReadonlySet<RowKey>;
|
|
11
11
|
focusOnRowKey: RowKey | undefined;
|
|
@@ -4,7 +4,7 @@ import { useHostTools } from "@m4l/core";
|
|
|
4
4
|
import { u as useMasterDetail } from "../useMasterDetail/index.js";
|
|
5
5
|
import { U as USE_REFRESH_DATA_DICTIONARY } from "./dictionary.js";
|
|
6
6
|
const useRefreshData = (useRefreshDataProps) => {
|
|
7
|
-
const { rows, refreshPaginate, getLabel } = useRefreshDataProps;
|
|
7
|
+
const { rows, refreshPaginate, getLabel, triggerSelectedRowWhen } = useRefreshDataProps;
|
|
8
8
|
const { toast } = useHostTools();
|
|
9
9
|
const { onChangeMasterSelection } = useMasterDetail();
|
|
10
10
|
const [validateShowRowCreate, setValidateShowRowCreate] = useState({ show: false, idRow: void 0 });
|
|
@@ -31,17 +31,28 @@ const useRefreshData = (useRefreshDataProps) => {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}, [rows]);
|
|
34
|
-
const
|
|
35
|
-
if (
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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) => {
|
|
44
|
+
const idRow = getRowKey(rowParam);
|
|
45
|
+
setFocusOnRowKey(idRow);
|
|
46
|
+
setValidateShowRowCreate({ show: idRow !== void 0, idRow });
|
|
47
|
+
if (idRow !== void 0) {
|
|
48
|
+
if (triggerSelectedRowWhen === void 0) {
|
|
49
|
+
setSelectedRows(/* @__PURE__ */ new Set([idRow]));
|
|
50
|
+
} else if (triggerSelectedRowWhen !== void 0 && typeof rowParam === "object" && Object.prototype.hasOwnProperty.call(rowParam, triggerSelectedRowWhen.attribute) && rowParam[triggerSelectedRowWhen.attribute] === triggerSelectedRowWhen.equals) {
|
|
51
|
+
setSelectedRows(/* @__PURE__ */ new Set([idRow]));
|
|
52
|
+
}
|
|
42
53
|
}
|
|
43
54
|
refreshPaginate();
|
|
44
|
-
}, [refreshPaginate, setSelectedRows]);
|
|
55
|
+
}, [refreshPaginate, setSelectedRows, getRowKey]);
|
|
45
56
|
return { refresh, onSelectedRowsChange, selectedRows, focusOnRowKey };
|
|
46
57
|
};
|
|
47
58
|
export {
|