@fctc/widget-logic 2.8.2 → 2.8.4

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.mjs CHANGED
@@ -96,52 +96,13 @@ import { createContext, useContext, useMemo as useMemo5 } from "react";
96
96
  import { useMemo, useState as useState2 } from "react";
97
97
 
98
98
  // src/hooks/core/use-call-action.ts
99
- import { useCallback, useState } from "react";
99
+ import { useCallback as useCallback2, useState } from "react";
100
100
 
101
101
  // src/provider.ts
102
102
  var provider_exports = {};
103
103
  __reExport(provider_exports, provider_star);
104
104
  import * as provider_star from "@fctc/interface-logic/provider";
105
105
 
106
- // src/hooks/core/use-call-action.ts
107
- var useCallAction = () => {
108
- const { env } = (0, provider_exports.useEnv)();
109
- const { useLoadAction: useLoadAction2, useRunAction: useRunAction2 } = (0, provider_exports.useService)();
110
- const queryLoadAction = useLoadAction2();
111
- const queryRunAction = useRunAction2();
112
- const [actionData, setActionData] = useState(
113
- void 0
114
- );
115
- const callAction = useCallback(
116
- async ({
117
- aid
118
- }) => {
119
- try {
120
- const loadRes = await queryLoadAction.mutateAsync({
121
- idAction: aid,
122
- context: env.context
123
- });
124
- if (loadRes?.result?.type === "ir.actions.server") {
125
- const runRes = await queryRunAction.mutateAsync({
126
- idAction: aid,
127
- context: env.context
128
- });
129
- setActionData(runRes?.result);
130
- return runRes?.result;
131
- } else {
132
- setActionData(loadRes?.result);
133
- return loadRes?.result;
134
- }
135
- } catch (err) {
136
- console.error("callAction error:", err);
137
- return void 0;
138
- }
139
- },
140
- [env?.context?.lang]
141
- );
142
- return [actionData, callAction];
143
- };
144
-
145
106
  // src/utils.ts
146
107
  var utils_exports = {};
147
108
  __export(utils_exports, {
@@ -163,7 +124,7 @@ var languages = [
163
124
  ];
164
125
 
165
126
  // src/utils/function.ts
166
- import { useCallback as useCallback2, useEffect, useReducer } from "react";
127
+ import { useCallback, useEffect, useReducer } from "react";
167
128
  var countSum = (data, field) => {
168
129
  if (!data || !field) return 0;
169
130
  return data.reduce(
@@ -310,7 +271,7 @@ function useStorageState(key) {
310
271
  console.error("Local storage is unavailable:", e);
311
272
  }
312
273
  }, [key]);
313
- const setValue = useCallback2(
274
+ const setValue = useCallback(
314
275
  (value) => {
315
276
  setState(value);
316
277
  setStorageItemAsync(key, value);
@@ -324,18 +285,74 @@ function useStorageState(key) {
324
285
  __reExport(utils_exports, utils_star);
325
286
  import * as utils_star from "@fctc/interface-logic/utils";
326
287
 
288
+ // src/hooks/core/use-call-action.ts
289
+ var useCallAction = () => {
290
+ const { env } = (0, provider_exports.useEnv)();
291
+ const { useLoadAction: useLoadAction2, useRunAction: useRunAction2 } = (0, provider_exports.useService)();
292
+ const queryLoadAction = useLoadAction2();
293
+ const queryRunAction = useRunAction2();
294
+ const [actionData, setActionData] = useState(
295
+ void 0
296
+ );
297
+ const callAction = useCallback2(
298
+ async ({
299
+ aid,
300
+ service,
301
+ xNode,
302
+ context
303
+ }) => {
304
+ try {
305
+ const loadRes = await queryLoadAction.mutateAsync({
306
+ idAction: aid,
307
+ context: {
308
+ ...env?.context,
309
+ ...context ? (0, utils_exports.evalJSONContext)(context, { ...env?.context }) || {} : {}
310
+ },
311
+ service,
312
+ xNode
313
+ });
314
+ if (loadRes?.result?.type === "ir.actions.server") {
315
+ const runRes = await queryRunAction.mutateAsync({
316
+ idAction: aid,
317
+ context: {
318
+ ...env?.context,
319
+ ...context ? (0, utils_exports.evalJSONContext)(context, { ...env?.context }) || {} : {}
320
+ },
321
+ service,
322
+ xNode
323
+ });
324
+ setActionData(runRes?.result);
325
+ return runRes?.result;
326
+ } else {
327
+ setActionData(loadRes?.result);
328
+ return loadRes?.result;
329
+ }
330
+ } catch (err) {
331
+ console.error("callAction error:", err);
332
+ return void 0;
333
+ }
334
+ },
335
+ [env?.context?.lang]
336
+ );
337
+ return [actionData, callAction];
338
+ };
339
+
327
340
  // src/hooks/core/use-menu.ts
328
341
  var useMenu = ({
329
342
  context,
330
- specification
343
+ specification,
344
+ domain
331
345
  }) => {
332
346
  const { env } = (0, provider_exports.useEnv)();
333
347
  const { useGetMenu: useGetMenu2 } = (0, provider_exports.useService)();
334
348
  const [action, callAction] = useCallAction();
349
+ const [service, setService] = useState2("");
350
+ const [xNode, setXNode] = useState2("");
335
351
  const menuData = useGetMenu2(
336
352
  context,
337
353
  specification,
338
- !!context && !(0, utils_exports.isObjectEmpty)(context)
354
+ !!context && !(0, utils_exports.isObjectEmpty)(context),
355
+ domain
339
356
  );
340
357
  const [menuId, setMenuId] = useState2(void 0);
341
358
  const configedIconData = useMemo(() => {
@@ -353,20 +370,30 @@ var useMenu = ({
353
370
  };
354
371
  });
355
372
  }, [menuData.data, env?.envFile?.VITE_APP_DOMAIN]);
356
- const handleChangeMenu = async ({ menu }) => {
373
+ const handleChangeMenu = async ({
374
+ menu,
375
+ service: service2,
376
+ xNode: xNode2
377
+ }) => {
357
378
  const aidMenu = menu?.action?.id?.id;
358
379
  if (menu) {
359
380
  setMenuId(menu.id?.toString() ?? "");
360
381
  }
361
382
  if (aidMenu) {
362
383
  const actionResponse = await callAction({
363
- aid: Number(aidMenu)
384
+ aid: Number(aidMenu),
385
+ service: service2 ?? "",
386
+ xNode: xNode2
364
387
  });
388
+ if (service2 && service2 !== "") setService(service2);
389
+ if (xNode2 && xNode2 !== "") setXNode(xNode2);
365
390
  return actionResponse;
366
391
  }
367
392
  };
368
393
  return {
369
394
  ...menuData,
395
+ service,
396
+ xNode,
370
397
  data: configedIconData,
371
398
  action: { handleChangeMenu },
372
399
  state: { menuId, action },
@@ -458,7 +485,9 @@ import { useMemo as useMemo3 } from "react";
458
485
  var useViewV2 = ({
459
486
  action,
460
487
  context,
461
- aid
488
+ aid,
489
+ service,
490
+ xNode
462
491
  }) => {
463
492
  const { useGetView: useGetView2 } = (0, provider_exports.useService)();
464
493
  const viewParams = useMemo3(() => {
@@ -478,7 +507,9 @@ var useViewV2 = ({
478
507
  ]
479
508
  ],
480
509
  context,
481
- id: isNaN(Number(aid)) ? action?.id : aid
510
+ id: isNaN(Number(aid)) ? action?.id : aid,
511
+ service,
512
+ xNode
482
513
  };
483
514
  }, [action, context, aid]);
484
515
  const view = useGetView2({
@@ -550,7 +581,7 @@ var AppProviderInitialValue = {
550
581
  var ReactContext = createContext(AppProviderInitialValue);
551
582
  var AppProvider = ({
552
583
  children,
553
- menuSpecification,
584
+ menuParams,
554
585
  aid
555
586
  }) => {
556
587
  const { env } = (0, provider_exports.useEnv)();
@@ -560,7 +591,8 @@ var AppProvider = ({
560
591
  return combineContexts([
561
592
  {
562
593
  ...user?.context,
563
- ...!(0, utils_exports.isObjectEmpty)(env?.user) && company?.context?.allowed_company_ids ? { lang: env?.context?.lang } : {}
594
+ ...!(0, utils_exports.isObjectEmpty)(env?.user) && company?.context?.allowed_company_ids ? { lang: env?.context?.lang } : {},
595
+ ...menuParams?.context ?? {}
564
596
  },
565
597
  company?.context
566
598
  ]);
@@ -569,7 +601,8 @@ var AppProvider = ({
569
601
  context: {
570
602
  ...menuContext
571
603
  },
572
- specification: menuSpecification
604
+ specification: menuParams?.specification,
605
+ domain: menuParams?.domain
573
606
  });
574
607
  const action = useMemo5(() => {
575
608
  return menu?.state?.action;
@@ -583,7 +616,9 @@ var AppProvider = ({
583
616
  const view = useViewV2({
584
617
  action,
585
618
  context: viewContext,
586
- aid
619
+ aid,
620
+ service: menu?.service,
621
+ xNode: menu?.xNode
587
622
  });
588
623
  return /* @__PURE__ */ jsx(
589
624
  ReactContext.Provider,
@@ -831,7 +866,9 @@ var useListData = ({
831
866
  action,
832
867
  context,
833
868
  viewData,
834
- model
869
+ model,
870
+ service,
871
+ xNode
835
872
  }) => {
836
873
  const { useGetListData: useGetListData2 } = (0, provider_exports.useService)();
837
874
  const [page, setPage] = useState5(0);
@@ -870,7 +907,9 @@ var useListData = ({
870
907
  groupby,
871
908
  context,
872
909
  sort,
873
- type
910
+ type,
911
+ service,
912
+ xNode
874
913
  };
875
914
  }, [
876
915
  action,
@@ -882,7 +921,9 @@ var useListData = ({
882
921
  debouncedPage,
883
922
  pageLimit,
884
923
  type,
885
- debouncedDomain
924
+ debouncedDomain,
925
+ service,
926
+ xNode
886
927
  ]);
887
928
  const list = useGetListData2(
888
929
  listDataProps,