@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.mjs CHANGED
@@ -5591,7 +5591,9 @@ function TableBlockClient({
5591
5591
  role,
5592
5592
  permissions,
5593
5593
  readOnly,
5594
+ selectedRowIds,
5594
5595
  onSelectionChange,
5596
+ onRowToggle,
5595
5597
  rowStatusMap,
5596
5598
  editModelUrl
5597
5599
  }) {
@@ -6035,12 +6037,29 @@ function TableBlockClient({
6035
6037
  setPage((prev) => Math.min(totalPages, prev + 1));
6036
6038
  };
6037
6039
  const [selectedIds, setSelectedIds] = useState13(/* @__PURE__ */ new Set());
6040
+ const isExternalSyncRef = useRef10(false);
6041
+ useEffect11(() => {
6042
+ if (selectedRowIds !== void 0) {
6043
+ const nextSet = new Set(selectedRowIds);
6044
+ setSelectedIds((prev) => {
6045
+ if (prev.size === nextSet.size && Array.from(prev).every((id) => nextSet.has(id))) {
6046
+ return prev;
6047
+ }
6048
+ isExternalSyncRef.current = true;
6049
+ return nextSet;
6050
+ });
6051
+ }
6052
+ }, [selectedRowIds]);
6038
6053
  const isFirstSelectionChangeRef = useRef10(true);
6039
6054
  useEffect11(() => {
6040
6055
  if (isFirstSelectionChangeRef.current) {
6041
6056
  isFirstSelectionChangeRef.current = false;
6042
6057
  if (selectedIds.size === 0) return;
6043
6058
  }
6059
+ if (isExternalSyncRef.current) {
6060
+ isExternalSyncRef.current = false;
6061
+ return;
6062
+ }
6044
6063
  onSelectionChange == null ? void 0 : onSelectionChange(Array.from(selectedIds));
6045
6064
  }, [selectedIds, onSelectionChange]);
6046
6065
  const [pendingDeletions, setPendingDeletions] = useState13([]);
@@ -6489,17 +6508,19 @@ function TableBlockClient({
6489
6508
  }
6490
6509
  }, []);
6491
6510
  const toggleSelectAll = useCallback11((checked) => {
6511
+ onRowToggle == null ? void 0 : onRowToggle("ALL", checked);
6492
6512
  const next = checked ? new Set(filteredData.map((r) => r.id)) : /* @__PURE__ */ new Set();
6493
6513
  setSelectedIds(next);
6494
- }, [filteredData]);
6514
+ }, [filteredData, onRowToggle]);
6495
6515
  const toggleSelectRow = useCallback11((rowId, checked) => {
6516
+ onRowToggle == null ? void 0 : onRowToggle(rowId, checked);
6496
6517
  setSelectedIds((prev) => {
6497
6518
  const next = new Set(prev);
6498
6519
  if (checked) next.add(rowId);
6499
6520
  else next.delete(rowId);
6500
6521
  return next;
6501
6522
  });
6502
- }, []);
6523
+ }, [onRowToggle]);
6503
6524
  const handleToggleExpand = useCallback11((rowId) => {
6504
6525
  setExpandedRowIds((prev) => {
6505
6526
  const next = new Set(prev);
@@ -9897,6 +9918,10 @@ function buildWhatsAppPayload(to, templateName, languageCode, components) {
9897
9918
  }
9898
9919
  async function sendWhatsAppMessage(payload, executeAction, orgId) {
9899
9920
  try {
9921
+ console.log(
9922
+ "[whatsappApi] Dispatching WhatsApp message action with payload:",
9923
+ JSON.stringify(payload, null, 2)
9924
+ );
9900
9925
  const actionPayload = {
9901
9926
  payload
9902
9927
  };
@@ -9906,12 +9931,18 @@ async function sendWhatsAppMessage(payload, executeAction, orgId) {
9906
9931
  }
9907
9932
  const result = await executeAction("SEND_WHATSAPP_MESSAGE", actionPayload);
9908
9933
  if (result && result.success === false) {
9934
+ console.error(
9935
+ "[whatsappApi] SEND_WHATSAPP_MESSAGE dispatch failed:",
9936
+ result.error,
9937
+ result.details || result
9938
+ );
9909
9939
  return {
9910
9940
  success: false,
9911
9941
  error: result.error || "\u05E9\u05DC\u05D9\u05D7\u05EA \u05D4\u05D5\u05D3\u05E2\u05EA WhatsApp \u05E0\u05DB\u05E9\u05DC\u05D4",
9912
9942
  data: result
9913
9943
  };
9914
9944
  }
9945
+ console.log("[whatsappApi] SEND_WHATSAPP_MESSAGE dispatch succeeded:", result);
9915
9946
  return {
9916
9947
  success: true,
9917
9948
  data: result
@@ -10228,7 +10259,12 @@ function useWhatsAppState(props) {
10228
10259
  const [tableError, setTableError] = useState15(null);
10229
10260
  const [filters, setFilters] = useState15({});
10230
10261
  const [selectedRowIds, setSelectedRowIds] = useState15([]);
10262
+ const [autoSelectCount, setAutoSelectCount] = useState15(null);
10263
+ const isAutoSelectingRef = useRef12(false);
10264
+ const isManualOverrideRef = useRef12(false);
10265
+ const prevAutoSelectCountRef = useRef12(null);
10231
10266
  const fetchedTableIdsRef = useRef12(/* @__PURE__ */ new Set());
10267
+ const fullyFetchedRelationKeysRef = useRef12(/* @__PURE__ */ new Set());
10232
10268
  const loadTableData = useCallback12(async () => {
10233
10269
  var _a2;
10234
10270
  const tableId = (settings == null ? void 0 : settings.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableId);
@@ -10253,7 +10289,34 @@ function useWhatsAppState(props) {
10253
10289
  setRawRecords(res.records);
10254
10290
  }
10255
10291
  if (res.relationOptions && typeof res.relationOptions === "object") {
10256
- setRelationOptions((prev) => __spreadValues(__spreadValues({}, prev), res.relationOptions));
10292
+ setRelationOptions((prev) => {
10293
+ const merged = __spreadValues({}, prev);
10294
+ Object.entries(res.relationOptions).forEach(([k, opts]) => {
10295
+ if (Array.isArray(opts)) {
10296
+ const existing = prev[k] || [];
10297
+ if (existing.length >= opts.length && existing.length > 0) {
10298
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10299
+ opts.forEach((o) => {
10300
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10301
+ if (id && !existingMap.has(id)) {
10302
+ existingMap.set(id, o);
10303
+ }
10304
+ });
10305
+ merged[k] = Array.from(existingMap.values());
10306
+ } else {
10307
+ const map = new Map(opts.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10308
+ existing.forEach((o) => {
10309
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10310
+ if (id && !map.has(id)) {
10311
+ map.set(id, o);
10312
+ }
10313
+ });
10314
+ merged[k] = Array.from(map.values());
10315
+ }
10316
+ }
10317
+ });
10318
+ return merged;
10319
+ });
10257
10320
  }
10258
10321
  }
10259
10322
  } catch (err) {
@@ -10481,7 +10544,7 @@ function useWhatsAppState(props) {
10481
10544
  }, []);
10482
10545
  const getRelationOptionsForCol = useCallback12(
10483
10546
  (colName, parentColName) => {
10484
- var _a2;
10547
+ var _a2, _b2, _c, _d;
10485
10548
  if (parentColName) {
10486
10549
  const subKey = `${parentColName}.${colName}`;
10487
10550
  if (relationOptions[subKey] && relationOptions[subKey].length > 0) {
@@ -10496,20 +10559,55 @@ function useWhatsAppState(props) {
10496
10559
  if (refId && relationOptions[refId] && relationOptions[refId].length > 0) {
10497
10560
  return relationOptions[refId];
10498
10561
  }
10562
+ const postSendCol = postSendActionTargetOptions.find(
10563
+ (c) => c.columnName === colName && (!parentColName || c.parentColumnName === parentColName) || c.id === colName
10564
+ );
10565
+ if (postSendCol) {
10566
+ if (postSendCol.id && relationOptions[postSendCol.id] && relationOptions[postSendCol.id].length > 0) {
10567
+ return relationOptions[postSendCol.id];
10568
+ }
10569
+ const postSendRefId = postSendCol.referencedTableId || ((_b2 = postSendCol.config) == null ? void 0 : _b2.referencedTableId);
10570
+ if (postSendRefId && relationOptions[postSendRefId] && relationOptions[postSendRefId].length > 0) {
10571
+ return relationOptions[postSendRefId];
10572
+ }
10573
+ }
10574
+ const mainCol = (tableColumns || []).find((c) => c.name === colName);
10575
+ const mainRefId = ((_c = mainCol == null ? void 0 : mainCol.config) == null ? void 0 : _c.referencedTableId) || (mainCol == null ? void 0 : mainCol.referencedTableId);
10576
+ if (mainRefId && relationOptions[mainRefId] && relationOptions[mainRefId].length > 0) {
10577
+ return relationOptions[mainRefId];
10578
+ }
10579
+ const filterCol = filterableColumns.find((c) => c.name === colName);
10580
+ const filterRefId = ((_d = filterCol == null ? void 0 : filterCol.config) == null ? void 0 : _d.referencedTableId) || (filterCol == null ? void 0 : filterCol.referencedTableId);
10581
+ if (filterRefId && relationOptions[filterRefId] && relationOptions[filterRefId].length > 0) {
10582
+ return relationOptions[filterRefId];
10583
+ }
10499
10584
  return [];
10500
10585
  },
10501
- [relationOptions, subtableFilterableColumns]
10586
+ [relationOptions, subtableFilterableColumns, postSendActionTargetOptions, tableColumns, filterableColumns]
10502
10587
  );
10503
10588
  useEffect13(() => {
10504
- var _a2, _b2, _c;
10589
+ var _a2, _b2, _c, _d, _e;
10505
10590
  if (!executeAction) return;
10506
10591
  const targets = [];
10592
+ (tableColumns || []).forEach((col) => {
10593
+ var _a3, _b3, _c2;
10594
+ if (((_a3 = col.type) == null ? void 0 : _a3.toUpperCase()) === "RELATION") {
10595
+ const refId = ((_b3 = col.config) == null ? void 0 : _b3.referencedTableId) || col.referencedTableId;
10596
+ const displayField = ((_c2 = col.config) == null ? void 0 : _c2.displayField) || col.displayField;
10597
+ if (refId) {
10598
+ targets.push({ key: col.name, refId, displayField, colName: col.name, extraKey: col.id });
10599
+ targets.push({ key: refId, refId, displayField, colName: col.name, extraKey: col.id });
10600
+ }
10601
+ }
10602
+ });
10507
10603
  filterableColumns.forEach((col) => {
10508
10604
  var _a3, _b3, _c2;
10509
10605
  if (((_a3 = col.type) == null ? void 0 : _a3.toUpperCase()) === "RELATION") {
10510
10606
  const refId = ((_b3 = col.config) == null ? void 0 : _b3.referencedTableId) || col.referencedTableId;
10511
10607
  const displayField = ((_c2 = col.config) == null ? void 0 : _c2.displayField) || col.displayField;
10512
- if (refId) targets.push({ key: col.name, refId, displayField });
10608
+ if (refId) {
10609
+ targets.push({ key: col.name, refId, displayField, colName: col.name, extraKey: col.id });
10610
+ }
10513
10611
  }
10514
10612
  });
10515
10613
  if ((selectedPhoneOption == null ? void 0 : selectedPhoneOption.type) === "SUBTABLE") {
@@ -10525,35 +10623,64 @@ function useWhatsAppState(props) {
10525
10623
  const refId = ((_b3 = subCol.config) == null ? void 0 : _b3.referencedTableId) || subCol.referencedTableId;
10526
10624
  const displayField = ((_c2 = subCol.config) == null ? void 0 : _c2.displayField) || subCol.displayField;
10527
10625
  if (refId) {
10528
- targets.push({ key: `${parentColName}.${subCol.name}`, refId, displayField });
10529
- targets.push({ key: subCol.name, refId, displayField });
10530
- targets.push({ key: refId, refId, displayField });
10626
+ targets.push({ key: `${parentColName}.${subCol.name}`, refId, displayField, colName: subCol.name });
10627
+ targets.push({ key: subCol.name, refId, displayField, colName: subCol.name });
10628
+ targets.push({ key: refId, refId, displayField, colName: subCol.name });
10531
10629
  }
10532
10630
  }
10533
10631
  });
10534
10632
  }
10633
+ if (selectedPostSendOption && selectedPostSendOption.type === "RELATION") {
10634
+ const postSendRefId = selectedPostSendOption.referencedTableId || ((_d = selectedPostSendOption.config) == null ? void 0 : _d.referencedTableId);
10635
+ const postSendDisplayField = ((_e = selectedPostSendOption.config) == null ? void 0 : _e.displayField) || (selectedPostSendOption == null ? void 0 : selectedPostSendOption.displayField);
10636
+ if (postSendRefId) {
10637
+ const parentCol = selectedPostSendOption.parentColumnName;
10638
+ if (parentCol) {
10639
+ targets.push({ key: `${parentCol}.${selectedPostSendOption.columnName}`, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName, extraKey: selectedPostSendOption.id });
10640
+ }
10641
+ targets.push({ key: selectedPostSendOption.columnName, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName, extraKey: selectedPostSendOption.id });
10642
+ targets.push({ key: postSendRefId, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName });
10643
+ }
10644
+ }
10535
10645
  targets.forEach(async (target) => {
10536
- if (relationOptions[target.key] && relationOptions[target.key].length > 0) return;
10646
+ if (fullyFetchedRelationKeysRef.current.has(target.key)) return;
10537
10647
  try {
10538
- const result = await executeAction("FETCH_RELATION", {
10648
+ const result = await executeAction("FETCH_RELATION", __spreadValues({
10539
10649
  referencedTableId: target.refId,
10540
10650
  displayField: target.displayField,
10541
- take: 1e3
10542
- });
10651
+ take: 1e3,
10652
+ limit: 1e3,
10653
+ isFilter: false,
10654
+ bypassScoping: true,
10655
+ allOptions: true
10656
+ }, orgId ? { orgId, organizationId: orgId } : {}));
10543
10657
  const list = Array.isArray(result) ? result : (result == null ? void 0 : result.data) && Array.isArray(result.data) ? result.data : [];
10544
10658
  if (list.length > 0) {
10545
- setRelationOptions((prev) => __spreadProps(__spreadValues({}, prev), {
10546
- [target.key]: list,
10547
- [target.refId]: list
10548
- }));
10659
+ fullyFetchedRelationKeysRef.current.add(target.key);
10660
+ fullyFetchedRelationKeysRef.current.add(target.refId);
10661
+ if (target.colName) fullyFetchedRelationKeysRef.current.add(target.colName);
10662
+ if (target.extraKey) fullyFetchedRelationKeysRef.current.add(target.extraKey);
10663
+ setRelationOptions((prev) => {
10664
+ const existing = prev[target.key] || [];
10665
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10666
+ list.forEach((o) => {
10667
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10668
+ if (id) existingMap.set(id, o);
10669
+ });
10670
+ const mergedList = Array.from(existingMap.values());
10671
+ return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, prev), {
10672
+ [target.key]: mergedList,
10673
+ [target.refId]: mergedList
10674
+ }), target.colName ? { [target.colName]: mergedList } : {}), target.extraKey ? { [target.extraKey]: mergedList } : {});
10675
+ });
10549
10676
  }
10550
10677
  } catch (err) {
10551
10678
  console.warn(`[useWhatsAppState] Failed to fetch relation options for ${target.key}:`, err);
10552
10679
  }
10553
10680
  });
10554
- }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns, executeAction, relationOptions]);
10681
+ }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns, executeAction, selectedPostSendOption, orgId]);
10555
10682
  useEffect13(() => {
10556
- var _a2, _b2, _c, _d, _e, _f;
10683
+ var _a2, _b2, _c;
10557
10684
  if (!executeAction || !selectedSubtableFilterCol) return;
10558
10685
  if (((_a2 = selectedSubtableFilterCol.type) == null ? void 0 : _a2.toUpperCase()) !== "RELATION") return;
10559
10686
  const refId = ((_b2 = selectedSubtableFilterCol.config) == null ? void 0 : _b2.referencedTableId) || selectedSubtableFilterCol.referencedTableId;
@@ -10561,24 +10688,39 @@ function useWhatsAppState(props) {
10561
10688
  const parentColName = (selectedPhoneOption == null ? void 0 : selectedPhoneOption.parentColumnName) || "";
10562
10689
  const keyWithParent = parentColName ? `${parentColName}.${selectedSubtableFilterCol.name}` : "";
10563
10690
  const keyDirect = selectedSubtableFilterCol.name;
10564
- 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) {
10691
+ if (keyWithParent && fullyFetchedRelationKeysRef.current.has(keyWithParent) || fullyFetchedRelationKeysRef.current.has(keyDirect) || fullyFetchedRelationKeysRef.current.has(refId)) {
10565
10692
  return;
10566
10693
  }
10567
- const displayField = ((_f = selectedSubtableFilterCol.config) == null ? void 0 : _f.displayField) || selectedSubtableFilterCol.displayField;
10694
+ const displayField = ((_c = selectedSubtableFilterCol.config) == null ? void 0 : _c.displayField) || selectedSubtableFilterCol.displayField;
10568
10695
  (async () => {
10569
10696
  try {
10570
10697
  const res = await executeAction("FETCH_RELATION", __spreadValues({
10571
10698
  referencedTableId: refId,
10572
10699
  displayField,
10573
10700
  take: 1e3,
10574
- limit: 1e3
10701
+ limit: 1e3,
10702
+ isFilter: false,
10703
+ bypassScoping: true,
10704
+ allOptions: true
10575
10705
  }, orgId ? { orgId, organizationId: orgId } : {}));
10576
10706
  const list = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : [];
10577
10707
  if (list.length > 0) {
10578
- setRelationOptions((prev) => __spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: list } : {}), {
10579
- [keyDirect]: list,
10580
- [refId]: list
10581
- }));
10708
+ if (keyWithParent) fullyFetchedRelationKeysRef.current.add(keyWithParent);
10709
+ fullyFetchedRelationKeysRef.current.add(keyDirect);
10710
+ fullyFetchedRelationKeysRef.current.add(refId);
10711
+ setRelationOptions((prev) => {
10712
+ const existing = prev[keyDirect] || [];
10713
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10714
+ list.forEach((o) => {
10715
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10716
+ if (id) existingMap.set(id, o);
10717
+ });
10718
+ const mergedList = Array.from(existingMap.values());
10719
+ return __spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: mergedList } : {}), {
10720
+ [keyDirect]: mergedList,
10721
+ [refId]: mergedList
10722
+ });
10723
+ });
10582
10724
  }
10583
10725
  } catch (err) {
10584
10726
  console.warn(
@@ -10587,7 +10729,60 @@ function useWhatsAppState(props) {
10587
10729
  );
10588
10730
  }
10589
10731
  })();
10590
- }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, relationOptions, orgId]);
10732
+ }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, orgId]);
10733
+ useEffect13(() => {
10734
+ var _a2, _b2;
10735
+ if (!executeAction || !selectedPostSendOption) return;
10736
+ if (selectedPostSendOption.type !== "RELATION") return;
10737
+ const refId = selectedPostSendOption.referencedTableId || ((_a2 = selectedPostSendOption.config) == null ? void 0 : _a2.referencedTableId);
10738
+ if (!refId) return;
10739
+ const parentColName = selectedPostSendOption.parentColumnName || "";
10740
+ const keyWithParent = parentColName ? `${parentColName}.${selectedPostSendOption.columnName}` : "";
10741
+ const keyDirect = selectedPostSendOption.columnName;
10742
+ const optionId = selectedPostSendOption.id;
10743
+ if (keyWithParent && fullyFetchedRelationKeysRef.current.has(keyWithParent) || fullyFetchedRelationKeysRef.current.has(keyDirect) || fullyFetchedRelationKeysRef.current.has(refId) || optionId && fullyFetchedRelationKeysRef.current.has(optionId)) {
10744
+ return;
10745
+ }
10746
+ const displayField = ((_b2 = selectedPostSendOption.config) == null ? void 0 : _b2.displayField) || (selectedPostSendOption == null ? void 0 : selectedPostSendOption.displayField);
10747
+ (async () => {
10748
+ try {
10749
+ const res = await executeAction("FETCH_RELATION", __spreadValues({
10750
+ referencedTableId: refId,
10751
+ displayField,
10752
+ take: 1e3,
10753
+ limit: 1e3,
10754
+ isFilter: false,
10755
+ bypassScoping: true,
10756
+ allOptions: true
10757
+ }, orgId ? { orgId, organizationId: orgId } : {}));
10758
+ const list = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : [];
10759
+ if (list.length > 0) {
10760
+ if (keyWithParent) fullyFetchedRelationKeysRef.current.add(keyWithParent);
10761
+ fullyFetchedRelationKeysRef.current.add(keyDirect);
10762
+ fullyFetchedRelationKeysRef.current.add(refId);
10763
+ if (optionId) fullyFetchedRelationKeysRef.current.add(optionId);
10764
+ setRelationOptions((prev) => {
10765
+ const existing = prev[keyDirect] || [];
10766
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10767
+ list.forEach((o) => {
10768
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10769
+ if (id) existingMap.set(id, o);
10770
+ });
10771
+ const mergedList = Array.from(existingMap.values());
10772
+ return __spreadValues(__spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: mergedList } : {}), {
10773
+ [keyDirect]: mergedList,
10774
+ [refId]: mergedList
10775
+ }), optionId ? { [optionId]: mergedList } : {});
10776
+ });
10777
+ }
10778
+ } catch (err) {
10779
+ console.warn(
10780
+ `[useWhatsAppState] Failed to fetch relation options for post-send column ${selectedPostSendOption.columnName}:`,
10781
+ err
10782
+ );
10783
+ }
10784
+ })();
10785
+ }, [selectedPostSendOption, executeAction, orgId]);
10591
10786
  const filteredRecords = useMemo8(() => {
10592
10787
  const activeEntries = Object.entries(filters).filter(
10593
10788
  ([_, val]) => val !== void 0 && val !== null && val !== ""
@@ -10619,6 +10814,25 @@ function useWhatsAppState(props) {
10619
10814
  return true;
10620
10815
  });
10621
10816
  }, [rawRecords, filters, filterableColumns]);
10817
+ const filteredData = filteredRecords;
10818
+ useEffect13(() => {
10819
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10820
+ isAutoSelectingRef.current = true;
10821
+ const sliced = filteredData.slice(0, autoSelectCount);
10822
+ const slicedIds = sliced.map((r) => r.id);
10823
+ setSelectedRowIds(slicedIds);
10824
+ const timer = setTimeout(() => {
10825
+ isAutoSelectingRef.current = false;
10826
+ }, 0);
10827
+ return () => clearTimeout(timer);
10828
+ } else if (autoSelectCount === 0 || autoSelectCount === null) {
10829
+ if (!isManualOverrideRef.current && prevAutoSelectCountRef.current !== null) {
10830
+ setSelectedRowIds([]);
10831
+ }
10832
+ }
10833
+ isManualOverrideRef.current = false;
10834
+ prevAutoSelectCountRef.current = autoSelectCount;
10835
+ }, [autoSelectCount, filteredData]);
10622
10836
  const embeddedTableExecuteAction = useCallback12(async (actionType, payload) => {
10623
10837
  if (actionType === "FETCH_TABLE_DATA") {
10624
10838
  const colFilters = (payload == null ? void 0 : payload.columnFilters) || (payload == null ? void 0 : payload.filters);
@@ -10640,6 +10854,15 @@ function useWhatsAppState(props) {
10640
10854
  relationOptions
10641
10855
  };
10642
10856
  }
10857
+ if (actionType === "FETCH_RELATION") {
10858
+ if (executeAction) {
10859
+ return executeAction("FETCH_RELATION", __spreadProps(__spreadValues({}, payload), {
10860
+ isFilter: false,
10861
+ bypassScoping: true,
10862
+ allOptions: true
10863
+ }));
10864
+ }
10865
+ }
10643
10866
  if (executeAction) {
10644
10867
  return executeAction(actionType, payload);
10645
10868
  }
@@ -10661,11 +10884,37 @@ function useWhatsAppState(props) {
10661
10884
  if (prev.length === selectedIds.length && prev.every((id, idx) => id === selectedIds[idx])) {
10662
10885
  return prev;
10663
10886
  }
10887
+ if (!isAutoSelectingRef.current && autoSelectCount !== null && autoSelectCount > 0) {
10888
+ isManualOverrideRef.current = true;
10889
+ setAutoSelectCount(null);
10890
+ }
10664
10891
  setBroadcastSummary(null);
10665
10892
  setRowStatusMap({});
10666
10893
  return selectedIds;
10667
10894
  });
10668
- }, []);
10895
+ }, [autoSelectCount]);
10896
+ const handleRowToggle = useCallback12((rowId, checked) => {
10897
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10898
+ isManualOverrideRef.current = true;
10899
+ setAutoSelectCount(null);
10900
+ }
10901
+ }, [autoSelectCount]);
10902
+ const toggleRowSelection = useCallback12((rowId, checked) => {
10903
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10904
+ isManualOverrideRef.current = true;
10905
+ setAutoSelectCount(null);
10906
+ }
10907
+ setSelectedRowIds((prev) => {
10908
+ const isSelected = prev.includes(rowId);
10909
+ const nextChecked = checked !== void 0 ? checked : !isSelected;
10910
+ if (nextChecked && !isSelected) {
10911
+ return [...prev, rowId];
10912
+ } else if (!nextChecked && isSelected) {
10913
+ return prev.filter((id) => id !== rowId);
10914
+ }
10915
+ return prev;
10916
+ });
10917
+ }, [autoSelectCount]);
10669
10918
  const [templates, setTemplates] = useState15([]);
10670
10919
  const [selectedTemplateId, setSelectedTemplateId] = useState15(null);
10671
10920
  const [isLoading, setIsLoading] = useState15(true);
@@ -11223,6 +11472,11 @@ function useWhatsAppState(props) {
11223
11472
  // Selection
11224
11473
  selectedRowIds,
11225
11474
  handleSelectionChange,
11475
+ handleRowToggle,
11476
+ toggleRowSelection,
11477
+ autoSelectCount,
11478
+ setAutoSelectCount,
11479
+ filteredData,
11226
11480
  // Phone & Subtable settings
11227
11481
  targetPhoneOptions,
11228
11482
  phoneColumns,
@@ -11660,6 +11914,7 @@ function DynamicFiltersBlock({
11660
11914
  handleClearFilters,
11661
11915
  activeFiltersCount,
11662
11916
  relationOptions,
11917
+ getRelationOptionsForCol,
11663
11918
  selectedRowIds,
11664
11919
  filteredRecordsCount,
11665
11920
  rawRecordsCount,
@@ -11691,12 +11946,13 @@ function DynamicFiltersBlock({
11691
11946
  /* @__PURE__ */ jsx16("span", { children: "\u05D0\u05D9\u05DF \u05E9\u05D3\u05D5\u05EA \u05DC\u05E1\u05D9\u05E0\u05D5\u05DF \u05D1\u05D8\u05D1\u05DC\u05D4 \u05D6\u05D5" }),
11692
11947
  /* @__PURE__ */ jsx16("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" })
11693
11948
  ] }) : /* @__PURE__ */ jsx16("div", { className: "grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-1 gap-2", children: filterableColumns.map((col) => {
11694
- var _a;
11949
+ var _a, _b, _c;
11695
11950
  const colType = (_a = col.type) == null ? void 0 : _a.toUpperCase();
11696
11951
  const isBoolean = colType === "BOOLEAN";
11697
11952
  const currentValue = filters[col.name] || "";
11698
11953
  const isActive = Boolean(currentValue);
11699
- const options = relationOptions[col.name] || [];
11954
+ const refTableId = ((_b = col == null ? void 0 : col.config) == null ? void 0 : _b.referencedTableId) || (col == null ? void 0 : col.referencedTableId);
11955
+ 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] : [];
11700
11956
  return /* @__PURE__ */ jsxs15("div", { className: "space-y-1", children: [
11701
11957
  /* @__PURE__ */ jsxs15("div", { className: "flex items-center justify-between", children: [
11702
11958
  /* @__PURE__ */ jsx16(
@@ -11777,7 +12033,8 @@ import {
11777
12033
  Loader2 as Loader26,
11778
12034
  AlertCircle as AlertCircle3,
11779
12035
  Send,
11780
- X as X11
12036
+ X as X11,
12037
+ CheckSquare as CheckSquare2
11781
12038
  } from "lucide-react";
11782
12039
  import { Fragment as Fragment6, jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
11783
12040
  function SettingsAndActionsBlock({
@@ -11786,6 +12043,8 @@ function SettingsAndActionsBlock({
11786
12043
  phoneColumnId,
11787
12044
  setPhoneColumnId,
11788
12045
  selectedPhoneOption,
12046
+ autoSelectCount = null,
12047
+ setAutoSelectCount,
11789
12048
  subtableFilterColumn,
11790
12049
  setSubtableFilterColumn,
11791
12050
  subtableFilterValue,
@@ -11875,6 +12134,72 @@ function SettingsAndActionsBlock({
11875
12134
  /* @__PURE__ */ jsx17(ChevronDown5, { className: "w-3 h-3 text-slate-400 absolute left-2 top-1/2 -translate-y-1/2 pointer-events-none" })
11876
12135
  ] })
11877
12136
  ] }),
12137
+ /* @__PURE__ */ jsxs16("div", { className: "space-y-1", children: [
12138
+ /* @__PURE__ */ jsxs16("div", { className: "flex items-center justify-between", children: [
12139
+ /* @__PURE__ */ jsxs16(
12140
+ "label",
12141
+ {
12142
+ htmlFor: "whatsapp-auto-select-records",
12143
+ className: "text-[11px] font-semibold text-slate-700 flex items-center gap-1 cursor-pointer",
12144
+ children: [
12145
+ /* @__PURE__ */ jsx17(CheckSquare2, { className: "w-3 h-3 text-slate-400" }),
12146
+ /* @__PURE__ */ jsx17("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)" })
12147
+ ]
12148
+ }
12149
+ ),
12150
+ autoSelectCount !== null && autoSelectCount > 0 && /* @__PURE__ */ jsxs16("div", { className: "flex items-center gap-1.5 animate-in fade-in duration-150", children: [
12151
+ /* @__PURE__ */ jsxs16("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: [
12152
+ /* @__PURE__ */ jsx17("span", { className: "w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" }),
12153
+ /* @__PURE__ */ jsxs16("span", { children: [
12154
+ "\u05E0\u05D1\u05D7\u05E8\u05D5 ",
12155
+ selectedRowIdsCount,
12156
+ " \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA"
12157
+ ] })
12158
+ ] }),
12159
+ /* @__PURE__ */ jsxs16(
12160
+ "button",
12161
+ {
12162
+ type: "button",
12163
+ onClick: () => setAutoSelectCount == null ? void 0 : setAutoSelectCount(null),
12164
+ 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",
12165
+ title: "\u05E0\u05E7\u05D4 \u05D1\u05D7\u05D9\u05E8\u05D4 \u05D0\u05D5\u05D8\u05D5\u05DE\u05D8\u05D9\u05EA",
12166
+ "aria-label": "Clear auto select count",
12167
+ children: [
12168
+ /* @__PURE__ */ jsx17(X11, { className: "w-3 h-3" }),
12169
+ /* @__PURE__ */ jsx17("span", { children: "\u05E0\u05E7\u05D4" })
12170
+ ]
12171
+ }
12172
+ )
12173
+ ] })
12174
+ ] }),
12175
+ /* @__PURE__ */ jsx17("div", { className: "relative", children: /* @__PURE__ */ jsx17(
12176
+ "input",
12177
+ {
12178
+ id: "whatsapp-auto-select-records",
12179
+ name: "autoSelectCount",
12180
+ type: "number",
12181
+ min: "0",
12182
+ placeholder: "\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA",
12183
+ "aria-label": "\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA",
12184
+ "data-testid": "auto-select-records-input",
12185
+ value: autoSelectCount === null || autoSelectCount === void 0 ? "" : autoSelectCount,
12186
+ onChange: (e) => {
12187
+ const val = e.target.value.trim();
12188
+ if (val === "") {
12189
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(null);
12190
+ } else {
12191
+ const num = parseInt(val, 10);
12192
+ if (isNaN(num) || num < 0) {
12193
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(null);
12194
+ } else {
12195
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(num);
12196
+ }
12197
+ }
12198
+ },
12199
+ 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"
12200
+ }
12201
+ ) })
12202
+ ] }),
11878
12203
  (selectedPhoneOption == null ? void 0 : selectedPhoneOption.type) === "SUBTABLE" && /* @__PURE__ */ jsxs16("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: [
11879
12204
  /* @__PURE__ */ jsxs16("div", { className: "flex items-center gap-1.5 pb-1 border-b border-emerald-200/60", children: [
11880
12205
  /* @__PURE__ */ jsx17(Users, { className: "w-3.5 h-3.5 text-emerald-700" }),
@@ -12279,6 +12604,7 @@ function WhatsAppComponent(props) {
12279
12604
  handleClearFilters: state.handleClearFilters,
12280
12605
  activeFiltersCount: state.activeFiltersCount,
12281
12606
  relationOptions: state.relationOptions,
12607
+ getRelationOptionsForCol: state.getRelationOptionsForCol,
12282
12608
  selectedRowIds: state.selectedRowIds,
12283
12609
  filteredRecordsCount: state.filteredRecords.length,
12284
12610
  rawRecordsCount: state.rawRecords.length,
@@ -12294,6 +12620,8 @@ function WhatsAppComponent(props) {
12294
12620
  phoneColumnId: state.phoneColumnId,
12295
12621
  setPhoneColumnId: state.setPhoneColumnId,
12296
12622
  selectedPhoneOption: state.selectedPhoneOption,
12623
+ autoSelectCount: state.autoSelectCount,
12624
+ setAutoSelectCount: state.setAutoSelectCount,
12297
12625
  subtableFilterColumn: state.subtableFilterColumn,
12298
12626
  setSubtableFilterColumn: state.setSubtableFilterColumn,
12299
12627
  subtableFilterValue: state.subtableFilterValue,
@@ -12347,7 +12675,9 @@ function WhatsAppComponent(props) {
12347
12675
  },
12348
12676
  data: state.filteredRecords,
12349
12677
  readOnly: true,
12678
+ selectedRowIds: state.selectedRowIds,
12350
12679
  onSelectionChange: state.handleSelectionChange,
12680
+ onRowToggle: state.handleRowToggle,
12351
12681
  executeAction: state.embeddedTableExecuteAction,
12352
12682
  orgId,
12353
12683
  componentId: `${componentId || "whatsapp"}-embedded-table`,
@@ -12543,13 +12873,16 @@ export {
12543
12873
  ColumnHeaderTitle,
12544
12874
  CreateTemplateModal,
12545
12875
  DatePickerCell,
12876
+ DynamicFiltersBlock,
12546
12877
  LinkPickerCell,
12547
12878
  PASTEL_PALETTES,
12548
12879
  RelationFilterPopover,
12549
12880
  RelationPickerCell,
12881
+ SettingsAndActionsBlock,
12550
12882
  SmartTextCell,
12551
12883
  TEXT_REPRESENTABLE_TYPES,
12552
12884
  TableBlock,
12885
+ TableBlockClient,
12553
12886
  TimePickerCell,
12554
12887
  ToastContext,
12555
12888
  ToastProvider,
@@ -12600,6 +12933,7 @@ export {
12600
12933
  useColumnResize,
12601
12934
  useSmartTooltip,
12602
12935
  useToast,
12936
+ useWhatsAppState,
12603
12937
  validateSequentialVariables,
12604
12938
  validateTemplateBody,
12605
12939
  validateTemplateButtons,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@universe-platform/ui",
3
- "version": "0.1.0-beta.20",
3
+ "version": "0.1.0-beta.22",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",