@fctc/widget-logic 2.0.8 → 2.0.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/widget.mjs CHANGED
@@ -4978,6 +4978,7 @@ var many2oneFieldController = (props) => {
4978
4978
  options: fieldOptions,
4979
4979
  showDetail
4980
4980
  } = props;
4981
+ const { env } = (0, provider_exports.useEnv)();
4981
4982
  const [options, setOptions] = useState7([]);
4982
4983
  const [inputValue, setInputValue] = useState7("");
4983
4984
  const [debouncedInputValue] = useDebounce(inputValue, 1e3);
@@ -4987,15 +4988,14 @@ var many2oneFieldController = (props) => {
4987
4988
  const [domainObject, setDomainObject] = useState7(null);
4988
4989
  const actionData = sessionStorageUtils.getActionData();
4989
4990
  const { menuList } = (0, store_exports.useAppSelector)(store_exports.selectNavbar);
4990
- const { context } = (0, store_exports.useAppSelector)(store_exports.selectEnv);
4991
4991
  const initValue = methods?.getValues(name);
4992
4992
  const optionsObject = (0, utils_exports.evalJSONContext)(fieldOptions) || {};
4993
4993
  const contextObject = {
4994
4994
  ...(0, utils_exports.evalJSONContext)(actionData?.context) || {},
4995
4995
  ...fieldContext,
4996
- ...context
4996
+ ...env?.context
4997
4997
  };
4998
- const { useGetSelection: useGetSelection2 } = (0, provider_exports.useService)();
4998
+ const { useGetSelection: useGetSelection3 } = (0, provider_exports.useService)();
4999
4999
  const data = {
5000
5000
  model: relation,
5001
5001
  domain: domainObject,
@@ -5011,7 +5011,7 @@ var many2oneFieldController = (props) => {
5011
5011
  data: dataOfSelection,
5012
5012
  refetch,
5013
5013
  isFetching
5014
- } = useGetSelection2({
5014
+ } = useGetSelection3({
5015
5015
  data,
5016
5016
  queryKey,
5017
5017
  enabled: false
@@ -5165,15 +5165,9 @@ var many2oneButtonController = (props) => {
5165
5165
 
5166
5166
  // src/widget/basic/many2many-field/controller.ts
5167
5167
  import { useEffect as useEffect11, useMemo as useMemo10, useState as useState8 } from "react";
5168
- import {
5169
- useAppDispatch as useAppDispatch5,
5170
- setFirstDomain,
5171
- setViewDataStore,
5172
- setPage,
5173
- setGroupByDomain
5174
- } from "@fctc/interface-logic/store";
5175
5168
  import {
5176
5169
  evalJSONContext as evalJSONContext4,
5170
+ evalJSONDomain as evalJSONDomain4,
5177
5171
  formatSortingString as formatSortingString2
5178
5172
  } from "@fctc/interface-logic/utils";
5179
5173
  var many2manyFieldController = (props) => {
@@ -5181,45 +5175,43 @@ var many2manyFieldController = (props) => {
5181
5175
  relation,
5182
5176
  domain,
5183
5177
  context,
5178
+ options,
5184
5179
  tab,
5185
- model,
5186
- aid,
5187
5180
  setSelectedRowKeys: setSelectedRowKeys4,
5188
- fields,
5189
- setFields,
5190
5181
  groupByDomain,
5191
- page,
5192
- options,
5193
- sessionStorageUtils
5182
+ enabled: enabledCallAPI,
5183
+ actionData
5194
5184
  } = props;
5195
- const appDispatch = useAppDispatch5();
5196
- const actionData = sessionStorageUtils.getActionData();
5197
- const [debouncedPage] = useDebounce(page, 500);
5198
- const [order, setOrder] = useState8();
5199
- const [isLoadedData, setIsLoadedData] = useState8(false);
5200
- const [domainMany2Many, setDomainMany2Many] = useState8(domain);
5201
5185
  const { env } = (0, provider_exports.useEnv)();
5202
5186
  const { useGetView: useGetView2, useGetListData: useGetListData3, useGetFormView } = (0, provider_exports.useService)();
5187
+ const [order, setOrder] = useState8();
5188
+ const [page, setPage] = useState8(0);
5189
+ const [domainMany2Many, setDomainMany2Many] = useState8(null);
5190
+ const [debouncedPage] = useDebounce(page, 500);
5191
+ const contextObject = {
5192
+ ...env.context,
5193
+ ...context || {}
5194
+ };
5203
5195
  const viewParams = {
5204
5196
  model: relation,
5205
5197
  views: [
5206
5198
  [false, "list"],
5207
5199
  [false, "search"]
5208
5200
  ],
5209
- context
5201
+ context: contextObject
5210
5202
  };
5211
- const { data: viewResponse } = useGetView2(viewParams, actionData);
5203
+ const { data: viewResponse } = useGetView2(viewParams, enabledCallAPI);
5212
5204
  const baseModel = useMemo10(
5213
5205
  () => ({
5214
5206
  name: String(relation),
5215
5207
  view: viewResponse || {},
5216
- actContext: context,
5208
+ actContext: contextObject,
5217
5209
  fields: [
5218
5210
  ...Object.values(viewResponse?.views?.list?.fields ?? {}),
5219
5211
  ...tab?.fields ? tab.fields : []
5220
5212
  ]
5221
5213
  }),
5222
- [model, viewResponse]
5214
+ [relation, viewResponse]
5223
5215
  );
5224
5216
  const initModel = (0, hooks_exports.useModel)();
5225
5217
  const modelInstance = useMemo10(() => {
@@ -5238,26 +5230,15 @@ var many2manyFieldController = (props) => {
5238
5230
  const optionsObject = tab?.options ? evalJSONContext4(tab?.options) : (options ? evalJSONContext4(options) : {}) || {};
5239
5231
  const fetchData = async () => {
5240
5232
  try {
5241
- setDomainMany2Many(domain);
5242
- appDispatch(setFirstDomain(domain));
5243
- appDispatch(setViewDataStore(viewResponse));
5244
- const modalData = viewResponse?.views?.list?.fields.map((field) => ({
5245
- ...viewResponse?.models?.[String(model)]?.[field?.name],
5246
- ...field
5247
- }));
5248
- if (!fields?.[`${aid}_${relation}_popupmany2many`] && modalData) {
5249
- setFields({
5250
- ...fields,
5251
- [`${aid}_${relation}_popupmany2many`]: modalData
5252
- });
5253
- }
5254
- appDispatch(setPage(0));
5233
+ const domainParse = typeof domain === "string" ? evalJSONDomain4(domain, contextObject) : Array.isArray(domain) ? domain : [];
5234
+ setDomainMany2Many(domainParse);
5235
+ setPage(0);
5255
5236
  } catch (err) {
5256
5237
  console.log(err);
5257
5238
  }
5258
5239
  };
5259
5240
  const queryKey = [
5260
- `view-${relation}-${aid}`,
5241
+ `view-${relation}`,
5261
5242
  specification,
5262
5243
  domainMany2Many,
5263
5244
  debouncedPage,
@@ -5270,16 +5251,16 @@ var many2manyFieldController = (props) => {
5270
5251
  domain: domainMany2Many,
5271
5252
  offset: debouncedPage * 10,
5272
5253
  limit: 10,
5273
- context,
5254
+ context: contextObject,
5274
5255
  fields: groupByDomain?.fields,
5275
5256
  groupby: [groupByDomain?.contexts[0]?.group_by],
5276
5257
  sort: order ? order : default_order ? formatSortingString2(default_order) : ""
5277
5258
  };
5278
- const enabled = isLoadedData && !!specification && !!relation && !!domainMany2Many && !!viewResponse;
5259
+ const enabled = enabledCallAPI && !!specification && !!relation && !!domainMany2Many && !!viewResponse;
5279
5260
  const {
5280
5261
  data: dataResponse,
5281
- isLoading: isDataLoading,
5282
- isFetched: isDataResponseFetched,
5262
+ isLoading,
5263
+ isFetched,
5283
5264
  isPlaceholderData
5284
5265
  } = useGetListData3(data, queryKey, enabled);
5285
5266
  useEffect11(() => {
@@ -5287,74 +5268,59 @@ var many2manyFieldController = (props) => {
5287
5268
  fetchData();
5288
5269
  }
5289
5270
  return () => {
5290
- appDispatch(setGroupByDomain(null));
5291
- setFields((prevFields) => ({
5292
- ...prevFields,
5293
- [`${aid}_${relation}_popupmany2many`]: null
5294
- }));
5295
- appDispatch(setPage(0));
5271
+ setPage(0);
5296
5272
  setSelectedRowKeys4([]);
5297
5273
  setDomainMany2Many(null);
5298
- setIsLoadedData(false);
5299
5274
  };
5300
5275
  }, [viewResponse]);
5301
- const { rows, columns, typeTable } = tableController({
5276
+ const { rows, columns, typeTable, onToggleColumnOptional } = tableController({
5302
5277
  data: {
5303
- fields: fields?.[`${aid}_${relation}_popupmany2many`] || viewResponse?.views?.list?.fields,
5278
+ fields: viewResponse?.views?.list?.fields,
5304
5279
  records: dataResponse?.records ?? dataResponse?.groups,
5305
5280
  dataModel: viewResponse?.models?.[String(relation)],
5306
- context: { ...env.context, ...context },
5281
+ context: contextObject,
5307
5282
  typeTable: dataResponse?.groups ? "group" : "list"
5308
5283
  }
5309
5284
  });
5310
- const dataFormView = {
5311
- id: null,
5312
- model: relation,
5313
- context
5314
- };
5315
- const {
5316
- refetch,
5317
- data: dataFormViewResponse,
5318
- isSuccess
5319
- } = useGetFormView({
5320
- data: dataFormView,
5321
- queryKey: [`form-view-action-${relation}`],
5322
- enabled: false
5285
+ const searchControllers = searchController({
5286
+ viewData: viewResponse,
5287
+ model: relation ?? "",
5288
+ context: contextObject,
5289
+ domain,
5290
+ fieldsList: [
5291
+ ...columns?.filter(
5292
+ (col) => col?.field?.type_co === "field" && col?.optional !== "hide"
5293
+ )?.map((col) => ({ ...col.field })) ?? []
5294
+ ]
5323
5295
  });
5324
- useEffect11(() => {
5325
- if (isSuccess && dataFormViewResponse) {
5326
- sessionStorage.setItem("actionData", JSON.stringify(dataFormViewResponse));
5327
- window.location.href = `/form/menu?model=${relation}`;
5328
- }
5329
- }, [isSuccess]);
5330
- useEffect11(() => {
5331
- if (domainMany2Many && !isLoadedData) {
5332
- setIsLoadedData(true);
5333
- }
5334
- }, [domainMany2Many]);
5335
5296
  const handleCreateNewOnPage = async () => {
5336
- try {
5337
- refetch();
5338
- } catch (error) {
5339
- console.log(error);
5340
- }
5341
5297
  };
5342
5298
  return {
5343
5299
  handleCreateNewOnPage,
5344
5300
  optionsObject,
5301
+ totalRows: dataResponse?.length ?? 0,
5345
5302
  rows,
5346
5303
  columns,
5304
+ onToggleColumnOptional,
5347
5305
  typeTable,
5348
- isDataLoading,
5349
- isDataResponseFetched,
5350
- isPlaceholderData
5306
+ isLoading,
5307
+ isFetched,
5308
+ isPlaceholderData,
5309
+ setPage,
5310
+ page,
5311
+ viewData: viewResponse,
5312
+ domain: domainMany2Many,
5313
+ setDomain: setDomainMany2Many,
5314
+ searchController: searchControllers
5351
5315
  };
5352
5316
  };
5353
5317
 
5354
5318
  // src/widget/basic/many2many-tags-field/controller.ts
5355
5319
  import { useMemo as useMemo11 } from "react";
5356
5320
  import { WIDGETAVATAR, WIDGETCOLOR } from "@fctc/interface-logic/constants";
5357
- import { evalJSONContext as evalJSONContext5, evalJSONDomain as evalJSONDomain4 } from "@fctc/interface-logic/utils";
5321
+ import { getEnv as getEnv7 } from "@fctc/interface-logic/environment";
5322
+ import { useGetSelection as useGetSelection2 } from "@fctc/interface-logic/hooks";
5323
+ import { evalJSONContext as evalJSONContext5, evalJSONDomain as evalJSONDomain5 } from "@fctc/interface-logic/utils";
5358
5324
  var many2manyTagsController = (props) => {
5359
5325
  const {
5360
5326
  relation,
@@ -5365,11 +5331,10 @@ var many2manyTagsController = (props) => {
5365
5331
  placeholderNoOption
5366
5332
  } = props;
5367
5333
  const isUser = relation === "res.users" || relation === "res.partner";
5368
- const { env } = (0, provider_exports.useEnv)();
5369
- const { useGetSelection: useGetSelection2 } = (0, provider_exports.useService)();
5334
+ const env = getEnv7();
5370
5335
  const addtionalFields = optionsFields ? evalJSONContext5(optionsFields) : null;
5371
5336
  const domainObject = useMemo11(
5372
- () => evalJSONDomain4(domain, JSON.parse(JSON.stringify(formValues || {}))),
5337
+ () => evalJSONDomain5(domain, JSON.parse(JSON.stringify(formValues || {}))),
5373
5338
  [domain, formValues]
5374
5339
  );
5375
5340
  const data = {
@@ -5405,15 +5370,16 @@ var many2manyTagsController = (props) => {
5405
5370
  options,
5406
5371
  customNoOptionsMessage,
5407
5372
  tranfer,
5373
+ dataOfSelection,
5408
5374
  isUser
5409
5375
  };
5410
5376
  };
5411
5377
 
5412
5378
  // src/widget/basic/status-bar-field/controller.ts
5413
5379
  import { useState as useState9 } from "react";
5414
- import { evalJSONDomain as evalJSONDomain5 } from "@fctc/interface-logic/utils";
5380
+ import { evalJSONDomain as evalJSONDomain6 } from "@fctc/interface-logic/utils";
5415
5381
  var durationController = (props) => {
5416
- const { relation, domain, formValues, name, id, model, onRefetch, enabled } = props;
5382
+ const { relation, domain, formValues, name, id, model, onRefetch } = props;
5417
5383
  const specification = {
5418
5384
  id: 0,
5419
5385
  name: "",
@@ -5427,7 +5393,7 @@ var durationController = (props) => {
5427
5393
  const listDataProps = {
5428
5394
  model: relation,
5429
5395
  specification,
5430
- domain: evalJSONDomain5(domain, JSON.parse(JSON.stringify(formValues))),
5396
+ domain: evalJSONDomain6(domain, JSON.parse(JSON.stringify(formValues))),
5431
5397
  limit: 10,
5432
5398
  offset: 0,
5433
5399
  fields: "",
@@ -5437,11 +5403,7 @@ var durationController = (props) => {
5437
5403
  },
5438
5404
  sort: ""
5439
5405
  };
5440
- const { data: dataResponse } = useGetListData3(
5441
- listDataProps,
5442
- queryKey,
5443
- enabled
5444
- );
5406
+ const { data: dataResponse } = useGetListData3(listDataProps, queryKey);
5445
5407
  const { mutate: fetchChangeStatus } = useChangeStatus();
5446
5408
  const handleClick = async (stage_id) => {
5447
5409
  setDisabled(true);
@@ -5477,18 +5439,32 @@ var durationController = (props) => {
5477
5439
  };
5478
5440
 
5479
5441
  // src/widget/basic/priority-field/controller.ts
5442
+ import { useSave as useSave2 } from "@fctc/interface-logic/hooks";
5480
5443
  import { evalJSONContext as evalJSONContext6 } from "@fctc/interface-logic/utils";
5481
5444
  var priorityFieldController = (props) => {
5482
- const { name, model, id, actionData, context, onChange } = props;
5445
+ const {
5446
+ value,
5447
+ isForm,
5448
+ name,
5449
+ methods,
5450
+ onChange,
5451
+ model,
5452
+ selection,
5453
+ id,
5454
+ actionData,
5455
+ viewData,
5456
+ context
5457
+ } = props;
5483
5458
  const _context = { ...evalJSONContext6(actionData?.context) };
5484
5459
  const contextObject = { ...context, ..._context };
5485
- const { useSave: useSave2 } = (0, provider_exports.useService)();
5460
+ const defaultPriority = parseInt(value) + 1;
5461
+ const label = viewData?.models?.[model]?.[name ?? ""]?.string ?? name;
5486
5462
  const { mutateAsync: fetchSave } = useSave2();
5487
5463
  const savePriorities = async ({
5488
- value,
5464
+ value: value2,
5489
5465
  resetPriority
5490
5466
  }) => {
5491
- const priorityValue = value <= 0 ? 0 : value - 1;
5467
+ const priorityValue = value2 <= 0 ? 0 : value2 - 1;
5492
5468
  try {
5493
5469
  fetchSave({
5494
5470
  ids: id ? [id] : [],
@@ -5506,7 +5482,14 @@ var priorityFieldController = (props) => {
5506
5482
  }
5507
5483
  };
5508
5484
  return {
5509
- savePriorities
5485
+ selection,
5486
+ isForm,
5487
+ methods,
5488
+ defaultPriority,
5489
+ savePriorities,
5490
+ label,
5491
+ id,
5492
+ onChange
5510
5493
  };
5511
5494
  };
5512
5495
 
@@ -6469,11 +6452,11 @@ import { evalJSONContext as evalJSONContext7 } from "@fctc/interface-logic/utils
6469
6452
  var colorFieldController = (props) => {
6470
6453
  const { value, isForm, name, formValues, idForm, model, actionData } = props;
6471
6454
  const { env } = (0, provider_exports.useEnv)();
6472
- const { useSave: useSave2 } = (0, provider_exports.useService)();
6455
+ const { useSave: useSave3 } = (0, provider_exports.useService)();
6473
6456
  const _context = { ...evalJSONContext7(actionData?.context) || {} };
6474
6457
  const contextObject = { ...env.context, ..._context };
6475
6458
  const idDefault = isForm ? idForm : formValues?.id;
6476
- const { mutate: onSave } = useSave2();
6459
+ const { mutate: onSave } = useSave3();
6477
6460
  const savePickColor = async (colorObject) => {
6478
6461
  const { id } = colorObject;
6479
6462
  if (value === id) return;
@@ -6596,25 +6579,20 @@ var binaryFieldController = (props) => {
6596
6579
  };
6597
6580
 
6598
6581
  // src/widget/advance/table/table-body/controller.ts
6599
- import {
6600
- useAppDispatch as useAppDispatch6,
6601
- setSelectedRowKeys,
6602
- useAppSelector as useAppSelector4,
6603
- selectList as selectList3
6604
- } from "@fctc/interface-logic/store";
6582
+ import { useAppDispatch as useAppDispatch5, setSelectedRowKeys } from "@fctc/interface-logic/store";
6605
6583
  import { useEffect as useEffect13, useMemo as useMemo12 } from "react";
6606
6584
  var tableBodyController = (props) => {
6607
6585
  const {
6608
6586
  checkedAll,
6609
6587
  checkboxRef,
6610
6588
  setIsAutoSelect,
6589
+ selectedRowKeys,
6611
6590
  row,
6612
6591
  isAutoSelect,
6613
6592
  selectedRowKeysRef,
6614
6593
  onClickRow
6615
6594
  } = props;
6616
- const appDispatch = useAppDispatch6();
6617
- const { selectedRowKeys } = useAppSelector4(selectList3);
6595
+ const appDispatch = useAppDispatch5();
6618
6596
  const checked = useMemo12(() => {
6619
6597
  if (!row?.id) return false;
6620
6598
  if (selectedRowKeys?.includes(row.id)) {
@@ -6630,6 +6608,7 @@ var tableBodyController = (props) => {
6630
6608
  return;
6631
6609
  }
6632
6610
  const newSelectedRowKeys = selectedRowKeys?.includes(row.id) ? selectedRowKeys?.filter((key) => key !== row.id) : [...selectedRowKeys, row.id];
6611
+ console.log("newSelectedRowKeys", newSelectedRowKeys);
6633
6612
  appDispatch(setSelectedRowKeys(newSelectedRowKeys));
6634
6613
  };
6635
6614
  const handleClickRow = (col, row2) => {
@@ -6668,15 +6647,15 @@ var tableBodyController = (props) => {
6668
6647
 
6669
6648
  // src/widget/advance/table/table-head/controller.ts
6670
6649
  import {
6671
- useAppDispatch as useAppDispatch7,
6672
- useAppSelector as useAppSelector5,
6650
+ useAppDispatch as useAppDispatch6,
6651
+ useAppSelector as useAppSelector4,
6673
6652
  selectSearch as selectSearch3,
6674
6653
  setSelectedRowKeys as setSelectedRowKeys2
6675
6654
  } from "@fctc/interface-logic/store";
6676
6655
  var tableHeadController = (props) => {
6677
6656
  const { typeTable, rows, selectedRowKeysRef } = props;
6678
- const appDispatch = useAppDispatch7();
6679
- const { groupByDomain } = useAppSelector5(selectSearch3);
6657
+ const appDispatch = useAppDispatch6();
6658
+ const { groupByDomain } = useAppSelector4(selectSearch3);
6680
6659
  const handleCheckBoxAll = (event) => {
6681
6660
  if (event?.target?.checked && typeTable === "list") {
6682
6661
  const allRowKeys = Array.isArray(rows) ? rows.map((record) => record?.id) : [];
@@ -6711,9 +6690,9 @@ var tableHeadController = (props) => {
6711
6690
  // src/widget/advance/table/table-view/controller.ts
6712
6691
  import { useEffect as useEffect14, useMemo as useMemo13, useRef as useRef5, useState as useState13 } from "react";
6713
6692
  import {
6714
- useAppSelector as useAppSelector6,
6693
+ useAppSelector as useAppSelector5,
6715
6694
  selectSearch as selectSearch4,
6716
- selectList as selectList4
6695
+ selectList as selectList3
6717
6696
  } from "@fctc/interface-logic/store";
6718
6697
  import { domainHelper } from "@fctc/interface-logic/utils";
6719
6698
  var tableController = ({ data }) => {
@@ -6798,10 +6777,10 @@ import {
6798
6777
  useGetListData as useGetListData2
6799
6778
  } from "@fctc/interface-logic/hooks";
6800
6779
  import {
6801
- useAppSelector as useAppSelector7,
6780
+ useAppSelector as useAppSelector6,
6802
6781
  selectSearch as selectSearch5,
6803
- selectList as selectList5,
6804
- useAppDispatch as useAppDispatch8,
6782
+ selectList as selectList4,
6783
+ useAppDispatch as useAppDispatch7,
6805
6784
  setSelectedRowKeys as setSelectedRowKeys3
6806
6785
  } from "@fctc/interface-logic/store";
6807
6786
 
@@ -6832,9 +6811,9 @@ var tableGroupController = (props) => {
6832
6811
  selectedRowKeysRef
6833
6812
  } = props;
6834
6813
  const [pageGroup, setPageGroup] = useState14(0);
6835
- const { groupByDomain, selectedTags } = useAppSelector7(selectSearch5);
6836
- const { selectedRowKeys } = useAppSelector7(selectList5);
6837
- const appDispatch = useAppDispatch8();
6814
+ const { groupByDomain, selectedTags } = useAppSelector6(selectSearch5);
6815
+ const { selectedRowKeys } = useAppSelector6(selectList4);
6816
+ const appDispatch = useAppDispatch7();
6838
6817
  const { toDataJS } = useOdooDataTransform();
6839
6818
  const initVal = toDataJS(row, viewData, model);
6840
6819
  const [isShowGroup, setIsShowGroup] = useState14(false);
@@ -6975,26 +6954,28 @@ var import_moment2 = __toESM(require_moment());
6975
6954
  import { SearchType } from "@fctc/interface-logic/constants";
6976
6955
  import {
6977
6956
  domainHelper as domainHelper2,
6978
- evalJSONDomain as evalJSONDomain6,
6957
+ evalJSONContext as evalJSONContext8,
6958
+ evalJSONDomain as evalJSONDomain7,
6979
6959
  validateAndParseDate
6980
6960
  } from "@fctc/interface-logic/utils";
6981
6961
  import { useCallback as useCallback3, useEffect as useEffect16, useState as useState15 } from "react";
6982
6962
  var searchController = ({
6983
6963
  viewData,
6984
- actionData,
6985
- fieldsList,
6986
- contextSearch,
6987
- setSearchMap,
6988
- searchMap
6964
+ model,
6965
+ domain,
6966
+ context,
6967
+ fieldsList
6989
6968
  }) => {
6969
+ const { env } = (0, provider_exports.useEnv)();
6990
6970
  const [filterBy, setFilterBy] = useState15(null);
6991
6971
  const [searchBy, setSearchBy] = useState15(null);
6992
6972
  const [groupBy, setGroupBy] = useState15(null);
6993
6973
  const [selectedTags, setSelectedTags] = useState15(null);
6994
6974
  const [searchString, setSearchString] = useState15("");
6995
- const domainAction = actionData?.domain ? Array.isArray(actionData?.domain) ? [...actionData?.domain] : evalJSONDomain6(actionData?.domain, contextSearch) : [];
6996
- const aid = actionData?.id;
6997
- const model = actionData?.res_model;
6975
+ const [searchMap, setSearchMap] = useState15({});
6976
+ const actionContext = typeof context === "string" ? evalJSONContext8(context) : context;
6977
+ const contextSearch = { ...env.context, ...actionContext };
6978
+ const domainAction = domain ? Array.isArray(domain) ? [...domain] : evalJSONDomain7(domain, contextSearch) : [];
6998
6979
  const clearSearch = () => {
6999
6980
  setFilterBy([]);
7000
6981
  setGroupBy([]);
@@ -7039,9 +7020,8 @@ var searchController = ({
7039
7020
  }
7040
7021
  };
7041
7022
  useEffect16(() => {
7042
- clearSearch();
7043
7023
  fetchData();
7044
- }, [aid, model, viewData]);
7024
+ }, [model, viewData]);
7045
7025
  const onChangeSearchInput = (search_string) => {
7046
7026
  setSearchString(search_string);
7047
7027
  };
@@ -7078,27 +7058,27 @@ var searchController = ({
7078
7058
  };
7079
7059
  const formatDomain = () => {
7080
7060
  if (domainAction) {
7081
- const domain = [];
7061
+ const domain2 = [];
7082
7062
  if (domainAction?.length > 0) {
7083
- if (Object.keys(searchMap).length > 0) {
7084
- domain.push("&");
7063
+ if (Object.keys(searchMap).some((key) => !key.includes(SearchType.GROUP))) {
7064
+ domain2.push("&");
7085
7065
  }
7086
7066
  domainAction.forEach((domainItem) => {
7087
- domain.push(domainItem);
7067
+ domain2.push(domainItem);
7088
7068
  });
7089
7069
  }
7090
7070
  Object.keys(searchMap).forEach((key, keyIndex, keys) => {
7091
7071
  if (!key?.includes(SearchType.GROUP)) {
7092
7072
  if (keys.length > 1 && keyIndex < keys.length - 1) {
7093
- domain.push("&");
7073
+ domain2.push("&");
7094
7074
  }
7095
7075
  const valuesOfKey = searchMap[key];
7096
7076
  valuesOfKey.forEach((value, index) => {
7097
7077
  if (index < valuesOfKey.length - 1) {
7098
- domain.push("|");
7078
+ domain2.push("|");
7099
7079
  }
7100
7080
  if (value.domain) {
7101
- domain.push(...value.domain);
7081
+ domain2.push(...value.domain);
7102
7082
  return;
7103
7083
  }
7104
7084
  let valueDomainItem = value?.value;
@@ -7114,11 +7094,11 @@ var searchController = ({
7114
7094
  }
7115
7095
  }
7116
7096
  const operator = value?.modelType === "date" || value?.modelType === "datetime" || value?.modelType === "boolean" || value?.modelType === "integer" ? value?.operator ?? "=" : value.operator ?? "ilike";
7117
- domain.push([value.name, operator, valueDomainItem]);
7097
+ domain2.push([value.name, operator, valueDomainItem]);
7118
7098
  });
7119
7099
  }
7120
7100
  });
7121
- return [...domain];
7101
+ return [...domain2];
7122
7102
  }
7123
7103
  };
7124
7104
  const setTagSearch = useCallback3(
@@ -7149,16 +7129,16 @@ var searchController = ({
7149
7129
  const contexts = [];
7150
7130
  let groupValues = [];
7151
7131
  objValues?.forEach((objValue) => {
7152
- const { context, value, active, groupIndex: groupIndex2, isDefault } = objValue;
7132
+ const { context: context2, value, active, groupIndex: groupIndex2, isDefault } = objValue;
7153
7133
  const indexAppend = groupIndex2 != null ? groupIndex2 : viewData?.views?.search?.filters_by?.length ?? 0;
7154
7134
  contexts.push(
7155
- ...Array.isArray(context?.group_by) ? context.group_by.map((item) => ({ group_by: item })) : [context]
7135
+ ...Array.isArray(context2?.group_by) ? context2.group_by.map((item) => ({ group_by: item })) : [context2]
7156
7136
  );
7157
7137
  groupValues[indexAppend] = {
7158
7138
  contexts: [
7159
- ...Array.isArray(context?.group_by) ? context.group_by.map((item) => ({
7139
+ ...Array.isArray(context2?.group_by) ? context2.group_by.map((item) => ({
7160
7140
  group_by: item
7161
- })) : [context]
7141
+ })) : [context2]
7162
7142
  ],
7163
7143
  strings: isDefault ? [value] : [...groupValues[indexAppend]?.strings ?? [], value]
7164
7144
  };
@@ -7185,39 +7165,38 @@ var searchController = ({
7185
7165
  [searchMap]
7186
7166
  );
7187
7167
  useEffect16(() => {
7188
- setSelectedTags(null);
7189
7168
  setTagSearch(searchMap);
7190
7169
  }, [searchMap]);
7191
7170
  const handleAddTagSearch = (tag) => {
7192
7171
  const {
7193
- domain,
7172
+ domain: domain2,
7194
7173
  groupIndex,
7195
7174
  value,
7196
7175
  type,
7197
7176
  title,
7198
- context,
7177
+ context: context2,
7199
7178
  active,
7200
7179
  dataIndex
7201
7180
  } = tag;
7202
- const domainFormat = new domainHelper2.Domain(domain);
7181
+ const domainFormat = new domainHelper2.Domain(domain2);
7203
7182
  if (type === SearchType.FILTER) {
7204
7183
  addSearchItems(`${SearchType.FILTER}_${groupIndex}`, {
7205
7184
  ...tag,
7206
- domain: domain ? domainFormat.toList(context) : null
7185
+ domain: domain2 ? domainFormat.toList(context2) : null
7207
7186
  });
7208
7187
  } else if (type === SearchType.SEARCH) {
7209
7188
  addSearchItems(`${SearchType.SEARCH}_${String(dataIndex)}`, {
7210
7189
  ...tag,
7211
- domain: domain ? domainFormat.toList({
7212
- ...context,
7190
+ domain: domain2 ? domainFormat.toList({
7191
+ ...context2,
7213
7192
  self: value
7214
7193
  }) : null
7215
7194
  });
7216
7195
  } else if (type === SearchType.GROUP) {
7217
7196
  addSearchItems(`${SearchType.GROUP}`, {
7218
7197
  ...tag,
7219
- domain: domain ? domainFormat.toList({
7220
- context,
7198
+ domain: domain2 ? domainFormat.toList({
7199
+ context: context2,
7221
7200
  self: value
7222
7201
  }) : null
7223
7202
  });
@@ -7237,7 +7216,8 @@ var searchController = ({
7237
7216
  removeSearchItems,
7238
7217
  onSearchString: onChangeSearchInput,
7239
7218
  handleAddTagSearch,
7240
- domain: formatDomain()
7219
+ domain: formatDomain(),
7220
+ context: contextSearch
7241
7221
  };
7242
7222
  };
7243
7223
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/widget-logic",
3
- "version": "2.0.8",
3
+ "version": "2.0.9",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",