@fctc/widget-logic 2.8.7 → 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.d.mts CHANGED
@@ -4,11 +4,9 @@ import * as _tanstack_query_core from '@tanstack/query-core';
4
4
  import * as react from 'react';
5
5
  import react__default, { RefObject } from 'react';
6
6
 
7
- declare const useCallAction: () => readonly [ActionResult | undefined, ({ aid, service, xNode, context, }: {
7
+ declare const useCallAction: () => readonly [ActionResult | undefined, ({ aid, }: {
8
8
  aid: number;
9
- service: string;
10
- xNode?: string;
11
- context?: any;
9
+ actionType?: string;
12
10
  }) => Promise<ActionResult | undefined>];
13
11
  type useCallActionType = ReturnType<typeof useCallAction>;
14
12
  type ActionResultType = useCallActionType[0];
@@ -40,10 +38,9 @@ interface ActionResult {
40
38
  url?: string;
41
39
  }
42
40
 
43
- declare const useMenu: ({ context, specification, domain, }: {
41
+ declare const useMenu: ({ context, specification, }: {
44
42
  context?: any;
45
43
  specification?: any;
46
- domain?: any;
47
44
  }) => UseMenuReturn;
48
45
  type useMenuType = ReturnType<typeof useMenu>;
49
46
  interface RecordMenu {
@@ -74,10 +71,8 @@ interface RecordMenu {
74
71
  interface UseMenuReturn {
75
72
  data: RecordMenu[] | undefined;
76
73
  action: {
77
- handleChangeMenu: ({ menu, service, xNode, }: {
74
+ handleChangeMenu: ({ menu }: {
78
75
  menu?: RecordMenu;
79
- service?: string;
80
- xNode?: string;
81
76
  }) => Promise<any>;
82
77
  };
83
78
  state: {
@@ -89,19 +84,15 @@ interface UseMenuReturn {
89
84
  isError: boolean;
90
85
  error: unknown;
91
86
  refetch: () => void;
92
- service?: string;
93
- xNode?: string;
94
87
  }
95
88
 
96
89
  declare const useUser: () => any;
97
90
  type useUserType = ReturnType<typeof useUser>;
98
91
 
99
- declare const useViewV2: ({ action, context, aid, service, xNode, }: {
92
+ declare const useViewV2: ({ action, context, aid, }: {
100
93
  action: ActionResultType;
101
94
  context: any;
102
95
  aid?: any;
103
- service?: string;
104
- xNode?: string;
105
96
  }) => {
106
97
  context: any;
107
98
  data: ViewResponse;
@@ -550,14 +541,10 @@ type AppProviderType = {
550
541
  menu: useMenuType;
551
542
  view: useViewV2Type;
552
543
  };
553
- declare const AppProvider: ({ children, menuParams, aid, }: {
544
+ declare const AppProvider: ({ children, menuSpecification, aid, }: {
554
545
  children: React.ReactNode;
555
546
  } & {
556
- menuParams: {
557
- specification: any;
558
- domain?: any;
559
- context?: any;
560
- };
547
+ menuSpecification: any;
561
548
  aid?: number;
562
549
  }) => react_jsx_runtime.JSX.Element;
563
550
  declare const useAppProvider: () => AppProviderType;
@@ -777,13 +764,11 @@ declare const useGetSpecification: ({ model, viewData, fields, }: {
777
764
  specification: Record<string, any> | null;
778
765
  };
779
766
 
780
- declare const useListData: ({ action, context, viewData, model, service, xNode, }: {
767
+ declare const useListData: ({ action, context, viewData, model, }: {
781
768
  action: ActionResultType;
782
769
  context: any;
783
770
  viewData?: ViewResponse;
784
771
  model: string;
785
- service?: string;
786
- xNode?: string;
787
772
  }) => {
788
773
  state: {
789
774
  specification: Record<string, any> | null;
package/dist/hooks.d.ts CHANGED
@@ -4,11 +4,9 @@ import * as _tanstack_query_core from '@tanstack/query-core';
4
4
  import * as react from 'react';
5
5
  import react__default, { RefObject } from 'react';
6
6
 
7
- declare const useCallAction: () => readonly [ActionResult | undefined, ({ aid, service, xNode, context, }: {
7
+ declare const useCallAction: () => readonly [ActionResult | undefined, ({ aid, }: {
8
8
  aid: number;
9
- service: string;
10
- xNode?: string;
11
- context?: any;
9
+ actionType?: string;
12
10
  }) => Promise<ActionResult | undefined>];
13
11
  type useCallActionType = ReturnType<typeof useCallAction>;
14
12
  type ActionResultType = useCallActionType[0];
@@ -40,10 +38,9 @@ interface ActionResult {
40
38
  url?: string;
41
39
  }
42
40
 
43
- declare const useMenu: ({ context, specification, domain, }: {
41
+ declare const useMenu: ({ context, specification, }: {
44
42
  context?: any;
45
43
  specification?: any;
46
- domain?: any;
47
44
  }) => UseMenuReturn;
48
45
  type useMenuType = ReturnType<typeof useMenu>;
49
46
  interface RecordMenu {
@@ -74,10 +71,8 @@ interface RecordMenu {
74
71
  interface UseMenuReturn {
75
72
  data: RecordMenu[] | undefined;
76
73
  action: {
77
- handleChangeMenu: ({ menu, service, xNode, }: {
74
+ handleChangeMenu: ({ menu }: {
78
75
  menu?: RecordMenu;
79
- service?: string;
80
- xNode?: string;
81
76
  }) => Promise<any>;
82
77
  };
83
78
  state: {
@@ -89,19 +84,15 @@ interface UseMenuReturn {
89
84
  isError: boolean;
90
85
  error: unknown;
91
86
  refetch: () => void;
92
- service?: string;
93
- xNode?: string;
94
87
  }
95
88
 
96
89
  declare const useUser: () => any;
97
90
  type useUserType = ReturnType<typeof useUser>;
98
91
 
99
- declare const useViewV2: ({ action, context, aid, service, xNode, }: {
92
+ declare const useViewV2: ({ action, context, aid, }: {
100
93
  action: ActionResultType;
101
94
  context: any;
102
95
  aid?: any;
103
- service?: string;
104
- xNode?: string;
105
96
  }) => {
106
97
  context: any;
107
98
  data: ViewResponse;
@@ -550,14 +541,10 @@ type AppProviderType = {
550
541
  menu: useMenuType;
551
542
  view: useViewV2Type;
552
543
  };
553
- declare const AppProvider: ({ children, menuParams, aid, }: {
544
+ declare const AppProvider: ({ children, menuSpecification, aid, }: {
554
545
  children: React.ReactNode;
555
546
  } & {
556
- menuParams: {
557
- specification: any;
558
- domain?: any;
559
- context?: any;
560
- };
547
+ menuSpecification: any;
561
548
  aid?: number;
562
549
  }) => react_jsx_runtime.JSX.Element;
563
550
  declare const useAppProvider: () => AppProviderType;
@@ -777,13 +764,11 @@ declare const useGetSpecification: ({ model, viewData, fields, }: {
777
764
  specification: Record<string, any> | null;
778
765
  };
779
766
 
780
- declare const useListData: ({ action, context, viewData, model, service, xNode, }: {
767
+ declare const useListData: ({ action, context, viewData, model, }: {
781
768
  action: ActionResultType;
782
769
  context: any;
783
770
  viewData?: ViewResponse;
784
771
  model: string;
785
- service?: string;
786
- xNode?: string;
787
772
  }) => {
788
773
  state: {
789
774
  specification: Record<string, any> | null;
package/dist/hooks.js CHANGED
@@ -117,12 +117,51 @@ var import_react8 = require("react");
117
117
  var import_react3 = require("react");
118
118
 
119
119
  // src/hooks/core/use-call-action.ts
120
- var import_react2 = require("react");
120
+ var import_react = require("react");
121
121
 
122
122
  // src/provider.ts
123
123
  var provider_exports = {};
124
124
  __reExport(provider_exports, require("@fctc/interface-logic/provider"));
125
125
 
126
+ // src/hooks/core/use-call-action.ts
127
+ var useCallAction = () => {
128
+ const { env } = (0, provider_exports.useEnv)();
129
+ const { useLoadAction: useLoadAction2, useRunAction: useRunAction2 } = (0, provider_exports.useService)();
130
+ const queryLoadAction = useLoadAction2();
131
+ const queryRunAction = useRunAction2();
132
+ const [actionData, setActionData] = (0, import_react.useState)(
133
+ void 0
134
+ );
135
+ const callAction = (0, import_react.useCallback)(
136
+ async ({
137
+ aid
138
+ }) => {
139
+ try {
140
+ const loadRes = await queryLoadAction.mutateAsync({
141
+ idAction: aid,
142
+ context: env.context
143
+ });
144
+ if (loadRes?.result?.type === "ir.actions.server") {
145
+ const runRes = await queryRunAction.mutateAsync({
146
+ idAction: aid,
147
+ context: env.context
148
+ });
149
+ setActionData(runRes?.result);
150
+ return runRes?.result;
151
+ } else {
152
+ setActionData(loadRes?.result);
153
+ return loadRes?.result;
154
+ }
155
+ } catch (err) {
156
+ console.error("callAction error:", err);
157
+ return void 0;
158
+ }
159
+ },
160
+ [env?.context?.lang]
161
+ );
162
+ return [actionData, callAction];
163
+ };
164
+
126
165
  // src/utils.ts
127
166
  var utils_exports = {};
128
167
  __export(utils_exports, {
@@ -144,7 +183,7 @@ var languages = [
144
183
  ];
145
184
 
146
185
  // src/utils/function.ts
147
- var import_react = require("react");
186
+ var import_react2 = require("react");
148
187
  var countSum = (data, field) => {
149
188
  if (!data || !field) return 0;
150
189
  return data.reduce(
@@ -265,7 +304,7 @@ var STORAGES = {
265
304
  USER_INFO: "USER_INFO"
266
305
  };
267
306
  function useAsyncState(initialValue = [true, null]) {
268
- return (0, import_react.useReducer)(
307
+ return (0, import_react2.useReducer)(
269
308
  (_state, action = null) => [false, action],
270
309
  initialValue
271
310
  );
@@ -283,7 +322,7 @@ async function setStorageItemAsync(key, value) {
283
322
  }
284
323
  function useStorageState(key) {
285
324
  const [state, setState] = useAsyncState();
286
- (0, import_react.useEffect)(() => {
325
+ (0, import_react2.useEffect)(() => {
287
326
  try {
288
327
  const storedValue = localStorage.getItem(key);
289
328
  setState(storedValue);
@@ -291,7 +330,7 @@ function useStorageState(key) {
291
330
  console.error("Local storage is unavailable:", e);
292
331
  }
293
332
  }, [key]);
294
- const setValue = (0, import_react.useCallback)(
333
+ const setValue = (0, import_react2.useCallback)(
295
334
  (value) => {
296
335
  setState(value);
297
336
  setStorageItemAsync(key, value);
@@ -304,74 +343,18 @@ function useStorageState(key) {
304
343
  // src/utils.ts
305
344
  __reExport(utils_exports, require("@fctc/interface-logic/utils"));
306
345
 
307
- // src/hooks/core/use-call-action.ts
308
- var useCallAction = () => {
309
- const { env } = (0, provider_exports.useEnv)();
310
- const { useLoadAction: useLoadAction2, useRunAction: useRunAction2 } = (0, provider_exports.useService)();
311
- const queryLoadAction = useLoadAction2();
312
- const queryRunAction = useRunAction2();
313
- const [actionData, setActionData] = (0, import_react2.useState)(
314
- void 0
315
- );
316
- const callAction = (0, import_react2.useCallback)(
317
- async ({
318
- aid,
319
- service,
320
- xNode,
321
- context
322
- }) => {
323
- try {
324
- const loadRes = await queryLoadAction.mutateAsync({
325
- idAction: aid,
326
- context: {
327
- ...env?.context,
328
- ...context ? (0, utils_exports.evalJSONContext)(context, { ...env?.context }) || {} : {}
329
- },
330
- service,
331
- xNode
332
- });
333
- if (loadRes?.result?.type === "ir.actions.server") {
334
- const runRes = await queryRunAction.mutateAsync({
335
- idAction: aid,
336
- context: {
337
- ...env?.context,
338
- ...context ? (0, utils_exports.evalJSONContext)(context, { ...env?.context }) || {} : {}
339
- },
340
- service,
341
- xNode
342
- });
343
- setActionData(runRes?.result);
344
- return runRes?.result;
345
- } else {
346
- setActionData(loadRes?.result);
347
- return loadRes?.result;
348
- }
349
- } catch (err) {
350
- console.error("callAction error:", err);
351
- return void 0;
352
- }
353
- },
354
- [env?.context?.lang]
355
- );
356
- return [actionData, callAction];
357
- };
358
-
359
346
  // src/hooks/core/use-menu.ts
360
347
  var useMenu = ({
361
348
  context,
362
- specification,
363
- domain
349
+ specification
364
350
  }) => {
365
351
  const { env } = (0, provider_exports.useEnv)();
366
352
  const { useGetMenu: useGetMenu2 } = (0, provider_exports.useService)();
367
353
  const [action, callAction] = useCallAction();
368
- const [service, setService] = (0, import_react3.useState)("");
369
- const [xNode, setXNode] = (0, import_react3.useState)("");
370
354
  const menuData = useGetMenu2(
371
355
  context,
372
356
  specification,
373
- !!context && !(0, utils_exports.isObjectEmpty)(context),
374
- domain
357
+ !!context && !(0, utils_exports.isObjectEmpty)(context)
375
358
  );
376
359
  const [menuId, setMenuId] = (0, import_react3.useState)(void 0);
377
360
  const configedIconData = (0, import_react3.useMemo)(() => {
@@ -389,30 +372,20 @@ var useMenu = ({
389
372
  };
390
373
  });
391
374
  }, [menuData.data, env?.envFile?.VITE_APP_DOMAIN]);
392
- const handleChangeMenu = async ({
393
- menu,
394
- service: service2,
395
- xNode: xNode2
396
- }) => {
375
+ const handleChangeMenu = async ({ menu }) => {
397
376
  const aidMenu = menu?.action?.id?.id;
398
377
  if (menu) {
399
378
  setMenuId(menu.id?.toString() ?? "");
400
379
  }
401
380
  if (aidMenu) {
402
381
  const actionResponse = await callAction({
403
- aid: Number(aidMenu),
404
- service: service2 ?? "",
405
- xNode: xNode2
382
+ aid: Number(aidMenu)
406
383
  });
407
- if (service2 && service2 !== "") setService(service2);
408
- if (xNode2 && xNode2 !== "") setXNode(xNode2);
409
384
  return actionResponse;
410
385
  }
411
386
  };
412
387
  return {
413
388
  ...menuData,
414
- service,
415
- xNode,
416
389
  data: configedIconData,
417
390
  action: { handleChangeMenu },
418
391
  state: { menuId, action },
@@ -504,9 +477,7 @@ var import_react6 = require("react");
504
477
  var useViewV2 = ({
505
478
  action,
506
479
  context,
507
- aid,
508
- service,
509
- xNode
480
+ aid
510
481
  }) => {
511
482
  const { useGetView: useGetView2 } = (0, provider_exports.useService)();
512
483
  const viewParams = (0, import_react6.useMemo)(() => {
@@ -526,9 +497,7 @@ var useViewV2 = ({
526
497
  ]
527
498
  ],
528
499
  context,
529
- id: isNaN(Number(aid)) ? action?.id : aid,
530
- service,
531
- xNode
500
+ id: isNaN(Number(aid)) ? action?.id : aid
532
501
  };
533
502
  }, [action, context, aid]);
534
503
  const view = useGetView2({
@@ -600,7 +569,7 @@ var AppProviderInitialValue = {
600
569
  var ReactContext = (0, import_react8.createContext)(AppProviderInitialValue);
601
570
  var AppProvider = ({
602
571
  children,
603
- menuParams,
572
+ menuSpecification,
604
573
  aid
605
574
  }) => {
606
575
  const { env } = (0, provider_exports.useEnv)();
@@ -610,8 +579,7 @@ var AppProvider = ({
610
579
  return combineContexts([
611
580
  {
612
581
  ...user?.context,
613
- ...!(0, utils_exports.isObjectEmpty)(env?.user) && company?.context?.allowed_company_ids ? { lang: env?.context?.lang } : {},
614
- ...menuParams?.context ?? {}
582
+ ...!(0, utils_exports.isObjectEmpty)(env?.user) && company?.context?.allowed_company_ids ? { lang: env?.context?.lang } : {}
615
583
  },
616
584
  company?.context
617
585
  ]);
@@ -620,8 +588,7 @@ var AppProvider = ({
620
588
  context: {
621
589
  ...menuContext
622
590
  },
623
- specification: menuParams?.specification,
624
- domain: menuParams?.domain
591
+ specification: menuSpecification
625
592
  });
626
593
  const action = (0, import_react8.useMemo)(() => {
627
594
  return menu?.state?.action;
@@ -635,9 +602,7 @@ var AppProvider = ({
635
602
  const view = useViewV2({
636
603
  action,
637
604
  context: viewContext,
638
- aid,
639
- service: menu?.service,
640
- xNode: menu?.xNode
605
+ aid
641
606
  });
642
607
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
643
608
  ReactContext.Provider,
@@ -762,7 +727,7 @@ var useGetSpecification = ({
762
727
 
763
728
  // src/hooks/core/use-list-data.ts
764
729
  var import_react14 = require("react");
765
- var import_utils6 = require("@fctc/interface-logic/utils");
730
+ var import_utils5 = require("@fctc/interface-logic/utils");
766
731
 
767
732
  // src/hooks/utils/use-click-outside.ts
768
733
  var import_react11 = require("react");
@@ -881,9 +846,7 @@ var useListData = ({
881
846
  action,
882
847
  context,
883
848
  viewData,
884
- model,
885
- service,
886
- xNode
849
+ model
887
850
  }) => {
888
851
  const { useGetListData: useGetListData2 } = (0, provider_exports.useService)();
889
852
  const [page, setPage] = (0, import_react14.useState)(0);
@@ -906,12 +869,12 @@ var useListData = ({
906
869
  if (!viewData || !action || !context) {
907
870
  return null;
908
871
  }
909
- const domainParse = type === "calendar" ? getDateRange(currentDate, mode) : action?.domain ? Array.isArray(action?.domain) ? [...action?.domain] : (0, import_utils6.evalJSONDomain)(action?.domain, context) : [];
872
+ const domainParse = type === "calendar" ? getDateRange(currentDate, mode) : action?.domain ? Array.isArray(action?.domain) ? [...action?.domain] : (0, import_utils5.evalJSONDomain)(action?.domain, context) : [];
910
873
  const limit = type === "calendar" ? 2500 : pageLimit;
911
874
  const offset = debouncedPage * pageLimit;
912
875
  const fields = type === "calendar" ? convertFieldsToArray(viewData?.views?.calendar?.fields) || [] : typeof groupByList === "object" ? groupByList?.fields : void 0;
913
876
  const groupby = typeof groupByList === "object" ? [groupByList?.contexts?.[0]?.group_by] : [];
914
- const sort = order ? order : viewData?.views?.list?.default_order ? (0, import_utils6.formatSortingString)(viewData?.views?.list?.default_order) : "";
877
+ const sort = order ? order : viewData?.views?.list?.default_order ? (0, import_utils5.formatSortingString)(viewData?.views?.list?.default_order) : "";
915
878
  return {
916
879
  model: action.res_model,
917
880
  specification,
@@ -922,9 +885,7 @@ var useListData = ({
922
885
  groupby,
923
886
  context,
924
887
  sort,
925
- type,
926
- service,
927
- xNode
888
+ type
928
889
  };
929
890
  }, [
930
891
  action,
@@ -941,9 +902,7 @@ var useListData = ({
941
902
  const list = useGetListData2(
942
903
  listDataProps,
943
904
  [listDataProps],
944
- !!listDataProps && !!specification && !(0, import_utils6.isObjectEmpty)(specification),
945
- service,
946
- xNode
905
+ !!listDataProps && !!specification && !(0, import_utils5.isObjectEmpty)(specification)
947
906
  );
948
907
  return {
949
908
  ...list,