@fctc/widget-logic 2.8.3 → 2.8.5

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