@fctc/widget-logic 2.3.7 → 2.3.8

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/utils.d.mts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as react from 'react';
1
2
  export * from '@fctc/interface-logic/utils';
2
3
 
3
4
  declare const languages: {
@@ -15,6 +16,18 @@ declare const API_APP_URL: {
15
16
 
16
17
  declare const countSum: (data: any[], field: string) => number;
17
18
  declare function mergeButtons(fields: any): any;
19
+ declare function useGetRowIds(tableRef: React.RefObject<HTMLTableElement | null>): {
20
+ rowIds: string[];
21
+ refresh: () => void;
22
+ };
23
+ declare const useSelectionState: ({ typeTable, tableRef, rows, }: {
24
+ typeTable?: string;
25
+ tableRef: any;
26
+ rows?: any[];
27
+ }) => {
28
+ checkedAll: boolean;
29
+ selectedRowKeysRef: react.MutableRefObject<any[]>;
30
+ };
18
31
  declare const getDateRange: (currentDate: any, unit: string) => string[][];
19
32
  declare const convertFieldsToArray: (fields: any[] | undefined | null) => any[];
20
33
  declare function combineContexts(contexts: ({
@@ -31,4 +44,4 @@ type StorageKey = keyof typeof STORAGES;
31
44
  declare function setStorageItemAsync(key: StorageKey, value: string | null): Promise<void>;
32
45
  declare function useStorageState(key: StorageKey): UseStateHook<string>;
33
46
 
34
- export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useStorageState };
47
+ export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useSelectionState, useStorageState };
package/dist/utils.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import * as react from 'react';
1
2
  export * from '@fctc/interface-logic/utils';
2
3
 
3
4
  declare const languages: {
@@ -15,6 +16,18 @@ declare const API_APP_URL: {
15
16
 
16
17
  declare const countSum: (data: any[], field: string) => number;
17
18
  declare function mergeButtons(fields: any): any;
19
+ declare function useGetRowIds(tableRef: React.RefObject<HTMLTableElement | null>): {
20
+ rowIds: string[];
21
+ refresh: () => void;
22
+ };
23
+ declare const useSelectionState: ({ typeTable, tableRef, rows, }: {
24
+ typeTable?: string;
25
+ tableRef: any;
26
+ rows?: any[];
27
+ }) => {
28
+ checkedAll: boolean;
29
+ selectedRowKeysRef: react.MutableRefObject<any[]>;
30
+ };
18
31
  declare const getDateRange: (currentDate: any, unit: string) => string[][];
19
32
  declare const convertFieldsToArray: (fields: any[] | undefined | null) => any[];
20
33
  declare function combineContexts(contexts: ({
@@ -31,4 +44,4 @@ type StorageKey = keyof typeof STORAGES;
31
44
  declare function setStorageItemAsync(key: StorageKey, value: string | null): Promise<void>;
32
45
  declare function useStorageState(key: StorageKey): UseStateHook<string>;
33
46
 
34
- export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useStorageState };
47
+ export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useSelectionState, useStorageState };
package/dist/utils.js CHANGED
@@ -31,6 +31,8 @@ __export(utils_exports, {
31
31
  languages: () => languages,
32
32
  mergeButtons: () => mergeButtons,
33
33
  setStorageItemAsync: () => setStorageItemAsync,
34
+ useGetRowIds: () => useGetRowIds,
35
+ useSelectionState: () => useSelectionState,
34
36
  useStorageState: () => useStorageState
35
37
  });
36
38
  module.exports = __toCommonJS(utils_exports);
@@ -51,6 +53,12 @@ var API_APP_URL = {
51
53
 
52
54
  // src/utils/function.ts
53
55
  var import_react = require("react");
56
+
57
+ // src/store.ts
58
+ var store_exports = {};
59
+ __reExport(store_exports, require("@fctc/interface-logic/store"));
60
+
61
+ // src/utils/function.ts
54
62
  var countSum = (data, field) => {
55
63
  if (!data || !field) return 0;
56
64
  return data.reduce(
@@ -69,6 +77,91 @@ function mergeButtons(fields) {
69
77
  }
70
78
  return others;
71
79
  }
80
+ function isElementVisible(el) {
81
+ const style = window.getComputedStyle(el);
82
+ return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
83
+ }
84
+ function arraysAreEqual(a, b) {
85
+ if (a.length !== b.length) return false;
86
+ const setA = new Set(a);
87
+ const setB = new Set(b);
88
+ if (setA.size !== setB.size) return false;
89
+ for (const val of setA) {
90
+ if (!setB.has(val)) return false;
91
+ }
92
+ return true;
93
+ }
94
+ function useGetRowIds(tableRef) {
95
+ const [rowIds, setRowIds] = (0, import_react.useState)([]);
96
+ const lastRowIdsRef = (0, import_react.useRef)([]);
97
+ const updateVisibleRowIds = (0, import_react.useCallback)(() => {
98
+ const table = tableRef?.current;
99
+ if (!table) return;
100
+ const rows = table.querySelectorAll("tr[data-row-id]");
101
+ const ids = [];
102
+ rows.forEach((row) => {
103
+ const el = row;
104
+ if (isElementVisible(el)) {
105
+ const id = el.getAttribute("data-row-id");
106
+ if (id) ids.push(id);
107
+ }
108
+ });
109
+ const uniqueIds = Array.from(new Set(ids));
110
+ if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
111
+ lastRowIdsRef.current = uniqueIds;
112
+ setRowIds(uniqueIds);
113
+ }
114
+ }, [tableRef]);
115
+ (0, import_react.useEffect)(() => {
116
+ const table = tableRef?.current;
117
+ if (!table) return;
118
+ const observer = new MutationObserver(() => {
119
+ updateVisibleRowIds();
120
+ });
121
+ observer.observe(table, {
122
+ childList: true,
123
+ subtree: true,
124
+ attributes: true,
125
+ attributeFilter: ["style", "class"]
126
+ });
127
+ updateVisibleRowIds();
128
+ return () => {
129
+ observer.disconnect();
130
+ };
131
+ }, [updateVisibleRowIds, tableRef]);
132
+ return { rowIds, refresh: updateVisibleRowIds };
133
+ }
134
+ var useSelectionState = ({
135
+ typeTable,
136
+ tableRef,
137
+ rows
138
+ }) => {
139
+ const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
140
+ const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
141
+ const { rowIds: recordIds } = useGetRowIds(tableRef);
142
+ const selectedRowKeysRef = (0, import_react.useRef)(recordIds);
143
+ const isGroupTable = typeTable === "group";
144
+ const recordsCheckedGroup = (0, import_react.useMemo)(() => {
145
+ if (!rows || !groupByDomain) return 0;
146
+ const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
147
+ return countSum(rows, groupBy);
148
+ }, [rows, groupByDomain]);
149
+ const isAllGroupChecked = (0, import_react.useMemo)(() => {
150
+ if (!isGroupTable || !selectedRowKeys?.length) return false;
151
+ const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
152
+ const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
153
+ const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
154
+ return allGroupsSelected || allRecordsSelected;
155
+ }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
156
+ const isAllNormalChecked = (0, import_react.useMemo)(() => {
157
+ if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
158
+ return selectedRowKeys.length === rows.length && selectedRowKeys.every(
159
+ (id) => rows.some((record) => record.id === id)
160
+ );
161
+ }, [isGroupTable, selectedRowKeys, rows]);
162
+ const checkedAll = isAllGroupChecked || isAllNormalChecked;
163
+ return { checkedAll, selectedRowKeysRef };
164
+ };
72
165
  var getDateRange = (currentDate, unit) => {
73
166
  const date = new Date(currentDate);
74
167
  let dateStart, dateEnd;
@@ -221,6 +314,8 @@ __reExport(utils_exports, require("@fctc/interface-logic/utils"), module.exports
221
314
  languages,
222
315
  mergeButtons,
223
316
  setStorageItemAsync,
317
+ useGetRowIds,
318
+ useSelectionState,
224
319
  useStorageState,
225
320
  ...require("@fctc/interface-logic/utils")
226
321
  });
package/dist/utils.mjs CHANGED
@@ -1,3 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+
1
15
  // src/utils/constants.ts
2
16
  var languages = [
3
17
  { id: "vi_VN", name: "VIE" },
@@ -13,7 +27,21 @@ var API_APP_URL = {
13
27
  };
14
28
 
15
29
  // src/utils/function.ts
16
- import { useCallback, useEffect, useReducer } from "react";
30
+ import {
31
+ useCallback,
32
+ useEffect,
33
+ useMemo,
34
+ useReducer,
35
+ useRef,
36
+ useState
37
+ } from "react";
38
+
39
+ // src/store.ts
40
+ var store_exports = {};
41
+ __reExport(store_exports, store_star);
42
+ import * as store_star from "@fctc/interface-logic/store";
43
+
44
+ // src/utils/function.ts
17
45
  var countSum = (data, field) => {
18
46
  if (!data || !field) return 0;
19
47
  return data.reduce(
@@ -32,6 +60,91 @@ function mergeButtons(fields) {
32
60
  }
33
61
  return others;
34
62
  }
63
+ function isElementVisible(el) {
64
+ const style = window.getComputedStyle(el);
65
+ return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
66
+ }
67
+ function arraysAreEqual(a, b) {
68
+ if (a.length !== b.length) return false;
69
+ const setA = new Set(a);
70
+ const setB = new Set(b);
71
+ if (setA.size !== setB.size) return false;
72
+ for (const val of setA) {
73
+ if (!setB.has(val)) return false;
74
+ }
75
+ return true;
76
+ }
77
+ function useGetRowIds(tableRef) {
78
+ const [rowIds, setRowIds] = useState([]);
79
+ const lastRowIdsRef = useRef([]);
80
+ const updateVisibleRowIds = useCallback(() => {
81
+ const table = tableRef?.current;
82
+ if (!table) return;
83
+ const rows = table.querySelectorAll("tr[data-row-id]");
84
+ const ids = [];
85
+ rows.forEach((row) => {
86
+ const el = row;
87
+ if (isElementVisible(el)) {
88
+ const id = el.getAttribute("data-row-id");
89
+ if (id) ids.push(id);
90
+ }
91
+ });
92
+ const uniqueIds = Array.from(new Set(ids));
93
+ if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
94
+ lastRowIdsRef.current = uniqueIds;
95
+ setRowIds(uniqueIds);
96
+ }
97
+ }, [tableRef]);
98
+ useEffect(() => {
99
+ const table = tableRef?.current;
100
+ if (!table) return;
101
+ const observer = new MutationObserver(() => {
102
+ updateVisibleRowIds();
103
+ });
104
+ observer.observe(table, {
105
+ childList: true,
106
+ subtree: true,
107
+ attributes: true,
108
+ attributeFilter: ["style", "class"]
109
+ });
110
+ updateVisibleRowIds();
111
+ return () => {
112
+ observer.disconnect();
113
+ };
114
+ }, [updateVisibleRowIds, tableRef]);
115
+ return { rowIds, refresh: updateVisibleRowIds };
116
+ }
117
+ var useSelectionState = ({
118
+ typeTable,
119
+ tableRef,
120
+ rows
121
+ }) => {
122
+ const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
123
+ const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
124
+ const { rowIds: recordIds } = useGetRowIds(tableRef);
125
+ const selectedRowKeysRef = useRef(recordIds);
126
+ const isGroupTable = typeTable === "group";
127
+ const recordsCheckedGroup = useMemo(() => {
128
+ if (!rows || !groupByDomain) return 0;
129
+ const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
130
+ return countSum(rows, groupBy);
131
+ }, [rows, groupByDomain]);
132
+ const isAllGroupChecked = useMemo(() => {
133
+ if (!isGroupTable || !selectedRowKeys?.length) return false;
134
+ const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
135
+ const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
136
+ const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
137
+ return allGroupsSelected || allRecordsSelected;
138
+ }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
139
+ const isAllNormalChecked = useMemo(() => {
140
+ if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
141
+ return selectedRowKeys.length === rows.length && selectedRowKeys.every(
142
+ (id) => rows.some((record) => record.id === id)
143
+ );
144
+ }, [isGroupTable, selectedRowKeys, rows]);
145
+ const checkedAll = isAllGroupChecked || isAllNormalChecked;
146
+ return { checkedAll, selectedRowKeysRef };
147
+ };
35
148
  var getDateRange = (currentDate, unit) => {
36
149
  const date = new Date(currentDate);
37
150
  let dateStart, dateEnd;
@@ -183,5 +296,7 @@ export {
183
296
  languages,
184
297
  mergeButtons,
185
298
  setStorageItemAsync,
299
+ useGetRowIds,
300
+ useSelectionState,
186
301
  useStorageState
187
302
  };
package/dist/widget.d.mts CHANGED
@@ -72,10 +72,10 @@ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {
72
72
  handleCreateNewOnPage: () => Promise<void>;
73
73
  optionsObject: any;
74
74
  totalRows: any;
75
- rows: any;
75
+ rows: any[];
76
76
  columns: any;
77
77
  onToggleColumnOptional: (item: any) => void;
78
- typeTable: "list" | "calendar" | "group" | undefined;
78
+ typeTable: "list" | "group" | "calendar" | undefined;
79
79
  isLoading: boolean;
80
80
  isFetched: boolean;
81
81
  isPlaceholderData: boolean;
@@ -203,15 +203,11 @@ declare const binaryFieldController: (props: IInputFieldProps) => {
203
203
  interface ITableHeadProps {
204
204
  typeTable: string;
205
205
  rows: any[];
206
- tableRef: React.RefObject<HTMLTableElement | null>;
207
- groupByList: any;
208
- selectedRowKeys: any;
206
+ selectedRowKeysRef: any;
209
207
  }
210
208
 
211
209
  declare const tableHeadController: (props: ITableHeadProps) => {
212
210
  handleCheckBoxAll: (event: React.ChangeEvent<HTMLInputElement>) => void;
213
- checkedAll: any;
214
- selectedRowKeysRef: react.MutableRefObject<any[]>;
215
211
  };
216
212
 
217
213
  interface ITableProps {
@@ -235,28 +231,45 @@ interface ISelctionStateProps {
235
231
  }
236
232
 
237
233
  declare const tableController: ({ data }: ITableProps) => {
238
- rows: any;
234
+ rows: any[];
239
235
  columns: any;
240
236
  onToggleColumnOptional: (item: any) => void;
241
- typeTable: "list" | "calendar" | "group" | undefined;
237
+ typeTable: "list" | "group" | "calendar" | undefined;
242
238
  };
243
239
 
244
240
  declare const tableGroupController: (props: any) => {
245
- onExpandChildGroup: () => void;
241
+ handleExpandChildGroup: () => void;
246
242
  colEmptyGroup: {
247
243
  fromStart: number;
248
244
  fromEnd: number;
249
245
  };
246
+ leftPadding: string;
250
247
  isShowGroup: boolean;
251
- isDataGroupFetched: boolean;
252
- isDataPlaceHolder: boolean;
248
+ isQueryFetched: boolean;
253
249
  nameGroupWithCount: string;
250
+ columns: any;
251
+ row: any;
252
+ isPlaceholderData: boolean;
254
253
  columnsGroup: any;
255
- rowsGroup: any;
256
- dataGroup: any;
254
+ indexRow: any;
255
+ rowsGroup: any[];
256
+ model: any;
257
+ viewData: any;
258
+ renderField: any;
259
+ level: any;
260
+ specification: any;
261
+ context: any;
262
+ checkedAll: any;
263
+ isDisplayCheckbox: any;
264
+ isAutoSelect: any;
265
+ setIsAutoSelect: any;
266
+ selectedRowKeysRef: any;
267
+ initVal: {
268
+ [x: string]: any;
269
+ };
270
+ dataResponse: any;
257
271
  pageGroup: any;
258
272
  setPageGroup: react.Dispatch<any>;
259
- typeTableGroup: "list" | "calendar" | "group" | undefined;
260
273
  };
261
274
 
262
275
  declare const searchController: ({ viewData, model, domain, context, fieldsList, }: {
package/dist/widget.d.ts CHANGED
@@ -72,10 +72,10 @@ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {
72
72
  handleCreateNewOnPage: () => Promise<void>;
73
73
  optionsObject: any;
74
74
  totalRows: any;
75
- rows: any;
75
+ rows: any[];
76
76
  columns: any;
77
77
  onToggleColumnOptional: (item: any) => void;
78
- typeTable: "list" | "calendar" | "group" | undefined;
78
+ typeTable: "list" | "group" | "calendar" | undefined;
79
79
  isLoading: boolean;
80
80
  isFetched: boolean;
81
81
  isPlaceholderData: boolean;
@@ -203,15 +203,11 @@ declare const binaryFieldController: (props: IInputFieldProps) => {
203
203
  interface ITableHeadProps {
204
204
  typeTable: string;
205
205
  rows: any[];
206
- tableRef: React.RefObject<HTMLTableElement | null>;
207
- groupByList: any;
208
- selectedRowKeys: any;
206
+ selectedRowKeysRef: any;
209
207
  }
210
208
 
211
209
  declare const tableHeadController: (props: ITableHeadProps) => {
212
210
  handleCheckBoxAll: (event: React.ChangeEvent<HTMLInputElement>) => void;
213
- checkedAll: any;
214
- selectedRowKeysRef: react.MutableRefObject<any[]>;
215
211
  };
216
212
 
217
213
  interface ITableProps {
@@ -235,28 +231,45 @@ interface ISelctionStateProps {
235
231
  }
236
232
 
237
233
  declare const tableController: ({ data }: ITableProps) => {
238
- rows: any;
234
+ rows: any[];
239
235
  columns: any;
240
236
  onToggleColumnOptional: (item: any) => void;
241
- typeTable: "list" | "calendar" | "group" | undefined;
237
+ typeTable: "list" | "group" | "calendar" | undefined;
242
238
  };
243
239
 
244
240
  declare const tableGroupController: (props: any) => {
245
- onExpandChildGroup: () => void;
241
+ handleExpandChildGroup: () => void;
246
242
  colEmptyGroup: {
247
243
  fromStart: number;
248
244
  fromEnd: number;
249
245
  };
246
+ leftPadding: string;
250
247
  isShowGroup: boolean;
251
- isDataGroupFetched: boolean;
252
- isDataPlaceHolder: boolean;
248
+ isQueryFetched: boolean;
253
249
  nameGroupWithCount: string;
250
+ columns: any;
251
+ row: any;
252
+ isPlaceholderData: boolean;
254
253
  columnsGroup: any;
255
- rowsGroup: any;
256
- dataGroup: any;
254
+ indexRow: any;
255
+ rowsGroup: any[];
256
+ model: any;
257
+ viewData: any;
258
+ renderField: any;
259
+ level: any;
260
+ specification: any;
261
+ context: any;
262
+ checkedAll: any;
263
+ isDisplayCheckbox: any;
264
+ isAutoSelect: any;
265
+ setIsAutoSelect: any;
266
+ selectedRowKeysRef: any;
267
+ initVal: {
268
+ [x: string]: any;
269
+ };
270
+ dataResponse: any;
257
271
  pageGroup: any;
258
272
  setPageGroup: react.Dispatch<any>;
259
- typeTableGroup: "list" | "calendar" | "group" | undefined;
260
273
  };
261
274
 
262
275
  declare const searchController: ({ viewData, model, domain, context, fieldsList, }: {