@fctc/widget-logic 2.5.1 → 2.5.3

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/widget.js CHANGED
@@ -4320,34 +4320,6 @@ __reExport(utils_exports, require("@fctc/interface-logic/utils"));
4320
4320
 
4321
4321
  // src/hooks/core/use-view-v2.ts
4322
4322
  var import_react7 = require("react");
4323
- var useViewV2 = ({
4324
- action,
4325
- context,
4326
- aid,
4327
- views,
4328
- model
4329
- }) => {
4330
- const { useGetView: useGetView2 } = (0, provider_exports.useService)();
4331
- const viewParams = (0, import_react7.useMemo)(() => {
4332
- if (!action) {
4333
- return void 0;
4334
- }
4335
- return {
4336
- model,
4337
- views,
4338
- context,
4339
- id: isNaN(Number(aid)) ? action?.id : aid
4340
- };
4341
- }, [action, context, aid]);
4342
- const view = useGetView2(
4343
- viewParams || {},
4344
- !!viewParams
4345
- );
4346
- return {
4347
- ...view,
4348
- context
4349
- };
4350
- };
4351
4323
 
4352
4324
  // src/hooks/core/use-company.ts
4353
4325
  var import_react_query3 = require("@tanstack/react-query");
@@ -4363,47 +4335,12 @@ var AppProviderInitialValue = {
4363
4335
  view: {}
4364
4336
  };
4365
4337
  var ReactContext = (0, import_react9.createContext)(AppProviderInitialValue);
4366
- var useAppProvider = () => {
4367
- const context = (0, import_react9.useContext)(ReactContext);
4368
- if (!context) {
4369
- return AppProviderInitialValue;
4370
- }
4371
- return context;
4372
- };
4373
4338
 
4374
4339
  // src/hooks/core/use-config.ts
4375
4340
  var import_react10 = require("react");
4376
4341
 
4377
4342
  // src/hooks/core/use-get-specification.ts
4378
4343
  var import_react11 = require("react");
4379
- var useGetSpecification = ({
4380
- model,
4381
- viewData,
4382
- fields
4383
- }) => {
4384
- const baseModel = (0, import_react11.useMemo)(
4385
- () => ({
4386
- name: String(model),
4387
- view: viewData || {},
4388
- fields
4389
- }),
4390
- [model, viewData]
4391
- );
4392
- const initModel = (0, import_hooks3.useModel)();
4393
- const modelInstance = (0, import_react11.useMemo)(() => {
4394
- if (viewData) {
4395
- return initModel.initModel(baseModel);
4396
- }
4397
- return null;
4398
- }, [baseModel, viewData]);
4399
- const specification = (0, import_react11.useMemo)(() => {
4400
- if (modelInstance) {
4401
- return modelInstance.getSpecification();
4402
- }
4403
- return null;
4404
- }, [modelInstance]);
4405
- return { specification };
4406
- };
4407
4344
 
4408
4345
  // src/hooks/core/use-list-data.ts
4409
4346
  var import_react15 = require("react");
@@ -4493,95 +4430,6 @@ var useGetRowIds = (tableRef) => {
4493
4430
  return { rowIds, refresh: updateVisibleRowIds };
4494
4431
  };
4495
4432
 
4496
- // src/hooks/core/use-list-data.ts
4497
- var useListData = ({
4498
- action,
4499
- context,
4500
- viewData,
4501
- model
4502
- }) => {
4503
- const { useGetListData: useGetListData2 } = (0, provider_exports.useService)();
4504
- const [page, setPage] = (0, import_react15.useState)(0);
4505
- const [pageLimit, setPageLimit] = (0, import_react15.useState)(10);
4506
- const [groupByList, setGroupByList] = (0, import_react15.useState)(null);
4507
- const [domain, setDomain] = (0, import_react15.useState)(null);
4508
- const [order, setOrder] = (0, import_react15.useState)("");
4509
- const [mode, setMode] = (0, import_react15.useState)("month");
4510
- const [type, setType] = (0, import_react15.useState)("list");
4511
- const [currentDate, setCurrentDate] = (0, import_react15.useState)(/* @__PURE__ */ new Date());
4512
- const [selectedRowKeys, setSelectedRowKeys2] = (0, import_react15.useState)([]);
4513
- const [debouncedPage] = useDebounce(page, 500);
4514
- const [debouncedDomain] = useDebounce(domain, 500);
4515
- const { specification } = useGetSpecification({
4516
- model,
4517
- viewData,
4518
- fields: viewData?.views?.list?.fields
4519
- });
4520
- const listDataProps = (0, import_react15.useMemo)(() => {
4521
- if (!viewData || !action || !context) {
4522
- return null;
4523
- }
4524
- const domainParse = type === "calendar" ? getDateRange(currentDate, mode) : action?.domain ? Array.isArray(action?.domain) ? [...action?.domain] : (0, import_utils4.evalJSONDomain)(action?.domain, context) : [];
4525
- const limit = type === "calendar" ? 2500 : pageLimit;
4526
- const offset = debouncedPage * pageLimit;
4527
- const fields = type === "calendar" ? convertFieldsToArray(viewData?.views?.calendar?.fields) || [] : typeof groupByList === "object" ? groupByList?.fields : void 0;
4528
- const groupby = typeof groupByList === "object" ? [groupByList?.contexts?.[0]?.group_by] : [];
4529
- const sort = order ? order : viewData?.views?.list?.default_order ? (0, import_utils4.formatSortingString)(viewData?.views?.list?.default_order) : "";
4530
- return {
4531
- model: action.res_model,
4532
- specification,
4533
- domain: domainParse,
4534
- limit,
4535
- offset,
4536
- fields,
4537
- groupby,
4538
- context,
4539
- sort,
4540
- type
4541
- };
4542
- }, [
4543
- action,
4544
- context,
4545
- currentDate,
4546
- groupByList,
4547
- mode,
4548
- order,
4549
- debouncedPage,
4550
- pageLimit,
4551
- type,
4552
- debouncedDomain
4553
- ]);
4554
- const list = useGetListData2(
4555
- listDataProps,
4556
- [listDataProps],
4557
- !!listDataProps && !!specification && !(0, import_utils4.isObjectEmpty)(specification)
4558
- );
4559
- return {
4560
- ...list,
4561
- state: {
4562
- specification,
4563
- type,
4564
- page,
4565
- mode,
4566
- order,
4567
- domain: listDataProps?.domain,
4568
- pageLimit,
4569
- groupByList,
4570
- currentDate,
4571
- selectedRowKeys,
4572
- setType,
4573
- setMode,
4574
- setPage,
4575
- setOrder,
4576
- setDomain,
4577
- setPageLimit,
4578
- setGroupByList,
4579
- setCurrentDate,
4580
- setSelectedRowKeys: setSelectedRowKeys2
4581
- }
4582
- };
4583
- };
4584
-
4585
4433
  // src/store.ts
4586
4434
  var store_exports = {};
4587
4435
  __reExport(store_exports, require("@fctc/interface-logic/store"));
@@ -4797,24 +4645,62 @@ var many2oneButtonController = (props) => {
4797
4645
  var import_react17 = require("react");
4798
4646
  var import_utils8 = require("@fctc/interface-logic/utils");
4799
4647
  var many2manyFieldController = (props) => {
4800
- const { relation, domain, context, options, tab, setSelectedRowKeys: setSelectedRowKeys2 } = props;
4648
+ const {
4649
+ relation,
4650
+ domain,
4651
+ context,
4652
+ options,
4653
+ tab,
4654
+ setSelectedRowKeys: setSelectedRowKeys2,
4655
+ groupByDomain,
4656
+ enabled: enabledCallAPI,
4657
+ actionData
4658
+ } = props;
4801
4659
  const { env } = (0, provider_exports.useEnv)();
4802
- const { useGetFormView: useGetFormView2 } = (0, provider_exports.useService)();
4660
+ const { useGetView: useGetView2, useGetListData: useGetListData2, useGetFormView: useGetFormView2 } = (0, provider_exports.useService)();
4661
+ const [order, setOrder] = (0, import_react17.useState)();
4803
4662
  const [page, setPage] = (0, import_react17.useState)(0);
4804
4663
  const [domainMany2Many, setDomainMany2Many] = (0, import_react17.useState)(null);
4805
- const { action } = useAppProvider();
4664
+ const [debouncedPage] = useDebounce(page, 500);
4806
4665
  const contextObject = {
4807
4666
  ...env.context,
4808
4667
  ...context || {}
4809
4668
  };
4810
- const { data: viewResponse } = useViewV2({
4811
- model: String(relation),
4669
+ const viewParams = {
4670
+ model: relation,
4812
4671
  views: [
4813
4672
  [false, "list"],
4814
4673
  [false, "search"]
4815
4674
  ],
4816
4675
  context: contextObject
4817
- });
4676
+ };
4677
+ const { data: viewResponse } = useGetView2(viewParams, enabledCallAPI);
4678
+ const baseModel = (0, import_react17.useMemo)(
4679
+ () => ({
4680
+ name: String(relation),
4681
+ view: viewResponse || {},
4682
+ actContext: contextObject,
4683
+ fields: [
4684
+ ...Object.values(viewResponse?.views?.list?.fields ?? {}),
4685
+ ...tab?.fields ? tab.fields : []
4686
+ ]
4687
+ }),
4688
+ [relation, viewResponse]
4689
+ );
4690
+ const initModel = (0, import_hooks3.useModel)();
4691
+ const modelInstance = (0, import_react17.useMemo)(() => {
4692
+ if (viewResponse) {
4693
+ return initModel.initModel(baseModel);
4694
+ }
4695
+ return null;
4696
+ }, [baseModel, viewResponse]);
4697
+ const specification = (0, import_react17.useMemo)(() => {
4698
+ if (modelInstance) {
4699
+ return modelInstance.getSpecification();
4700
+ }
4701
+ return null;
4702
+ }, [modelInstance]);
4703
+ const default_order = viewResponse && viewResponse?.views?.list?.default_order;
4818
4704
  const optionsObject = tab?.options ? (0, import_utils8.evalJSONContext)(tab?.options) : (options ? (0, import_utils8.evalJSONContext)(options) : {}) || {};
4819
4705
  const fetchData = async () => {
4820
4706
  try {
@@ -4825,17 +4711,32 @@ var many2manyFieldController = (props) => {
4825
4711
  console.log(err);
4826
4712
  }
4827
4713
  };
4714
+ const queryKey = [
4715
+ `view-${relation}`,
4716
+ specification,
4717
+ domainMany2Many,
4718
+ debouncedPage,
4719
+ groupByDomain,
4720
+ order
4721
+ ];
4722
+ const data = {
4723
+ model: relation,
4724
+ specification,
4725
+ domain: domainMany2Many,
4726
+ offset: debouncedPage * 10,
4727
+ limit: 10,
4728
+ context: contextObject,
4729
+ fields: groupByDomain?.fields,
4730
+ groupby: [groupByDomain?.contexts[0]?.group_by],
4731
+ sort: order ? order : default_order ? (0, import_utils8.formatSortingString)(default_order) : ""
4732
+ };
4733
+ const enabled = enabledCallAPI && !!specification && !!relation && !!domainMany2Many && !!viewResponse;
4828
4734
  const {
4829
4735
  data: dataResponse,
4736
+ isLoading,
4830
4737
  isFetched,
4831
- isPlaceholderData,
4832
- isLoading
4833
- } = useListData({
4834
- action,
4835
- context,
4836
- model: String(relation),
4837
- viewData: viewResponse
4838
- });
4738
+ isPlaceholderData
4739
+ } = useGetListData2(data, queryKey, enabled);
4839
4740
  (0, import_react17.useEffect)(() => {
4840
4741
  if (viewResponse) {
4841
4742
  fetchData();
@@ -4866,31 +4767,7 @@ var many2manyFieldController = (props) => {
4866
4767
  )?.map((col) => ({ ...col.field })) ?? []
4867
4768
  ]
4868
4769
  });
4869
- const {
4870
- refetch,
4871
- data: dataFormViewResponse,
4872
- isSuccess
4873
- } = useGetFormView2({
4874
- data: {
4875
- id: null,
4876
- model: relation ?? "",
4877
- context: contextObject
4878
- },
4879
- queryKey: [`form-view-action-${relation}`],
4880
- enabled: false
4881
- });
4882
- (0, import_react17.useEffect)(() => {
4883
- if (isSuccess && dataFormViewResponse) {
4884
- sessionStorage.setItem("actionData", JSON.stringify(dataFormViewResponse));
4885
- window.location.href = `/form/menu?model=${relation}`;
4886
- }
4887
- }, [isSuccess]);
4888
4770
  const handleCreateNewOnPage = async () => {
4889
- try {
4890
- refetch();
4891
- } catch (error) {
4892
- console.log(error);
4893
- }
4894
4771
  };
4895
4772
  return {
4896
4773
  handleCreateNewOnPage,