@fctc/widget-logic 2.0.9 → 2.1.0
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/hooks.d.mts +12 -1
- package/dist/hooks.d.ts +12 -1
- package/dist/hooks.js +179 -6
- package/dist/hooks.mjs +179 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +204 -246
- package/dist/index.mjs +157 -199
- package/dist/types.d.mts +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/widget.d.mts +3 -29
- package/dist/widget.d.ts +3 -29
- package/dist/widget.js +194 -238
- package/dist/widget.mjs +151 -194
- package/package.json +2 -2
package/dist/hooks.d.mts
CHANGED
|
@@ -955,6 +955,17 @@ declare const AppProvider: ({ children }: {
|
|
|
955
955
|
}) => react_jsx_runtime.JSX.Element;
|
|
956
956
|
declare const useAppProvider: () => AppProviderType;
|
|
957
957
|
|
|
958
|
+
interface TActionDetailType {
|
|
959
|
+
id: number;
|
|
960
|
+
res_model: string;
|
|
961
|
+
views: any[][];
|
|
962
|
+
}
|
|
963
|
+
declare const useMenuItem: (props: any) => {
|
|
964
|
+
handleClick: () => void;
|
|
965
|
+
path: string;
|
|
966
|
+
queryActionDetail: TActionDetailType;
|
|
967
|
+
};
|
|
968
|
+
|
|
958
969
|
declare const DEFAULT_EVENTS: readonly ["mousedown", "touchstart"];
|
|
959
970
|
type EventType = (typeof DEFAULT_EVENTS)[number];
|
|
960
971
|
interface UseClickOutsideOptions {
|
|
@@ -967,4 +978,4 @@ declare const useClickOutside: ({ handler, events, nodes, refs, }: UseClickOutsi
|
|
|
967
978
|
|
|
968
979
|
declare function useDebounce<T>(value: T, delay: number): [T];
|
|
969
980
|
|
|
970
|
-
export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useListData, type useListDataType, useMenu, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
|
|
981
|
+
export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
|
package/dist/hooks.d.ts
CHANGED
|
@@ -955,6 +955,17 @@ declare const AppProvider: ({ children }: {
|
|
|
955
955
|
}) => react_jsx_runtime.JSX.Element;
|
|
956
956
|
declare const useAppProvider: () => AppProviderType;
|
|
957
957
|
|
|
958
|
+
interface TActionDetailType {
|
|
959
|
+
id: number;
|
|
960
|
+
res_model: string;
|
|
961
|
+
views: any[][];
|
|
962
|
+
}
|
|
963
|
+
declare const useMenuItem: (props: any) => {
|
|
964
|
+
handleClick: () => void;
|
|
965
|
+
path: string;
|
|
966
|
+
queryActionDetail: TActionDetailType;
|
|
967
|
+
};
|
|
968
|
+
|
|
958
969
|
declare const DEFAULT_EVENTS: readonly ["mousedown", "touchstart"];
|
|
959
970
|
type EventType = (typeof DEFAULT_EVENTS)[number];
|
|
960
971
|
interface UseClickOutsideOptions {
|
|
@@ -967,4 +978,4 @@ declare const useClickOutside: ({ handler, events, nodes, refs, }: UseClickOutsi
|
|
|
967
978
|
|
|
968
979
|
declare function useDebounce<T>(value: T, delay: number): [T];
|
|
969
980
|
|
|
970
|
-
export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useListData, type useListDataType, useMenu, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
|
|
981
|
+
export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
|
package/dist/hooks.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(hooks_exports, {
|
|
|
31
31
|
useDetail: () => useDetail,
|
|
32
32
|
useListData: () => useListData,
|
|
33
33
|
useMenu: () => useMenu,
|
|
34
|
+
useMenuItem: () => useMenuItem,
|
|
34
35
|
useProfile: () => useProfile,
|
|
35
36
|
useUser: () => useUser,
|
|
36
37
|
useViewV2: () => useViewV2
|
|
@@ -162,6 +163,109 @@ var store_exports = {};
|
|
|
162
163
|
__reExport(store_exports, require("@fctc/interface-logic/store"));
|
|
163
164
|
|
|
164
165
|
// src/utils/function.ts
|
|
166
|
+
var countSum = (data, field) => {
|
|
167
|
+
if (!data || !field) return 0;
|
|
168
|
+
return data.reduce(
|
|
169
|
+
(total, item) => total + (item?.[`${field}_count`] || 0),
|
|
170
|
+
0
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
function mergeButtons(fields) {
|
|
174
|
+
const buttons = fields?.filter((f) => f.type_co === "button");
|
|
175
|
+
const others = fields?.filter((f) => f.type_co !== "button");
|
|
176
|
+
if (buttons?.length) {
|
|
177
|
+
others.push({
|
|
178
|
+
type_co: "buttons",
|
|
179
|
+
buttons
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
return others;
|
|
183
|
+
}
|
|
184
|
+
function isElementVisible(el) {
|
|
185
|
+
const style = window.getComputedStyle(el);
|
|
186
|
+
return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
|
|
187
|
+
}
|
|
188
|
+
function arraysAreEqual(a, b) {
|
|
189
|
+
if (a.length !== b.length) return false;
|
|
190
|
+
const setA = new Set(a);
|
|
191
|
+
const setB = new Set(b);
|
|
192
|
+
if (setA.size !== setB.size) return false;
|
|
193
|
+
for (const val of setA) {
|
|
194
|
+
if (!setB.has(val)) return false;
|
|
195
|
+
}
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
function useGetRowIds(tableRef) {
|
|
199
|
+
const [rowIds, setRowIds] = (0, import_react4.useState)([]);
|
|
200
|
+
const lastRowIdsRef = (0, import_react4.useRef)([]);
|
|
201
|
+
const updateVisibleRowIds = (0, import_react4.useCallback)(() => {
|
|
202
|
+
const table = tableRef?.current;
|
|
203
|
+
if (!table) return;
|
|
204
|
+
const rows = table.querySelectorAll("tr[data-row-id]");
|
|
205
|
+
const ids = [];
|
|
206
|
+
rows.forEach((row) => {
|
|
207
|
+
const el = row;
|
|
208
|
+
if (isElementVisible(el)) {
|
|
209
|
+
const id = el.getAttribute("data-row-id");
|
|
210
|
+
if (id) ids.push(id);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const uniqueIds = Array.from(new Set(ids));
|
|
214
|
+
if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
|
|
215
|
+
lastRowIdsRef.current = uniqueIds;
|
|
216
|
+
setRowIds(uniqueIds);
|
|
217
|
+
}
|
|
218
|
+
}, [tableRef]);
|
|
219
|
+
(0, import_react4.useEffect)(() => {
|
|
220
|
+
const table = tableRef?.current;
|
|
221
|
+
if (!table) return;
|
|
222
|
+
const observer = new MutationObserver(() => {
|
|
223
|
+
updateVisibleRowIds();
|
|
224
|
+
});
|
|
225
|
+
observer.observe(table, {
|
|
226
|
+
childList: true,
|
|
227
|
+
subtree: true,
|
|
228
|
+
attributes: true,
|
|
229
|
+
attributeFilter: ["style", "class"]
|
|
230
|
+
});
|
|
231
|
+
updateVisibleRowIds();
|
|
232
|
+
return () => {
|
|
233
|
+
observer.disconnect();
|
|
234
|
+
};
|
|
235
|
+
}, [updateVisibleRowIds, tableRef]);
|
|
236
|
+
return { rowIds, refresh: updateVisibleRowIds };
|
|
237
|
+
}
|
|
238
|
+
var useSelectionState = ({
|
|
239
|
+
typeTable,
|
|
240
|
+
tableRef,
|
|
241
|
+
rows
|
|
242
|
+
}) => {
|
|
243
|
+
const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
|
|
244
|
+
const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
|
|
245
|
+
const { rowIds: recordIds } = useGetRowIds(tableRef);
|
|
246
|
+
const selectedRowKeysRef = (0, import_react4.useRef)(recordIds);
|
|
247
|
+
const isGroupTable = typeTable === "group";
|
|
248
|
+
const recordsCheckedGroup = (0, import_react4.useMemo)(() => {
|
|
249
|
+
if (!rows || !groupByDomain) return 0;
|
|
250
|
+
const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
|
|
251
|
+
return countSum(rows, groupBy);
|
|
252
|
+
}, [rows, groupByDomain]);
|
|
253
|
+
const isAllGroupChecked = (0, import_react4.useMemo)(() => {
|
|
254
|
+
if (!isGroupTable || !selectedRowKeys?.length) return false;
|
|
255
|
+
const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
|
|
256
|
+
const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
|
|
257
|
+
const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
|
|
258
|
+
return allGroupsSelected || allRecordsSelected;
|
|
259
|
+
}, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
|
|
260
|
+
const isAllNormalChecked = (0, import_react4.useMemo)(() => {
|
|
261
|
+
if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
|
|
262
|
+
return selectedRowKeys.length === rows.length && selectedRowKeys.every(
|
|
263
|
+
(id) => rows.some((record) => record.id === id)
|
|
264
|
+
);
|
|
265
|
+
}, [isGroupTable, selectedRowKeys, rows]);
|
|
266
|
+
const checkedAll = isAllGroupChecked || isAllNormalChecked;
|
|
267
|
+
return { checkedAll, selectedRowKeysRef };
|
|
268
|
+
};
|
|
165
269
|
var getDateRange = (currentDate, unit) => {
|
|
166
270
|
const date = new Date(currentDate);
|
|
167
271
|
let dateStart, dateEnd;
|
|
@@ -259,6 +363,10 @@ function combineContexts(contexts) {
|
|
|
259
363
|
return res;
|
|
260
364
|
}
|
|
261
365
|
}
|
|
366
|
+
var STORAGES = {
|
|
367
|
+
TOKEN: "accessToken",
|
|
368
|
+
USER_INFO: "USER_INFO"
|
|
369
|
+
};
|
|
262
370
|
function useAsyncState(initialValue = [true, null]) {
|
|
263
371
|
return (0, import_react4.useReducer)(
|
|
264
372
|
(_state, action = null) => [false, action],
|
|
@@ -379,6 +487,9 @@ var languages = [
|
|
|
379
487
|
{ id: "vi_VN", name: "VIE" },
|
|
380
488
|
{ id: "en_US", name: "ENG" }
|
|
381
489
|
];
|
|
490
|
+
var API_PRESCHOOL_URL = {
|
|
491
|
+
baseURL: "https://preschool.vitrust.app"
|
|
492
|
+
};
|
|
382
493
|
var API_APP_URL = {
|
|
383
494
|
baseUrl: "https://api.vitrust.app",
|
|
384
495
|
c2: "https://api.vitrust.app/c2",
|
|
@@ -681,8 +792,69 @@ var useAppProvider = () => {
|
|
|
681
792
|
return context;
|
|
682
793
|
};
|
|
683
794
|
|
|
684
|
-
// src/hooks/
|
|
795
|
+
// src/hooks/core/use-menu-item.tsx
|
|
796
|
+
var import_environment5 = require("@fctc/interface-logic/environment");
|
|
797
|
+
var import_hooks9 = require("@fctc/interface-logic/hooks");
|
|
685
798
|
var import_react11 = require("react");
|
|
799
|
+
|
|
800
|
+
// src/utils.ts
|
|
801
|
+
var utils_exports = {};
|
|
802
|
+
__export(utils_exports, {
|
|
803
|
+
API_APP_URL: () => API_APP_URL,
|
|
804
|
+
API_PRESCHOOL_URL: () => API_PRESCHOOL_URL,
|
|
805
|
+
STORAGES: () => STORAGES,
|
|
806
|
+
combineContexts: () => combineContexts,
|
|
807
|
+
convertFieldsToArray: () => convertFieldsToArray,
|
|
808
|
+
countSum: () => countSum,
|
|
809
|
+
getDateRange: () => getDateRange,
|
|
810
|
+
languages: () => languages,
|
|
811
|
+
mergeButtons: () => mergeButtons,
|
|
812
|
+
setStorageItemAsync: () => setStorageItemAsync,
|
|
813
|
+
useGetRowIds: () => useGetRowIds,
|
|
814
|
+
useSelectionState: () => useSelectionState,
|
|
815
|
+
useStorageState: () => useStorageState
|
|
816
|
+
});
|
|
817
|
+
__reExport(utils_exports, require("@fctc/interface-logic/utils"));
|
|
818
|
+
|
|
819
|
+
// src/hooks/core/use-menu-item.tsx
|
|
820
|
+
var useMenuItem = (props) => {
|
|
821
|
+
const { menu, activeMenuId } = props;
|
|
822
|
+
const model = menu?.action?.res_model;
|
|
823
|
+
const aid = menu?.action?.id?.id;
|
|
824
|
+
const id = menu?.id;
|
|
825
|
+
const context = (0, import_environment5.getEnv)().context;
|
|
826
|
+
const queryActionDetail = (0, import_hooks9.useGetActionDetail)({
|
|
827
|
+
aid,
|
|
828
|
+
id,
|
|
829
|
+
model,
|
|
830
|
+
context,
|
|
831
|
+
enabled: true,
|
|
832
|
+
queryKey: [`action-${aid}`]
|
|
833
|
+
}).data;
|
|
834
|
+
const [path, setPath] = (0, import_react11.useState)("");
|
|
835
|
+
const handleClick = () => {
|
|
836
|
+
if (location?.pathname === "/list/menu" && activeMenuId === menu?.id) {
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
const hasListView = queryActionDetail.views.some(
|
|
840
|
+
([id2, type]) => type === "list"
|
|
841
|
+
);
|
|
842
|
+
const viewType = hasListView ? "list" : "form";
|
|
843
|
+
const isAccountPayment = menu?.action?.res_model === "account.payment" && menu?.action?.id?.id === 1551;
|
|
844
|
+
const isConvertCurrencyMenu = menu?.action?.res_model === "currency.convert" && menu?.action?.id?.id === 1562;
|
|
845
|
+
const path2 = (0, utils_exports.formatUrlPath)({
|
|
846
|
+
viewType,
|
|
847
|
+
actionPath: isConvertCurrencyMenu ? "menu" : isAccountPayment ? "menu" : menu?.action?.path || "menu",
|
|
848
|
+
aid: menu?.action?.id?.id,
|
|
849
|
+
model: queryActionDetail.res_model
|
|
850
|
+
});
|
|
851
|
+
setPath(path2);
|
|
852
|
+
};
|
|
853
|
+
return { handleClick, path, queryActionDetail };
|
|
854
|
+
};
|
|
855
|
+
|
|
856
|
+
// src/hooks/utils/use-click-outside.ts
|
|
857
|
+
var import_react12 = require("react");
|
|
686
858
|
var DEFAULT_EVENTS = ["mousedown", "touchstart"];
|
|
687
859
|
var useClickOutside = ({
|
|
688
860
|
handler,
|
|
@@ -690,8 +862,8 @@ var useClickOutside = ({
|
|
|
690
862
|
nodes = [],
|
|
691
863
|
refs
|
|
692
864
|
}) => {
|
|
693
|
-
const ref = (0,
|
|
694
|
-
(0,
|
|
865
|
+
const ref = (0, import_react12.useRef)(null);
|
|
866
|
+
(0, import_react12.useEffect)(() => {
|
|
695
867
|
const listener = (event) => {
|
|
696
868
|
const { target } = event;
|
|
697
869
|
if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
|
|
@@ -713,10 +885,10 @@ var useClickOutside = ({
|
|
|
713
885
|
};
|
|
714
886
|
|
|
715
887
|
// src/hooks/utils/use-debounce.ts
|
|
716
|
-
var
|
|
888
|
+
var import_react13 = require("react");
|
|
717
889
|
function useDebounce(value, delay) {
|
|
718
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
719
|
-
(0,
|
|
890
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react13.useState)(value);
|
|
891
|
+
(0, import_react13.useEffect)(() => {
|
|
720
892
|
const handler = setTimeout(() => {
|
|
721
893
|
setDebouncedValue(value);
|
|
722
894
|
}, delay);
|
|
@@ -741,6 +913,7 @@ __reExport(hooks_exports, require("@fctc/interface-logic/hooks"), module.exports
|
|
|
741
913
|
useDetail,
|
|
742
914
|
useListData,
|
|
743
915
|
useMenu,
|
|
916
|
+
useMenuItem,
|
|
744
917
|
useProfile,
|
|
745
918
|
useUser,
|
|
746
919
|
useViewV2,
|
package/dist/hooks.mjs
CHANGED
|
@@ -2,6 +2,10 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
5
9
|
var __copyProps = (to, from, except, desc) => {
|
|
6
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
11
|
for (let key of __getOwnPropNames(from))
|
|
@@ -145,6 +149,109 @@ __reExport(store_exports, store_star);
|
|
|
145
149
|
import * as store_star from "@fctc/interface-logic/store";
|
|
146
150
|
|
|
147
151
|
// src/utils/function.ts
|
|
152
|
+
var countSum = (data, field) => {
|
|
153
|
+
if (!data || !field) return 0;
|
|
154
|
+
return data.reduce(
|
|
155
|
+
(total, item) => total + (item?.[`${field}_count`] || 0),
|
|
156
|
+
0
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
function mergeButtons(fields) {
|
|
160
|
+
const buttons = fields?.filter((f) => f.type_co === "button");
|
|
161
|
+
const others = fields?.filter((f) => f.type_co !== "button");
|
|
162
|
+
if (buttons?.length) {
|
|
163
|
+
others.push({
|
|
164
|
+
type_co: "buttons",
|
|
165
|
+
buttons
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return others;
|
|
169
|
+
}
|
|
170
|
+
function isElementVisible(el) {
|
|
171
|
+
const style = window.getComputedStyle(el);
|
|
172
|
+
return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
|
|
173
|
+
}
|
|
174
|
+
function arraysAreEqual(a, b) {
|
|
175
|
+
if (a.length !== b.length) return false;
|
|
176
|
+
const setA = new Set(a);
|
|
177
|
+
const setB = new Set(b);
|
|
178
|
+
if (setA.size !== setB.size) return false;
|
|
179
|
+
for (const val of setA) {
|
|
180
|
+
if (!setB.has(val)) return false;
|
|
181
|
+
}
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
function useGetRowIds(tableRef) {
|
|
185
|
+
const [rowIds, setRowIds] = useState2([]);
|
|
186
|
+
const lastRowIdsRef = useRef([]);
|
|
187
|
+
const updateVisibleRowIds = useCallback(() => {
|
|
188
|
+
const table = tableRef?.current;
|
|
189
|
+
if (!table) return;
|
|
190
|
+
const rows = table.querySelectorAll("tr[data-row-id]");
|
|
191
|
+
const ids = [];
|
|
192
|
+
rows.forEach((row) => {
|
|
193
|
+
const el = row;
|
|
194
|
+
if (isElementVisible(el)) {
|
|
195
|
+
const id = el.getAttribute("data-row-id");
|
|
196
|
+
if (id) ids.push(id);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const uniqueIds = Array.from(new Set(ids));
|
|
200
|
+
if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
|
|
201
|
+
lastRowIdsRef.current = uniqueIds;
|
|
202
|
+
setRowIds(uniqueIds);
|
|
203
|
+
}
|
|
204
|
+
}, [tableRef]);
|
|
205
|
+
useEffect3(() => {
|
|
206
|
+
const table = tableRef?.current;
|
|
207
|
+
if (!table) return;
|
|
208
|
+
const observer = new MutationObserver(() => {
|
|
209
|
+
updateVisibleRowIds();
|
|
210
|
+
});
|
|
211
|
+
observer.observe(table, {
|
|
212
|
+
childList: true,
|
|
213
|
+
subtree: true,
|
|
214
|
+
attributes: true,
|
|
215
|
+
attributeFilter: ["style", "class"]
|
|
216
|
+
});
|
|
217
|
+
updateVisibleRowIds();
|
|
218
|
+
return () => {
|
|
219
|
+
observer.disconnect();
|
|
220
|
+
};
|
|
221
|
+
}, [updateVisibleRowIds, tableRef]);
|
|
222
|
+
return { rowIds, refresh: updateVisibleRowIds };
|
|
223
|
+
}
|
|
224
|
+
var useSelectionState = ({
|
|
225
|
+
typeTable,
|
|
226
|
+
tableRef,
|
|
227
|
+
rows
|
|
228
|
+
}) => {
|
|
229
|
+
const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
|
|
230
|
+
const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
|
|
231
|
+
const { rowIds: recordIds } = useGetRowIds(tableRef);
|
|
232
|
+
const selectedRowKeysRef = useRef(recordIds);
|
|
233
|
+
const isGroupTable = typeTable === "group";
|
|
234
|
+
const recordsCheckedGroup = useMemo2(() => {
|
|
235
|
+
if (!rows || !groupByDomain) return 0;
|
|
236
|
+
const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
|
|
237
|
+
return countSum(rows, groupBy);
|
|
238
|
+
}, [rows, groupByDomain]);
|
|
239
|
+
const isAllGroupChecked = useMemo2(() => {
|
|
240
|
+
if (!isGroupTable || !selectedRowKeys?.length) return false;
|
|
241
|
+
const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
|
|
242
|
+
const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
|
|
243
|
+
const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
|
|
244
|
+
return allGroupsSelected || allRecordsSelected;
|
|
245
|
+
}, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
|
|
246
|
+
const isAllNormalChecked = useMemo2(() => {
|
|
247
|
+
if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
|
|
248
|
+
return selectedRowKeys.length === rows.length && selectedRowKeys.every(
|
|
249
|
+
(id) => rows.some((record) => record.id === id)
|
|
250
|
+
);
|
|
251
|
+
}, [isGroupTable, selectedRowKeys, rows]);
|
|
252
|
+
const checkedAll = isAllGroupChecked || isAllNormalChecked;
|
|
253
|
+
return { checkedAll, selectedRowKeysRef };
|
|
254
|
+
};
|
|
148
255
|
var getDateRange = (currentDate, unit) => {
|
|
149
256
|
const date = new Date(currentDate);
|
|
150
257
|
let dateStart, dateEnd;
|
|
@@ -242,6 +349,10 @@ function combineContexts(contexts) {
|
|
|
242
349
|
return res;
|
|
243
350
|
}
|
|
244
351
|
}
|
|
352
|
+
var STORAGES = {
|
|
353
|
+
TOKEN: "accessToken",
|
|
354
|
+
USER_INFO: "USER_INFO"
|
|
355
|
+
};
|
|
245
356
|
function useAsyncState(initialValue = [true, null]) {
|
|
246
357
|
return useReducer(
|
|
247
358
|
(_state, action = null) => [false, action],
|
|
@@ -369,6 +480,9 @@ var languages = [
|
|
|
369
480
|
{ id: "vi_VN", name: "VIE" },
|
|
370
481
|
{ id: "en_US", name: "ENG" }
|
|
371
482
|
];
|
|
483
|
+
var API_PRESCHOOL_URL = {
|
|
484
|
+
baseURL: "https://preschool.vitrust.app"
|
|
485
|
+
};
|
|
372
486
|
var API_APP_URL = {
|
|
373
487
|
baseUrl: "https://api.vitrust.app",
|
|
374
488
|
c2: "https://api.vitrust.app/c2",
|
|
@@ -679,6 +793,68 @@ var useAppProvider = () => {
|
|
|
679
793
|
return context;
|
|
680
794
|
};
|
|
681
795
|
|
|
796
|
+
// src/hooks/core/use-menu-item.tsx
|
|
797
|
+
import { getEnv as getEnv5 } from "@fctc/interface-logic/environment";
|
|
798
|
+
import { useGetActionDetail } from "@fctc/interface-logic/hooks";
|
|
799
|
+
import { useState as useState5 } from "react";
|
|
800
|
+
|
|
801
|
+
// src/utils.ts
|
|
802
|
+
var utils_exports = {};
|
|
803
|
+
__export(utils_exports, {
|
|
804
|
+
API_APP_URL: () => API_APP_URL,
|
|
805
|
+
API_PRESCHOOL_URL: () => API_PRESCHOOL_URL,
|
|
806
|
+
STORAGES: () => STORAGES,
|
|
807
|
+
combineContexts: () => combineContexts,
|
|
808
|
+
convertFieldsToArray: () => convertFieldsToArray,
|
|
809
|
+
countSum: () => countSum,
|
|
810
|
+
getDateRange: () => getDateRange,
|
|
811
|
+
languages: () => languages,
|
|
812
|
+
mergeButtons: () => mergeButtons,
|
|
813
|
+
setStorageItemAsync: () => setStorageItemAsync,
|
|
814
|
+
useGetRowIds: () => useGetRowIds,
|
|
815
|
+
useSelectionState: () => useSelectionState,
|
|
816
|
+
useStorageState: () => useStorageState
|
|
817
|
+
});
|
|
818
|
+
__reExport(utils_exports, utils_star);
|
|
819
|
+
import * as utils_star from "@fctc/interface-logic/utils";
|
|
820
|
+
|
|
821
|
+
// src/hooks/core/use-menu-item.tsx
|
|
822
|
+
var useMenuItem = (props) => {
|
|
823
|
+
const { menu, activeMenuId } = props;
|
|
824
|
+
const model = menu?.action?.res_model;
|
|
825
|
+
const aid = menu?.action?.id?.id;
|
|
826
|
+
const id = menu?.id;
|
|
827
|
+
const context = getEnv5().context;
|
|
828
|
+
const queryActionDetail = useGetActionDetail({
|
|
829
|
+
aid,
|
|
830
|
+
id,
|
|
831
|
+
model,
|
|
832
|
+
context,
|
|
833
|
+
enabled: true,
|
|
834
|
+
queryKey: [`action-${aid}`]
|
|
835
|
+
}).data;
|
|
836
|
+
const [path, setPath] = useState5("");
|
|
837
|
+
const handleClick = () => {
|
|
838
|
+
if (location?.pathname === "/list/menu" && activeMenuId === menu?.id) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
const hasListView = queryActionDetail.views.some(
|
|
842
|
+
([id2, type]) => type === "list"
|
|
843
|
+
);
|
|
844
|
+
const viewType = hasListView ? "list" : "form";
|
|
845
|
+
const isAccountPayment = menu?.action?.res_model === "account.payment" && menu?.action?.id?.id === 1551;
|
|
846
|
+
const isConvertCurrencyMenu = menu?.action?.res_model === "currency.convert" && menu?.action?.id?.id === 1562;
|
|
847
|
+
const path2 = (0, utils_exports.formatUrlPath)({
|
|
848
|
+
viewType,
|
|
849
|
+
actionPath: isConvertCurrencyMenu ? "menu" : isAccountPayment ? "menu" : menu?.action?.path || "menu",
|
|
850
|
+
aid: menu?.action?.id?.id,
|
|
851
|
+
model: queryActionDetail.res_model
|
|
852
|
+
});
|
|
853
|
+
setPath(path2);
|
|
854
|
+
};
|
|
855
|
+
return { handleClick, path, queryActionDetail };
|
|
856
|
+
};
|
|
857
|
+
|
|
682
858
|
// src/hooks/utils/use-click-outside.ts
|
|
683
859
|
import { useEffect as useEffect7, useRef as useRef2 } from "react";
|
|
684
860
|
var DEFAULT_EVENTS = ["mousedown", "touchstart"];
|
|
@@ -711,9 +887,9 @@ var useClickOutside = ({
|
|
|
711
887
|
};
|
|
712
888
|
|
|
713
889
|
// src/hooks/utils/use-debounce.ts
|
|
714
|
-
import { useEffect as useEffect8, useState as
|
|
890
|
+
import { useEffect as useEffect8, useState as useState6 } from "react";
|
|
715
891
|
function useDebounce(value, delay) {
|
|
716
|
-
const [debouncedValue, setDebouncedValue] =
|
|
892
|
+
const [debouncedValue, setDebouncedValue] = useState6(value);
|
|
717
893
|
useEffect8(() => {
|
|
718
894
|
const handler = setTimeout(() => {
|
|
719
895
|
setDebouncedValue(value);
|
|
@@ -738,6 +914,7 @@ export {
|
|
|
738
914
|
useDetail,
|
|
739
915
|
useListData,
|
|
740
916
|
useMenu,
|
|
917
|
+
useMenuItem,
|
|
741
918
|
useProfile,
|
|
742
919
|
useUser,
|
|
743
920
|
useViewV2
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { ActionResultType, AppProvider, ContextProfile, Record, ViewResponse, useAppProvider, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useListData, useListDataType, useMenu, useMenuType, useProfile, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.mjs';
|
|
1
|
+
export { ActionResultType, AppProvider, ContextProfile, Record, ViewResponse, useAppProvider, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useListData, useListDataType, useMenu, useMenuItem, useMenuType, useProfile, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.mjs';
|
|
2
2
|
export * from '@fctc/interface-logic/hooks';
|
|
3
3
|
export * from '@fctc/interface-logic/configs';
|
|
4
4
|
export { CheckIcon, ChevronBottomIcon, CloseIcon, EyeIcon, FilterIcon, GroupByIcon, LoadingIcon, SearchIcon } from './icons.mjs';
|
|
5
|
-
export { ISelctionStateProps,
|
|
5
|
+
export { ISelctionStateProps, ITableHeadProps, ITableProps, binaryFieldController, colorFieldController, copyLinkButtonController, dateFieldController, downLoadBinaryController, downloadFileController, durationController, many2manyFieldController, many2manyTagsController, many2oneButtonController, many2oneFieldController, priorityFieldController, searchController, statusDropdownController, tableController, tableGroupController, tableHeadController } from './widget.mjs';
|
|
6
6
|
export * from '@fctc/interface-logic/types';
|
|
7
7
|
export { IInputFieldProps, ValuePropsType } from './types.mjs';
|
|
8
8
|
export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useSelectionState, useStorageState } from './utils.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { ActionResultType, AppProvider, ContextProfile, Record, ViewResponse, useAppProvider, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useListData, useListDataType, useMenu, useMenuType, useProfile, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.js';
|
|
1
|
+
export { ActionResultType, AppProvider, ContextProfile, Record, ViewResponse, useAppProvider, useAuth, useAuthType, useCallAction, useCallActionType, useClickOutside, useConfig, useConfigType, useDebounce, useDetail, useListData, useListDataType, useMenu, useMenuItem, useMenuType, useProfile, useUser, useUserType, useViewV2, useViewV2Type } from './hooks.js';
|
|
2
2
|
export * from '@fctc/interface-logic/hooks';
|
|
3
3
|
export * from '@fctc/interface-logic/configs';
|
|
4
4
|
export { CheckIcon, ChevronBottomIcon, CloseIcon, EyeIcon, FilterIcon, GroupByIcon, LoadingIcon, SearchIcon } from './icons.js';
|
|
5
|
-
export { ISelctionStateProps,
|
|
5
|
+
export { ISelctionStateProps, ITableHeadProps, ITableProps, binaryFieldController, colorFieldController, copyLinkButtonController, dateFieldController, downLoadBinaryController, downloadFileController, durationController, many2manyFieldController, many2manyTagsController, many2oneButtonController, many2oneFieldController, priorityFieldController, searchController, statusDropdownController, tableController, tableGroupController, tableHeadController } from './widget.js';
|
|
6
6
|
export * from '@fctc/interface-logic/types';
|
|
7
7
|
export { IInputFieldProps, ValuePropsType } from './types.js';
|
|
8
8
|
export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useSelectionState, useStorageState } from './utils.js';
|