@fctc/widget-logic 2.8.8 → 2.8.9

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,13 +96,52 @@ 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 as useCallback2, useState } from "react";
99
+ import { useCallback, 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
+
106
145
  // src/utils.ts
107
146
  var utils_exports = {};
108
147
  __export(utils_exports, {
@@ -124,7 +163,7 @@ var languages = [
124
163
  ];
125
164
 
126
165
  // src/utils/function.ts
127
- import { useCallback, useEffect, useReducer } from "react";
166
+ import { useCallback as useCallback2, useEffect, useReducer } from "react";
128
167
  var countSum = (data, field) => {
129
168
  if (!data || !field) return 0;
130
169
  return data.reduce(
@@ -271,7 +310,7 @@ function useStorageState(key) {
271
310
  console.error("Local storage is unavailable:", e);
272
311
  }
273
312
  }, [key]);
274
- const setValue = useCallback(
313
+ const setValue = useCallback2(
275
314
  (value) => {
276
315
  setState(value);
277
316
  setStorageItemAsync(key, value);
@@ -285,74 +324,18 @@ function useStorageState(key) {
285
324
  __reExport(utils_exports, utils_star);
286
325
  import * as utils_star from "@fctc/interface-logic/utils";
287
326
 
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
-
340
327
  // src/hooks/core/use-menu.ts
341
328
  var useMenu = ({
342
329
  context,
343
- specification,
344
- domain
330
+ specification
345
331
  }) => {
346
332
  const { env } = (0, provider_exports.useEnv)();
347
333
  const { useGetMenu: useGetMenu2 } = (0, provider_exports.useService)();
348
334
  const [action, callAction] = useCallAction();
349
- const [service, setService] = useState2("");
350
- const [xNode, setXNode] = useState2("");
351
335
  const menuData = useGetMenu2(
352
336
  context,
353
337
  specification,
354
- !!context && !(0, utils_exports.isObjectEmpty)(context),
355
- domain
338
+ !!context && !(0, utils_exports.isObjectEmpty)(context)
356
339
  );
357
340
  const [menuId, setMenuId] = useState2(void 0);
358
341
  const configedIconData = useMemo(() => {
@@ -370,30 +353,20 @@ var useMenu = ({
370
353
  };
371
354
  });
372
355
  }, [menuData.data, env?.envFile?.VITE_APP_DOMAIN]);
373
- const handleChangeMenu = async ({
374
- menu,
375
- service: service2,
376
- xNode: xNode2
377
- }) => {
356
+ const handleChangeMenu = async ({ menu }) => {
378
357
  const aidMenu = menu?.action?.id?.id;
379
358
  if (menu) {
380
359
  setMenuId(menu.id?.toString() ?? "");
381
360
  }
382
361
  if (aidMenu) {
383
362
  const actionResponse = await callAction({
384
- aid: Number(aidMenu),
385
- service: service2 ?? "",
386
- xNode: xNode2
363
+ aid: Number(aidMenu)
387
364
  });
388
- setService(service2 ?? "");
389
- setXNode(xNode2 ?? "");
390
365
  return actionResponse;
391
366
  }
392
367
  };
393
368
  return {
394
369
  ...menuData,
395
- service,
396
- xNode,
397
370
  data: configedIconData,
398
371
  action: { handleChangeMenu },
399
372
  state: { menuId, action },
@@ -485,9 +458,7 @@ import { useMemo as useMemo3 } from "react";
485
458
  var useViewV2 = ({
486
459
  action,
487
460
  context,
488
- aid,
489
- service,
490
- xNode
461
+ aid
491
462
  }) => {
492
463
  const { useGetView: useGetView2 } = (0, provider_exports.useService)();
493
464
  const viewParams = useMemo3(() => {
@@ -507,9 +478,7 @@ var useViewV2 = ({
507
478
  ]
508
479
  ],
509
480
  context,
510
- id: isNaN(Number(aid)) ? action?.id : aid,
511
- service,
512
- xNode
481
+ id: isNaN(Number(aid)) ? action?.id : aid
513
482
  };
514
483
  }, [action, context, aid]);
515
484
  const view = useGetView2({
@@ -581,7 +550,7 @@ var AppProviderInitialValue = {
581
550
  var ReactContext = createContext(AppProviderInitialValue);
582
551
  var AppProvider = ({
583
552
  children,
584
- menuParams,
553
+ menuSpecification,
585
554
  aid
586
555
  }) => {
587
556
  const { env } = (0, provider_exports.useEnv)();
@@ -591,8 +560,7 @@ var AppProvider = ({
591
560
  return combineContexts([
592
561
  {
593
562
  ...user?.context,
594
- ...!(0, utils_exports.isObjectEmpty)(env?.user) && company?.context?.allowed_company_ids ? { lang: env?.context?.lang } : {},
595
- ...menuParams?.context ?? {}
563
+ ...!(0, utils_exports.isObjectEmpty)(env?.user) && company?.context?.allowed_company_ids ? { lang: env?.context?.lang } : {}
596
564
  },
597
565
  company?.context
598
566
  ]);
@@ -601,8 +569,7 @@ var AppProvider = ({
601
569
  context: {
602
570
  ...menuContext
603
571
  },
604
- specification: menuParams?.specification,
605
- domain: menuParams?.domain
572
+ specification: menuSpecification
606
573
  });
607
574
  const action = useMemo5(() => {
608
575
  return menu?.state?.action;
@@ -616,9 +583,7 @@ var AppProvider = ({
616
583
  const view = useViewV2({
617
584
  action,
618
585
  context: viewContext,
619
- aid,
620
- service: menu?.service,
621
- xNode: menu?.xNode
586
+ aid
622
587
  });
623
588
  return /* @__PURE__ */ jsx(
624
589
  ReactContext.Provider,
@@ -866,9 +831,7 @@ var useListData = ({
866
831
  action,
867
832
  context,
868
833
  viewData,
869
- model,
870
- service,
871
- xNode
834
+ model
872
835
  }) => {
873
836
  const { useGetListData: useGetListData2 } = (0, provider_exports.useService)();
874
837
  const [page, setPage] = useState5(0);
@@ -924,9 +887,7 @@ var useListData = ({
924
887
  const list = useGetListData2(
925
888
  listDataProps,
926
889
  [listDataProps],
927
- !!listDataProps && !!specification && !isObjectEmpty4(specification),
928
- service,
929
- xNode
890
+ !!listDataProps && !!specification && !isObjectEmpty4(specification)
930
891
  );
931
892
  return {
932
893
  ...list,