@universe-platform/ui 0.1.0-beta.20 → 0.1.0-beta.22

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/index.js CHANGED
@@ -67,13 +67,16 @@ __export(src_exports, {
67
67
  ColumnHeaderTitle: () => ColumnHeaderTitle,
68
68
  CreateTemplateModal: () => CreateTemplateModal,
69
69
  DatePickerCell: () => DatePickerCell,
70
+ DynamicFiltersBlock: () => DynamicFiltersBlock,
70
71
  LinkPickerCell: () => LinkPickerCell,
71
72
  PASTEL_PALETTES: () => PASTEL_PALETTES,
72
73
  RelationFilterPopover: () => RelationFilterPopover,
73
74
  RelationPickerCell: () => RelationPickerCell,
75
+ SettingsAndActionsBlock: () => SettingsAndActionsBlock,
74
76
  SmartTextCell: () => SmartTextCell,
75
77
  TEXT_REPRESENTABLE_TYPES: () => TEXT_REPRESENTABLE_TYPES,
76
78
  TableBlock: () => TableBlock,
79
+ TableBlockClient: () => TableBlockClient,
77
80
  TimePickerCell: () => TimePickerCell,
78
81
  ToastContext: () => ToastContext,
79
82
  ToastProvider: () => ToastProvider,
@@ -124,6 +127,7 @@ __export(src_exports, {
124
127
  useColumnResize: () => useColumnResize,
125
128
  useSmartTooltip: () => useSmartTooltip,
126
129
  useToast: () => useToast,
130
+ useWhatsAppState: () => useWhatsAppState,
127
131
  validateSequentialVariables: () => validateSequentialVariables,
128
132
  validateTemplateBody: () => validateTemplateBody,
129
133
  validateTemplateButtons: () => validateTemplateButtons,
@@ -5692,7 +5696,9 @@ function TableBlockClient({
5692
5696
  role,
5693
5697
  permissions,
5694
5698
  readOnly,
5699
+ selectedRowIds,
5695
5700
  onSelectionChange,
5701
+ onRowToggle,
5696
5702
  rowStatusMap,
5697
5703
  editModelUrl
5698
5704
  }) {
@@ -6136,12 +6142,29 @@ function TableBlockClient({
6136
6142
  setPage((prev) => Math.min(totalPages, prev + 1));
6137
6143
  };
6138
6144
  const [selectedIds, setSelectedIds] = (0, import_react15.useState)(/* @__PURE__ */ new Set());
6145
+ const isExternalSyncRef = (0, import_react15.useRef)(false);
6146
+ (0, import_react15.useEffect)(() => {
6147
+ if (selectedRowIds !== void 0) {
6148
+ const nextSet = new Set(selectedRowIds);
6149
+ setSelectedIds((prev) => {
6150
+ if (prev.size === nextSet.size && Array.from(prev).every((id) => nextSet.has(id))) {
6151
+ return prev;
6152
+ }
6153
+ isExternalSyncRef.current = true;
6154
+ return nextSet;
6155
+ });
6156
+ }
6157
+ }, [selectedRowIds]);
6139
6158
  const isFirstSelectionChangeRef = (0, import_react15.useRef)(true);
6140
6159
  (0, import_react15.useEffect)(() => {
6141
6160
  if (isFirstSelectionChangeRef.current) {
6142
6161
  isFirstSelectionChangeRef.current = false;
6143
6162
  if (selectedIds.size === 0) return;
6144
6163
  }
6164
+ if (isExternalSyncRef.current) {
6165
+ isExternalSyncRef.current = false;
6166
+ return;
6167
+ }
6145
6168
  onSelectionChange == null ? void 0 : onSelectionChange(Array.from(selectedIds));
6146
6169
  }, [selectedIds, onSelectionChange]);
6147
6170
  const [pendingDeletions, setPendingDeletions] = (0, import_react15.useState)([]);
@@ -6590,17 +6613,19 @@ function TableBlockClient({
6590
6613
  }
6591
6614
  }, []);
6592
6615
  const toggleSelectAll = (0, import_react15.useCallback)((checked) => {
6616
+ onRowToggle == null ? void 0 : onRowToggle("ALL", checked);
6593
6617
  const next = checked ? new Set(filteredData.map((r) => r.id)) : /* @__PURE__ */ new Set();
6594
6618
  setSelectedIds(next);
6595
- }, [filteredData]);
6619
+ }, [filteredData, onRowToggle]);
6596
6620
  const toggleSelectRow = (0, import_react15.useCallback)((rowId, checked) => {
6621
+ onRowToggle == null ? void 0 : onRowToggle(rowId, checked);
6597
6622
  setSelectedIds((prev) => {
6598
6623
  const next = new Set(prev);
6599
6624
  if (checked) next.add(rowId);
6600
6625
  else next.delete(rowId);
6601
6626
  return next;
6602
6627
  });
6603
- }, []);
6628
+ }, [onRowToggle]);
6604
6629
  const handleToggleExpand = (0, import_react15.useCallback)((rowId) => {
6605
6630
  setExpandedRowIds((prev) => {
6606
6631
  const next = new Set(prev);
@@ -9975,6 +10000,10 @@ function buildWhatsAppPayload(to, templateName, languageCode, components) {
9975
10000
  }
9976
10001
  async function sendWhatsAppMessage(payload, executeAction, orgId) {
9977
10002
  try {
10003
+ console.log(
10004
+ "[whatsappApi] Dispatching WhatsApp message action with payload:",
10005
+ JSON.stringify(payload, null, 2)
10006
+ );
9978
10007
  const actionPayload = {
9979
10008
  payload
9980
10009
  };
@@ -9984,12 +10013,18 @@ async function sendWhatsAppMessage(payload, executeAction, orgId) {
9984
10013
  }
9985
10014
  const result = await executeAction("SEND_WHATSAPP_MESSAGE", actionPayload);
9986
10015
  if (result && result.success === false) {
10016
+ console.error(
10017
+ "[whatsappApi] SEND_WHATSAPP_MESSAGE dispatch failed:",
10018
+ result.error,
10019
+ result.details || result
10020
+ );
9987
10021
  return {
9988
10022
  success: false,
9989
10023
  error: result.error || "\u05E9\u05DC\u05D9\u05D7\u05EA \u05D4\u05D5\u05D3\u05E2\u05EA WhatsApp \u05E0\u05DB\u05E9\u05DC\u05D4",
9990
10024
  data: result
9991
10025
  };
9992
10026
  }
10027
+ console.log("[whatsappApi] SEND_WHATSAPP_MESSAGE dispatch succeeded:", result);
9993
10028
  return {
9994
10029
  success: true,
9995
10030
  data: result
@@ -10306,7 +10341,12 @@ function useWhatsAppState(props) {
10306
10341
  const [tableError, setTableError] = (0, import_react17.useState)(null);
10307
10342
  const [filters, setFilters] = (0, import_react17.useState)({});
10308
10343
  const [selectedRowIds, setSelectedRowIds] = (0, import_react17.useState)([]);
10344
+ const [autoSelectCount, setAutoSelectCount] = (0, import_react17.useState)(null);
10345
+ const isAutoSelectingRef = (0, import_react17.useRef)(false);
10346
+ const isManualOverrideRef = (0, import_react17.useRef)(false);
10347
+ const prevAutoSelectCountRef = (0, import_react17.useRef)(null);
10309
10348
  const fetchedTableIdsRef = (0, import_react17.useRef)(/* @__PURE__ */ new Set());
10349
+ const fullyFetchedRelationKeysRef = (0, import_react17.useRef)(/* @__PURE__ */ new Set());
10310
10350
  const loadTableData = (0, import_react17.useCallback)(async () => {
10311
10351
  var _a2;
10312
10352
  const tableId = (settings == null ? void 0 : settings.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableId);
@@ -10331,7 +10371,34 @@ function useWhatsAppState(props) {
10331
10371
  setRawRecords(res.records);
10332
10372
  }
10333
10373
  if (res.relationOptions && typeof res.relationOptions === "object") {
10334
- setRelationOptions((prev) => __spreadValues(__spreadValues({}, prev), res.relationOptions));
10374
+ setRelationOptions((prev) => {
10375
+ const merged = __spreadValues({}, prev);
10376
+ Object.entries(res.relationOptions).forEach(([k, opts]) => {
10377
+ if (Array.isArray(opts)) {
10378
+ const existing = prev[k] || [];
10379
+ if (existing.length >= opts.length && existing.length > 0) {
10380
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10381
+ opts.forEach((o) => {
10382
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10383
+ if (id && !existingMap.has(id)) {
10384
+ existingMap.set(id, o);
10385
+ }
10386
+ });
10387
+ merged[k] = Array.from(existingMap.values());
10388
+ } else {
10389
+ const map = new Map(opts.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10390
+ existing.forEach((o) => {
10391
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10392
+ if (id && !map.has(id)) {
10393
+ map.set(id, o);
10394
+ }
10395
+ });
10396
+ merged[k] = Array.from(map.values());
10397
+ }
10398
+ }
10399
+ });
10400
+ return merged;
10401
+ });
10335
10402
  }
10336
10403
  }
10337
10404
  } catch (err) {
@@ -10559,7 +10626,7 @@ function useWhatsAppState(props) {
10559
10626
  }, []);
10560
10627
  const getRelationOptionsForCol = (0, import_react17.useCallback)(
10561
10628
  (colName, parentColName) => {
10562
- var _a2;
10629
+ var _a2, _b2, _c, _d;
10563
10630
  if (parentColName) {
10564
10631
  const subKey = `${parentColName}.${colName}`;
10565
10632
  if (relationOptions[subKey] && relationOptions[subKey].length > 0) {
@@ -10574,20 +10641,55 @@ function useWhatsAppState(props) {
10574
10641
  if (refId && relationOptions[refId] && relationOptions[refId].length > 0) {
10575
10642
  return relationOptions[refId];
10576
10643
  }
10644
+ const postSendCol = postSendActionTargetOptions.find(
10645
+ (c) => c.columnName === colName && (!parentColName || c.parentColumnName === parentColName) || c.id === colName
10646
+ );
10647
+ if (postSendCol) {
10648
+ if (postSendCol.id && relationOptions[postSendCol.id] && relationOptions[postSendCol.id].length > 0) {
10649
+ return relationOptions[postSendCol.id];
10650
+ }
10651
+ const postSendRefId = postSendCol.referencedTableId || ((_b2 = postSendCol.config) == null ? void 0 : _b2.referencedTableId);
10652
+ if (postSendRefId && relationOptions[postSendRefId] && relationOptions[postSendRefId].length > 0) {
10653
+ return relationOptions[postSendRefId];
10654
+ }
10655
+ }
10656
+ const mainCol = (tableColumns || []).find((c) => c.name === colName);
10657
+ const mainRefId = ((_c = mainCol == null ? void 0 : mainCol.config) == null ? void 0 : _c.referencedTableId) || (mainCol == null ? void 0 : mainCol.referencedTableId);
10658
+ if (mainRefId && relationOptions[mainRefId] && relationOptions[mainRefId].length > 0) {
10659
+ return relationOptions[mainRefId];
10660
+ }
10661
+ const filterCol = filterableColumns.find((c) => c.name === colName);
10662
+ const filterRefId = ((_d = filterCol == null ? void 0 : filterCol.config) == null ? void 0 : _d.referencedTableId) || (filterCol == null ? void 0 : filterCol.referencedTableId);
10663
+ if (filterRefId && relationOptions[filterRefId] && relationOptions[filterRefId].length > 0) {
10664
+ return relationOptions[filterRefId];
10665
+ }
10577
10666
  return [];
10578
10667
  },
10579
- [relationOptions, subtableFilterableColumns]
10668
+ [relationOptions, subtableFilterableColumns, postSendActionTargetOptions, tableColumns, filterableColumns]
10580
10669
  );
10581
10670
  (0, import_react17.useEffect)(() => {
10582
- var _a2, _b2, _c;
10671
+ var _a2, _b2, _c, _d, _e;
10583
10672
  if (!executeAction) return;
10584
10673
  const targets = [];
10674
+ (tableColumns || []).forEach((col) => {
10675
+ var _a3, _b3, _c2;
10676
+ if (((_a3 = col.type) == null ? void 0 : _a3.toUpperCase()) === "RELATION") {
10677
+ const refId = ((_b3 = col.config) == null ? void 0 : _b3.referencedTableId) || col.referencedTableId;
10678
+ const displayField = ((_c2 = col.config) == null ? void 0 : _c2.displayField) || col.displayField;
10679
+ if (refId) {
10680
+ targets.push({ key: col.name, refId, displayField, colName: col.name, extraKey: col.id });
10681
+ targets.push({ key: refId, refId, displayField, colName: col.name, extraKey: col.id });
10682
+ }
10683
+ }
10684
+ });
10585
10685
  filterableColumns.forEach((col) => {
10586
10686
  var _a3, _b3, _c2;
10587
10687
  if (((_a3 = col.type) == null ? void 0 : _a3.toUpperCase()) === "RELATION") {
10588
10688
  const refId = ((_b3 = col.config) == null ? void 0 : _b3.referencedTableId) || col.referencedTableId;
10589
10689
  const displayField = ((_c2 = col.config) == null ? void 0 : _c2.displayField) || col.displayField;
10590
- if (refId) targets.push({ key: col.name, refId, displayField });
10690
+ if (refId) {
10691
+ targets.push({ key: col.name, refId, displayField, colName: col.name, extraKey: col.id });
10692
+ }
10591
10693
  }
10592
10694
  });
10593
10695
  if ((selectedPhoneOption == null ? void 0 : selectedPhoneOption.type) === "SUBTABLE") {
@@ -10603,35 +10705,64 @@ function useWhatsAppState(props) {
10603
10705
  const refId = ((_b3 = subCol.config) == null ? void 0 : _b3.referencedTableId) || subCol.referencedTableId;
10604
10706
  const displayField = ((_c2 = subCol.config) == null ? void 0 : _c2.displayField) || subCol.displayField;
10605
10707
  if (refId) {
10606
- targets.push({ key: `${parentColName}.${subCol.name}`, refId, displayField });
10607
- targets.push({ key: subCol.name, refId, displayField });
10608
- targets.push({ key: refId, refId, displayField });
10708
+ targets.push({ key: `${parentColName}.${subCol.name}`, refId, displayField, colName: subCol.name });
10709
+ targets.push({ key: subCol.name, refId, displayField, colName: subCol.name });
10710
+ targets.push({ key: refId, refId, displayField, colName: subCol.name });
10609
10711
  }
10610
10712
  }
10611
10713
  });
10612
10714
  }
10715
+ if (selectedPostSendOption && selectedPostSendOption.type === "RELATION") {
10716
+ const postSendRefId = selectedPostSendOption.referencedTableId || ((_d = selectedPostSendOption.config) == null ? void 0 : _d.referencedTableId);
10717
+ const postSendDisplayField = ((_e = selectedPostSendOption.config) == null ? void 0 : _e.displayField) || (selectedPostSendOption == null ? void 0 : selectedPostSendOption.displayField);
10718
+ if (postSendRefId) {
10719
+ const parentCol = selectedPostSendOption.parentColumnName;
10720
+ if (parentCol) {
10721
+ targets.push({ key: `${parentCol}.${selectedPostSendOption.columnName}`, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName, extraKey: selectedPostSendOption.id });
10722
+ }
10723
+ targets.push({ key: selectedPostSendOption.columnName, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName, extraKey: selectedPostSendOption.id });
10724
+ targets.push({ key: postSendRefId, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName });
10725
+ }
10726
+ }
10613
10727
  targets.forEach(async (target) => {
10614
- if (relationOptions[target.key] && relationOptions[target.key].length > 0) return;
10728
+ if (fullyFetchedRelationKeysRef.current.has(target.key)) return;
10615
10729
  try {
10616
- const result = await executeAction("FETCH_RELATION", {
10730
+ const result = await executeAction("FETCH_RELATION", __spreadValues({
10617
10731
  referencedTableId: target.refId,
10618
10732
  displayField: target.displayField,
10619
- take: 1e3
10620
- });
10733
+ take: 1e3,
10734
+ limit: 1e3,
10735
+ isFilter: false,
10736
+ bypassScoping: true,
10737
+ allOptions: true
10738
+ }, orgId ? { orgId, organizationId: orgId } : {}));
10621
10739
  const list = Array.isArray(result) ? result : (result == null ? void 0 : result.data) && Array.isArray(result.data) ? result.data : [];
10622
10740
  if (list.length > 0) {
10623
- setRelationOptions((prev) => __spreadProps(__spreadValues({}, prev), {
10624
- [target.key]: list,
10625
- [target.refId]: list
10626
- }));
10741
+ fullyFetchedRelationKeysRef.current.add(target.key);
10742
+ fullyFetchedRelationKeysRef.current.add(target.refId);
10743
+ if (target.colName) fullyFetchedRelationKeysRef.current.add(target.colName);
10744
+ if (target.extraKey) fullyFetchedRelationKeysRef.current.add(target.extraKey);
10745
+ setRelationOptions((prev) => {
10746
+ const existing = prev[target.key] || [];
10747
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10748
+ list.forEach((o) => {
10749
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10750
+ if (id) existingMap.set(id, o);
10751
+ });
10752
+ const mergedList = Array.from(existingMap.values());
10753
+ return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, prev), {
10754
+ [target.key]: mergedList,
10755
+ [target.refId]: mergedList
10756
+ }), target.colName ? { [target.colName]: mergedList } : {}), target.extraKey ? { [target.extraKey]: mergedList } : {});
10757
+ });
10627
10758
  }
10628
10759
  } catch (err) {
10629
10760
  console.warn(`[useWhatsAppState] Failed to fetch relation options for ${target.key}:`, err);
10630
10761
  }
10631
10762
  });
10632
- }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns, executeAction, relationOptions]);
10763
+ }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns, executeAction, selectedPostSendOption, orgId]);
10633
10764
  (0, import_react17.useEffect)(() => {
10634
- var _a2, _b2, _c, _d, _e, _f;
10765
+ var _a2, _b2, _c;
10635
10766
  if (!executeAction || !selectedSubtableFilterCol) return;
10636
10767
  if (((_a2 = selectedSubtableFilterCol.type) == null ? void 0 : _a2.toUpperCase()) !== "RELATION") return;
10637
10768
  const refId = ((_b2 = selectedSubtableFilterCol.config) == null ? void 0 : _b2.referencedTableId) || selectedSubtableFilterCol.referencedTableId;
@@ -10639,24 +10770,39 @@ function useWhatsAppState(props) {
10639
10770
  const parentColName = (selectedPhoneOption == null ? void 0 : selectedPhoneOption.parentColumnName) || "";
10640
10771
  const keyWithParent = parentColName ? `${parentColName}.${selectedSubtableFilterCol.name}` : "";
10641
10772
  const keyDirect = selectedSubtableFilterCol.name;
10642
- if (keyWithParent && ((_c = relationOptions[keyWithParent]) == null ? void 0 : _c.length) > 0 || ((_d = relationOptions[keyDirect]) == null ? void 0 : _d.length) > 0 || ((_e = relationOptions[refId]) == null ? void 0 : _e.length) > 0) {
10773
+ if (keyWithParent && fullyFetchedRelationKeysRef.current.has(keyWithParent) || fullyFetchedRelationKeysRef.current.has(keyDirect) || fullyFetchedRelationKeysRef.current.has(refId)) {
10643
10774
  return;
10644
10775
  }
10645
- const displayField = ((_f = selectedSubtableFilterCol.config) == null ? void 0 : _f.displayField) || selectedSubtableFilterCol.displayField;
10776
+ const displayField = ((_c = selectedSubtableFilterCol.config) == null ? void 0 : _c.displayField) || selectedSubtableFilterCol.displayField;
10646
10777
  (async () => {
10647
10778
  try {
10648
10779
  const res = await executeAction("FETCH_RELATION", __spreadValues({
10649
10780
  referencedTableId: refId,
10650
10781
  displayField,
10651
10782
  take: 1e3,
10652
- limit: 1e3
10783
+ limit: 1e3,
10784
+ isFilter: false,
10785
+ bypassScoping: true,
10786
+ allOptions: true
10653
10787
  }, orgId ? { orgId, organizationId: orgId } : {}));
10654
10788
  const list = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : [];
10655
10789
  if (list.length > 0) {
10656
- setRelationOptions((prev) => __spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: list } : {}), {
10657
- [keyDirect]: list,
10658
- [refId]: list
10659
- }));
10790
+ if (keyWithParent) fullyFetchedRelationKeysRef.current.add(keyWithParent);
10791
+ fullyFetchedRelationKeysRef.current.add(keyDirect);
10792
+ fullyFetchedRelationKeysRef.current.add(refId);
10793
+ setRelationOptions((prev) => {
10794
+ const existing = prev[keyDirect] || [];
10795
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10796
+ list.forEach((o) => {
10797
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10798
+ if (id) existingMap.set(id, o);
10799
+ });
10800
+ const mergedList = Array.from(existingMap.values());
10801
+ return __spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: mergedList } : {}), {
10802
+ [keyDirect]: mergedList,
10803
+ [refId]: mergedList
10804
+ });
10805
+ });
10660
10806
  }
10661
10807
  } catch (err) {
10662
10808
  console.warn(
@@ -10665,7 +10811,60 @@ function useWhatsAppState(props) {
10665
10811
  );
10666
10812
  }
10667
10813
  })();
10668
- }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, relationOptions, orgId]);
10814
+ }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, orgId]);
10815
+ (0, import_react17.useEffect)(() => {
10816
+ var _a2, _b2;
10817
+ if (!executeAction || !selectedPostSendOption) return;
10818
+ if (selectedPostSendOption.type !== "RELATION") return;
10819
+ const refId = selectedPostSendOption.referencedTableId || ((_a2 = selectedPostSendOption.config) == null ? void 0 : _a2.referencedTableId);
10820
+ if (!refId) return;
10821
+ const parentColName = selectedPostSendOption.parentColumnName || "";
10822
+ const keyWithParent = parentColName ? `${parentColName}.${selectedPostSendOption.columnName}` : "";
10823
+ const keyDirect = selectedPostSendOption.columnName;
10824
+ const optionId = selectedPostSendOption.id;
10825
+ if (keyWithParent && fullyFetchedRelationKeysRef.current.has(keyWithParent) || fullyFetchedRelationKeysRef.current.has(keyDirect) || fullyFetchedRelationKeysRef.current.has(refId) || optionId && fullyFetchedRelationKeysRef.current.has(optionId)) {
10826
+ return;
10827
+ }
10828
+ const displayField = ((_b2 = selectedPostSendOption.config) == null ? void 0 : _b2.displayField) || (selectedPostSendOption == null ? void 0 : selectedPostSendOption.displayField);
10829
+ (async () => {
10830
+ try {
10831
+ const res = await executeAction("FETCH_RELATION", __spreadValues({
10832
+ referencedTableId: refId,
10833
+ displayField,
10834
+ take: 1e3,
10835
+ limit: 1e3,
10836
+ isFilter: false,
10837
+ bypassScoping: true,
10838
+ allOptions: true
10839
+ }, orgId ? { orgId, organizationId: orgId } : {}));
10840
+ const list = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : [];
10841
+ if (list.length > 0) {
10842
+ if (keyWithParent) fullyFetchedRelationKeysRef.current.add(keyWithParent);
10843
+ fullyFetchedRelationKeysRef.current.add(keyDirect);
10844
+ fullyFetchedRelationKeysRef.current.add(refId);
10845
+ if (optionId) fullyFetchedRelationKeysRef.current.add(optionId);
10846
+ setRelationOptions((prev) => {
10847
+ const existing = prev[keyDirect] || [];
10848
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10849
+ list.forEach((o) => {
10850
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10851
+ if (id) existingMap.set(id, o);
10852
+ });
10853
+ const mergedList = Array.from(existingMap.values());
10854
+ return __spreadValues(__spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: mergedList } : {}), {
10855
+ [keyDirect]: mergedList,
10856
+ [refId]: mergedList
10857
+ }), optionId ? { [optionId]: mergedList } : {});
10858
+ });
10859
+ }
10860
+ } catch (err) {
10861
+ console.warn(
10862
+ `[useWhatsAppState] Failed to fetch relation options for post-send column ${selectedPostSendOption.columnName}:`,
10863
+ err
10864
+ );
10865
+ }
10866
+ })();
10867
+ }, [selectedPostSendOption, executeAction, orgId]);
10669
10868
  const filteredRecords = (0, import_react17.useMemo)(() => {
10670
10869
  const activeEntries = Object.entries(filters).filter(
10671
10870
  ([_, val]) => val !== void 0 && val !== null && val !== ""
@@ -10697,6 +10896,25 @@ function useWhatsAppState(props) {
10697
10896
  return true;
10698
10897
  });
10699
10898
  }, [rawRecords, filters, filterableColumns]);
10899
+ const filteredData = filteredRecords;
10900
+ (0, import_react17.useEffect)(() => {
10901
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10902
+ isAutoSelectingRef.current = true;
10903
+ const sliced = filteredData.slice(0, autoSelectCount);
10904
+ const slicedIds = sliced.map((r) => r.id);
10905
+ setSelectedRowIds(slicedIds);
10906
+ const timer = setTimeout(() => {
10907
+ isAutoSelectingRef.current = false;
10908
+ }, 0);
10909
+ return () => clearTimeout(timer);
10910
+ } else if (autoSelectCount === 0 || autoSelectCount === null) {
10911
+ if (!isManualOverrideRef.current && prevAutoSelectCountRef.current !== null) {
10912
+ setSelectedRowIds([]);
10913
+ }
10914
+ }
10915
+ isManualOverrideRef.current = false;
10916
+ prevAutoSelectCountRef.current = autoSelectCount;
10917
+ }, [autoSelectCount, filteredData]);
10700
10918
  const embeddedTableExecuteAction = (0, import_react17.useCallback)(async (actionType, payload) => {
10701
10919
  if (actionType === "FETCH_TABLE_DATA") {
10702
10920
  const colFilters = (payload == null ? void 0 : payload.columnFilters) || (payload == null ? void 0 : payload.filters);
@@ -10718,6 +10936,15 @@ function useWhatsAppState(props) {
10718
10936
  relationOptions
10719
10937
  };
10720
10938
  }
10939
+ if (actionType === "FETCH_RELATION") {
10940
+ if (executeAction) {
10941
+ return executeAction("FETCH_RELATION", __spreadProps(__spreadValues({}, payload), {
10942
+ isFilter: false,
10943
+ bypassScoping: true,
10944
+ allOptions: true
10945
+ }));
10946
+ }
10947
+ }
10721
10948
  if (executeAction) {
10722
10949
  return executeAction(actionType, payload);
10723
10950
  }
@@ -10739,11 +10966,37 @@ function useWhatsAppState(props) {
10739
10966
  if (prev.length === selectedIds.length && prev.every((id, idx) => id === selectedIds[idx])) {
10740
10967
  return prev;
10741
10968
  }
10969
+ if (!isAutoSelectingRef.current && autoSelectCount !== null && autoSelectCount > 0) {
10970
+ isManualOverrideRef.current = true;
10971
+ setAutoSelectCount(null);
10972
+ }
10742
10973
  setBroadcastSummary(null);
10743
10974
  setRowStatusMap({});
10744
10975
  return selectedIds;
10745
10976
  });
10746
- }, []);
10977
+ }, [autoSelectCount]);
10978
+ const handleRowToggle = (0, import_react17.useCallback)((rowId, checked) => {
10979
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10980
+ isManualOverrideRef.current = true;
10981
+ setAutoSelectCount(null);
10982
+ }
10983
+ }, [autoSelectCount]);
10984
+ const toggleRowSelection = (0, import_react17.useCallback)((rowId, checked) => {
10985
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10986
+ isManualOverrideRef.current = true;
10987
+ setAutoSelectCount(null);
10988
+ }
10989
+ setSelectedRowIds((prev) => {
10990
+ const isSelected = prev.includes(rowId);
10991
+ const nextChecked = checked !== void 0 ? checked : !isSelected;
10992
+ if (nextChecked && !isSelected) {
10993
+ return [...prev, rowId];
10994
+ } else if (!nextChecked && isSelected) {
10995
+ return prev.filter((id) => id !== rowId);
10996
+ }
10997
+ return prev;
10998
+ });
10999
+ }, [autoSelectCount]);
10747
11000
  const [templates, setTemplates] = (0, import_react17.useState)([]);
10748
11001
  const [selectedTemplateId, setSelectedTemplateId] = (0, import_react17.useState)(null);
10749
11002
  const [isLoading, setIsLoading] = (0, import_react17.useState)(true);
@@ -11301,6 +11554,11 @@ function useWhatsAppState(props) {
11301
11554
  // Selection
11302
11555
  selectedRowIds,
11303
11556
  handleSelectionChange,
11557
+ handleRowToggle,
11558
+ toggleRowSelection,
11559
+ autoSelectCount,
11560
+ setAutoSelectCount,
11561
+ filteredData,
11304
11562
  // Phone & Subtable settings
11305
11563
  targetPhoneOptions,
11306
11564
  phoneColumns,
@@ -11720,6 +11978,7 @@ function DynamicFiltersBlock({
11720
11978
  handleClearFilters,
11721
11979
  activeFiltersCount,
11722
11980
  relationOptions,
11981
+ getRelationOptionsForCol,
11723
11982
  selectedRowIds,
11724
11983
  filteredRecordsCount,
11725
11984
  rawRecordsCount,
@@ -11751,12 +12010,13 @@ function DynamicFiltersBlock({
11751
12010
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: "\u05D0\u05D9\u05DF \u05E9\u05D3\u05D5\u05EA \u05DC\u05E1\u05D9\u05E0\u05D5\u05DF \u05D1\u05D8\u05D1\u05DC\u05D4 \u05D6\u05D5" }),
11752
12011
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { className: "text-[10px] text-slate-400", children: "\u05E9\u05D3\u05D5\u05EA \u05DE\u05E1\u05D5\u05D2 \u05E7\u05E9\u05E8 \u05D5\u05D1\u05D5\u05DC\u05D9\u05D0\u05E0\u05D9 \u05D1\u05DC\u05D1\u05D3" })
11753
12012
  ] }) : /* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-1 gap-2", children: filterableColumns.map((col) => {
11754
- var _a;
12013
+ var _a, _b, _c;
11755
12014
  const colType = (_a = col.type) == null ? void 0 : _a.toUpperCase();
11756
12015
  const isBoolean = colType === "BOOLEAN";
11757
12016
  const currentValue = filters[col.name] || "";
11758
12017
  const isActive = Boolean(currentValue);
11759
- const options = relationOptions[col.name] || [];
12018
+ const refTableId = ((_b = col == null ? void 0 : col.config) == null ? void 0 : _b.referencedTableId) || (col == null ? void 0 : col.referencedTableId);
12019
+ const options = ((_c = getRelationOptionsForCol ? getRelationOptionsForCol(col.name) : []) == null ? void 0 : _c.length) > 0 ? getRelationOptionsForCol(col.name) : relationOptions[col.name] && relationOptions[col.name].length > 0 ? relationOptions[col.name] : refTableId && relationOptions[refTableId] && relationOptions[refTableId].length > 0 ? relationOptions[refTableId] : col.id && relationOptions[col.id] && relationOptions[col.id].length > 0 ? relationOptions[col.id] : [];
11760
12020
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "space-y-1", children: [
11761
12021
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex items-center justify-between", children: [
11762
12022
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
@@ -11838,6 +12098,8 @@ function SettingsAndActionsBlock({
11838
12098
  phoneColumnId,
11839
12099
  setPhoneColumnId,
11840
12100
  selectedPhoneOption,
12101
+ autoSelectCount = null,
12102
+ setAutoSelectCount,
11841
12103
  subtableFilterColumn,
11842
12104
  setSubtableFilterColumn,
11843
12105
  subtableFilterValue,
@@ -11927,6 +12189,72 @@ function SettingsAndActionsBlock({
11927
12189
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.ChevronDown, { className: "w-3 h-3 text-slate-400 absolute left-2 top-1/2 -translate-y-1/2 pointer-events-none" })
11928
12190
  ] })
11929
12191
  ] }),
12192
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "space-y-1", children: [
12193
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center justify-between", children: [
12194
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
12195
+ "label",
12196
+ {
12197
+ htmlFor: "whatsapp-auto-select-records",
12198
+ className: "text-[11px] font-semibold text-slate-700 flex items-center gap-1 cursor-pointer",
12199
+ children: [
12200
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.CheckSquare, { className: "w-3 h-3 text-slate-400" }),
12201
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: "\u05D1\u05D7\u05E8 \u05E8\u05E9\u05D5\u05DE\u05D4 (\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA)" })
12202
+ ]
12203
+ }
12204
+ ),
12205
+ autoSelectCount !== null && autoSelectCount > 0 && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center gap-1.5 animate-in fade-in duration-150", children: [
12206
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { className: "text-[9px] font-semibold text-emerald-700 bg-emerald-50 border border-emerald-200/80 px-1.5 py-0.5 rounded-full flex items-center gap-1", children: [
12207
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" }),
12208
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { children: [
12209
+ "\u05E0\u05D1\u05D7\u05E8\u05D5 ",
12210
+ selectedRowIdsCount,
12211
+ " \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA"
12212
+ ] })
12213
+ ] }),
12214
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
12215
+ "button",
12216
+ {
12217
+ type: "button",
12218
+ onClick: () => setAutoSelectCount == null ? void 0 : setAutoSelectCount(null),
12219
+ className: "text-[10px] text-slate-400 hover:text-rose-600 flex items-center gap-0.5 font-medium hover:underline cursor-pointer transition-colors p-0.5 rounded",
12220
+ title: "\u05E0\u05E7\u05D4 \u05D1\u05D7\u05D9\u05E8\u05D4 \u05D0\u05D5\u05D8\u05D5\u05DE\u05D8\u05D9\u05EA",
12221
+ "aria-label": "Clear auto select count",
12222
+ children: [
12223
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.X, { className: "w-3 h-3" }),
12224
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: "\u05E0\u05E7\u05D4" })
12225
+ ]
12226
+ }
12227
+ )
12228
+ ] })
12229
+ ] }),
12230
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "relative", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
12231
+ "input",
12232
+ {
12233
+ id: "whatsapp-auto-select-records",
12234
+ name: "autoSelectCount",
12235
+ type: "number",
12236
+ min: "0",
12237
+ placeholder: "\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA",
12238
+ "aria-label": "\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA",
12239
+ "data-testid": "auto-select-records-input",
12240
+ value: autoSelectCount === null || autoSelectCount === void 0 ? "" : autoSelectCount,
12241
+ onChange: (e) => {
12242
+ const val = e.target.value.trim();
12243
+ if (val === "") {
12244
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(null);
12245
+ } else {
12246
+ const num = parseInt(val, 10);
12247
+ if (isNaN(num) || num < 0) {
12248
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(null);
12249
+ } else {
12250
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(num);
12251
+ }
12252
+ }
12253
+ },
12254
+ className: "w-full h-8 px-2.5 text-[11px] rounded-lg border border-slate-200 bg-white text-slate-700 placeholder:text-slate-400 focus:border-emerald-500 focus:ring-1 focus:ring-emerald-500 transition-all font-medium"
12255
+ }
12256
+ ) })
12257
+ ] }),
11930
12258
  (selectedPhoneOption == null ? void 0 : selectedPhoneOption.type) === "SUBTABLE" && /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "p-2.5 bg-emerald-50/60 border border-emerald-200/80 rounded-xl space-y-2 animate-in fade-in duration-150", children: [
11931
12259
  /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center gap-1.5 pb-1 border-b border-emerald-200/60", children: [
11932
12260
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.Users, { className: "w-3.5 h-3.5 text-emerald-700" }),
@@ -12331,6 +12659,7 @@ function WhatsAppComponent(props) {
12331
12659
  handleClearFilters: state.handleClearFilters,
12332
12660
  activeFiltersCount: state.activeFiltersCount,
12333
12661
  relationOptions: state.relationOptions,
12662
+ getRelationOptionsForCol: state.getRelationOptionsForCol,
12334
12663
  selectedRowIds: state.selectedRowIds,
12335
12664
  filteredRecordsCount: state.filteredRecords.length,
12336
12665
  rawRecordsCount: state.rawRecords.length,
@@ -12346,6 +12675,8 @@ function WhatsAppComponent(props) {
12346
12675
  phoneColumnId: state.phoneColumnId,
12347
12676
  setPhoneColumnId: state.setPhoneColumnId,
12348
12677
  selectedPhoneOption: state.selectedPhoneOption,
12678
+ autoSelectCount: state.autoSelectCount,
12679
+ setAutoSelectCount: state.setAutoSelectCount,
12349
12680
  subtableFilterColumn: state.subtableFilterColumn,
12350
12681
  setSubtableFilterColumn: state.setSubtableFilterColumn,
12351
12682
  subtableFilterValue: state.subtableFilterValue,
@@ -12399,7 +12730,9 @@ function WhatsAppComponent(props) {
12399
12730
  },
12400
12731
  data: state.filteredRecords,
12401
12732
  readOnly: true,
12733
+ selectedRowIds: state.selectedRowIds,
12402
12734
  onSelectionChange: state.handleSelectionChange,
12735
+ onRowToggle: state.handleRowToggle,
12403
12736
  executeAction: state.embeddedTableExecuteAction,
12404
12737
  orgId,
12405
12738
  componentId: `${componentId || "whatsapp"}-embedded-table`,
@@ -12596,13 +12929,16 @@ var UNIVERSE_COMPONENTS = {
12596
12929
  ColumnHeaderTitle,
12597
12930
  CreateTemplateModal,
12598
12931
  DatePickerCell,
12932
+ DynamicFiltersBlock,
12599
12933
  LinkPickerCell,
12600
12934
  PASTEL_PALETTES,
12601
12935
  RelationFilterPopover,
12602
12936
  RelationPickerCell,
12937
+ SettingsAndActionsBlock,
12603
12938
  SmartTextCell,
12604
12939
  TEXT_REPRESENTABLE_TYPES,
12605
12940
  TableBlock,
12941
+ TableBlockClient,
12606
12942
  TimePickerCell,
12607
12943
  ToastContext,
12608
12944
  ToastProvider,
@@ -12653,6 +12989,7 @@ var UNIVERSE_COMPONENTS = {
12653
12989
  useColumnResize,
12654
12990
  useSmartTooltip,
12655
12991
  useToast,
12992
+ useWhatsAppState,
12656
12993
  validateSequentialVariables,
12657
12994
  validateTemplateBody,
12658
12995
  validateTemplateButtons,