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

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);
@@ -10306,7 +10331,12 @@ function useWhatsAppState(props) {
10306
10331
  const [tableError, setTableError] = (0, import_react17.useState)(null);
10307
10332
  const [filters, setFilters] = (0, import_react17.useState)({});
10308
10333
  const [selectedRowIds, setSelectedRowIds] = (0, import_react17.useState)([]);
10334
+ const [autoSelectCount, setAutoSelectCount] = (0, import_react17.useState)(null);
10335
+ const isAutoSelectingRef = (0, import_react17.useRef)(false);
10336
+ const isManualOverrideRef = (0, import_react17.useRef)(false);
10337
+ const prevAutoSelectCountRef = (0, import_react17.useRef)(null);
10309
10338
  const fetchedTableIdsRef = (0, import_react17.useRef)(/* @__PURE__ */ new Set());
10339
+ const fullyFetchedRelationKeysRef = (0, import_react17.useRef)(/* @__PURE__ */ new Set());
10310
10340
  const loadTableData = (0, import_react17.useCallback)(async () => {
10311
10341
  var _a2;
10312
10342
  const tableId = (settings == null ? void 0 : settings.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableMetaId) || (injectedData == null ? void 0 : injectedData.tableId);
@@ -10331,7 +10361,34 @@ function useWhatsAppState(props) {
10331
10361
  setRawRecords(res.records);
10332
10362
  }
10333
10363
  if (res.relationOptions && typeof res.relationOptions === "object") {
10334
- setRelationOptions((prev) => __spreadValues(__spreadValues({}, prev), res.relationOptions));
10364
+ setRelationOptions((prev) => {
10365
+ const merged = __spreadValues({}, prev);
10366
+ Object.entries(res.relationOptions).forEach(([k, opts]) => {
10367
+ if (Array.isArray(opts)) {
10368
+ const existing = prev[k] || [];
10369
+ if (existing.length >= opts.length && existing.length > 0) {
10370
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10371
+ opts.forEach((o) => {
10372
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10373
+ if (id && !existingMap.has(id)) {
10374
+ existingMap.set(id, o);
10375
+ }
10376
+ });
10377
+ merged[k] = Array.from(existingMap.values());
10378
+ } else {
10379
+ const map = new Map(opts.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10380
+ existing.forEach((o) => {
10381
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10382
+ if (id && !map.has(id)) {
10383
+ map.set(id, o);
10384
+ }
10385
+ });
10386
+ merged[k] = Array.from(map.values());
10387
+ }
10388
+ }
10389
+ });
10390
+ return merged;
10391
+ });
10335
10392
  }
10336
10393
  }
10337
10394
  } catch (err) {
@@ -10559,7 +10616,7 @@ function useWhatsAppState(props) {
10559
10616
  }, []);
10560
10617
  const getRelationOptionsForCol = (0, import_react17.useCallback)(
10561
10618
  (colName, parentColName) => {
10562
- var _a2;
10619
+ var _a2, _b2, _c, _d;
10563
10620
  if (parentColName) {
10564
10621
  const subKey = `${parentColName}.${colName}`;
10565
10622
  if (relationOptions[subKey] && relationOptions[subKey].length > 0) {
@@ -10574,20 +10631,55 @@ function useWhatsAppState(props) {
10574
10631
  if (refId && relationOptions[refId] && relationOptions[refId].length > 0) {
10575
10632
  return relationOptions[refId];
10576
10633
  }
10634
+ const postSendCol = postSendActionTargetOptions.find(
10635
+ (c) => c.columnName === colName && (!parentColName || c.parentColumnName === parentColName) || c.id === colName
10636
+ );
10637
+ if (postSendCol) {
10638
+ if (postSendCol.id && relationOptions[postSendCol.id] && relationOptions[postSendCol.id].length > 0) {
10639
+ return relationOptions[postSendCol.id];
10640
+ }
10641
+ const postSendRefId = postSendCol.referencedTableId || ((_b2 = postSendCol.config) == null ? void 0 : _b2.referencedTableId);
10642
+ if (postSendRefId && relationOptions[postSendRefId] && relationOptions[postSendRefId].length > 0) {
10643
+ return relationOptions[postSendRefId];
10644
+ }
10645
+ }
10646
+ const mainCol = (tableColumns || []).find((c) => c.name === colName);
10647
+ const mainRefId = ((_c = mainCol == null ? void 0 : mainCol.config) == null ? void 0 : _c.referencedTableId) || (mainCol == null ? void 0 : mainCol.referencedTableId);
10648
+ if (mainRefId && relationOptions[mainRefId] && relationOptions[mainRefId].length > 0) {
10649
+ return relationOptions[mainRefId];
10650
+ }
10651
+ const filterCol = filterableColumns.find((c) => c.name === colName);
10652
+ const filterRefId = ((_d = filterCol == null ? void 0 : filterCol.config) == null ? void 0 : _d.referencedTableId) || (filterCol == null ? void 0 : filterCol.referencedTableId);
10653
+ if (filterRefId && relationOptions[filterRefId] && relationOptions[filterRefId].length > 0) {
10654
+ return relationOptions[filterRefId];
10655
+ }
10577
10656
  return [];
10578
10657
  },
10579
- [relationOptions, subtableFilterableColumns]
10658
+ [relationOptions, subtableFilterableColumns, postSendActionTargetOptions, tableColumns, filterableColumns]
10580
10659
  );
10581
10660
  (0, import_react17.useEffect)(() => {
10582
- var _a2, _b2, _c;
10661
+ var _a2, _b2, _c, _d, _e;
10583
10662
  if (!executeAction) return;
10584
10663
  const targets = [];
10664
+ (tableColumns || []).forEach((col) => {
10665
+ var _a3, _b3, _c2;
10666
+ if (((_a3 = col.type) == null ? void 0 : _a3.toUpperCase()) === "RELATION") {
10667
+ const refId = ((_b3 = col.config) == null ? void 0 : _b3.referencedTableId) || col.referencedTableId;
10668
+ const displayField = ((_c2 = col.config) == null ? void 0 : _c2.displayField) || col.displayField;
10669
+ if (refId) {
10670
+ targets.push({ key: col.name, refId, displayField, colName: col.name, extraKey: col.id });
10671
+ targets.push({ key: refId, refId, displayField, colName: col.name, extraKey: col.id });
10672
+ }
10673
+ }
10674
+ });
10585
10675
  filterableColumns.forEach((col) => {
10586
10676
  var _a3, _b3, _c2;
10587
10677
  if (((_a3 = col.type) == null ? void 0 : _a3.toUpperCase()) === "RELATION") {
10588
10678
  const refId = ((_b3 = col.config) == null ? void 0 : _b3.referencedTableId) || col.referencedTableId;
10589
10679
  const displayField = ((_c2 = col.config) == null ? void 0 : _c2.displayField) || col.displayField;
10590
- if (refId) targets.push({ key: col.name, refId, displayField });
10680
+ if (refId) {
10681
+ targets.push({ key: col.name, refId, displayField, colName: col.name, extraKey: col.id });
10682
+ }
10591
10683
  }
10592
10684
  });
10593
10685
  if ((selectedPhoneOption == null ? void 0 : selectedPhoneOption.type) === "SUBTABLE") {
@@ -10603,35 +10695,64 @@ function useWhatsAppState(props) {
10603
10695
  const refId = ((_b3 = subCol.config) == null ? void 0 : _b3.referencedTableId) || subCol.referencedTableId;
10604
10696
  const displayField = ((_c2 = subCol.config) == null ? void 0 : _c2.displayField) || subCol.displayField;
10605
10697
  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 });
10698
+ targets.push({ key: `${parentColName}.${subCol.name}`, refId, displayField, colName: subCol.name });
10699
+ targets.push({ key: subCol.name, refId, displayField, colName: subCol.name });
10700
+ targets.push({ key: refId, refId, displayField, colName: subCol.name });
10609
10701
  }
10610
10702
  }
10611
10703
  });
10612
10704
  }
10705
+ if (selectedPostSendOption && selectedPostSendOption.type === "RELATION") {
10706
+ const postSendRefId = selectedPostSendOption.referencedTableId || ((_d = selectedPostSendOption.config) == null ? void 0 : _d.referencedTableId);
10707
+ const postSendDisplayField = ((_e = selectedPostSendOption.config) == null ? void 0 : _e.displayField) || (selectedPostSendOption == null ? void 0 : selectedPostSendOption.displayField);
10708
+ if (postSendRefId) {
10709
+ const parentCol = selectedPostSendOption.parentColumnName;
10710
+ if (parentCol) {
10711
+ targets.push({ key: `${parentCol}.${selectedPostSendOption.columnName}`, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName, extraKey: selectedPostSendOption.id });
10712
+ }
10713
+ targets.push({ key: selectedPostSendOption.columnName, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName, extraKey: selectedPostSendOption.id });
10714
+ targets.push({ key: postSendRefId, refId: postSendRefId, displayField: postSendDisplayField, colName: selectedPostSendOption.columnName });
10715
+ }
10716
+ }
10613
10717
  targets.forEach(async (target) => {
10614
- if (relationOptions[target.key] && relationOptions[target.key].length > 0) return;
10718
+ if (fullyFetchedRelationKeysRef.current.has(target.key)) return;
10615
10719
  try {
10616
- const result = await executeAction("FETCH_RELATION", {
10720
+ const result = await executeAction("FETCH_RELATION", __spreadValues({
10617
10721
  referencedTableId: target.refId,
10618
10722
  displayField: target.displayField,
10619
- take: 1e3
10620
- });
10723
+ take: 1e3,
10724
+ limit: 1e3,
10725
+ isFilter: false,
10726
+ bypassScoping: true,
10727
+ allOptions: true
10728
+ }, orgId ? { orgId, organizationId: orgId } : {}));
10621
10729
  const list = Array.isArray(result) ? result : (result == null ? void 0 : result.data) && Array.isArray(result.data) ? result.data : [];
10622
10730
  if (list.length > 0) {
10623
- setRelationOptions((prev) => __spreadProps(__spreadValues({}, prev), {
10624
- [target.key]: list,
10625
- [target.refId]: list
10626
- }));
10731
+ fullyFetchedRelationKeysRef.current.add(target.key);
10732
+ fullyFetchedRelationKeysRef.current.add(target.refId);
10733
+ if (target.colName) fullyFetchedRelationKeysRef.current.add(target.colName);
10734
+ if (target.extraKey) fullyFetchedRelationKeysRef.current.add(target.extraKey);
10735
+ setRelationOptions((prev) => {
10736
+ const existing = prev[target.key] || [];
10737
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10738
+ list.forEach((o) => {
10739
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10740
+ if (id) existingMap.set(id, o);
10741
+ });
10742
+ const mergedList = Array.from(existingMap.values());
10743
+ return __spreadValues(__spreadValues(__spreadProps(__spreadValues({}, prev), {
10744
+ [target.key]: mergedList,
10745
+ [target.refId]: mergedList
10746
+ }), target.colName ? { [target.colName]: mergedList } : {}), target.extraKey ? { [target.extraKey]: mergedList } : {});
10747
+ });
10627
10748
  }
10628
10749
  } catch (err) {
10629
10750
  console.warn(`[useWhatsAppState] Failed to fetch relation options for ${target.key}:`, err);
10630
10751
  }
10631
10752
  });
10632
- }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns, executeAction, relationOptions]);
10753
+ }, [filterableColumns, selectedPhoneOption, referencedTableSchemas, tableColumns, executeAction, selectedPostSendOption, orgId]);
10633
10754
  (0, import_react17.useEffect)(() => {
10634
- var _a2, _b2, _c, _d, _e, _f;
10755
+ var _a2, _b2, _c;
10635
10756
  if (!executeAction || !selectedSubtableFilterCol) return;
10636
10757
  if (((_a2 = selectedSubtableFilterCol.type) == null ? void 0 : _a2.toUpperCase()) !== "RELATION") return;
10637
10758
  const refId = ((_b2 = selectedSubtableFilterCol.config) == null ? void 0 : _b2.referencedTableId) || selectedSubtableFilterCol.referencedTableId;
@@ -10639,24 +10760,39 @@ function useWhatsAppState(props) {
10639
10760
  const parentColName = (selectedPhoneOption == null ? void 0 : selectedPhoneOption.parentColumnName) || "";
10640
10761
  const keyWithParent = parentColName ? `${parentColName}.${selectedSubtableFilterCol.name}` : "";
10641
10762
  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) {
10763
+ if (keyWithParent && fullyFetchedRelationKeysRef.current.has(keyWithParent) || fullyFetchedRelationKeysRef.current.has(keyDirect) || fullyFetchedRelationKeysRef.current.has(refId)) {
10643
10764
  return;
10644
10765
  }
10645
- const displayField = ((_f = selectedSubtableFilterCol.config) == null ? void 0 : _f.displayField) || selectedSubtableFilterCol.displayField;
10766
+ const displayField = ((_c = selectedSubtableFilterCol.config) == null ? void 0 : _c.displayField) || selectedSubtableFilterCol.displayField;
10646
10767
  (async () => {
10647
10768
  try {
10648
10769
  const res = await executeAction("FETCH_RELATION", __spreadValues({
10649
10770
  referencedTableId: refId,
10650
10771
  displayField,
10651
10772
  take: 1e3,
10652
- limit: 1e3
10773
+ limit: 1e3,
10774
+ isFilter: false,
10775
+ bypassScoping: true,
10776
+ allOptions: true
10653
10777
  }, orgId ? { orgId, organizationId: orgId } : {}));
10654
10778
  const list = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : [];
10655
10779
  if (list.length > 0) {
10656
- setRelationOptions((prev) => __spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: list } : {}), {
10657
- [keyDirect]: list,
10658
- [refId]: list
10659
- }));
10780
+ if (keyWithParent) fullyFetchedRelationKeysRef.current.add(keyWithParent);
10781
+ fullyFetchedRelationKeysRef.current.add(keyDirect);
10782
+ fullyFetchedRelationKeysRef.current.add(refId);
10783
+ setRelationOptions((prev) => {
10784
+ const existing = prev[keyDirect] || [];
10785
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10786
+ list.forEach((o) => {
10787
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10788
+ if (id) existingMap.set(id, o);
10789
+ });
10790
+ const mergedList = Array.from(existingMap.values());
10791
+ return __spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: mergedList } : {}), {
10792
+ [keyDirect]: mergedList,
10793
+ [refId]: mergedList
10794
+ });
10795
+ });
10660
10796
  }
10661
10797
  } catch (err) {
10662
10798
  console.warn(
@@ -10665,7 +10801,60 @@ function useWhatsAppState(props) {
10665
10801
  );
10666
10802
  }
10667
10803
  })();
10668
- }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, relationOptions, orgId]);
10804
+ }, [selectedSubtableFilterCol, selectedPhoneOption, executeAction, orgId]);
10805
+ (0, import_react17.useEffect)(() => {
10806
+ var _a2, _b2;
10807
+ if (!executeAction || !selectedPostSendOption) return;
10808
+ if (selectedPostSendOption.type !== "RELATION") return;
10809
+ const refId = selectedPostSendOption.referencedTableId || ((_a2 = selectedPostSendOption.config) == null ? void 0 : _a2.referencedTableId);
10810
+ if (!refId) return;
10811
+ const parentColName = selectedPostSendOption.parentColumnName || "";
10812
+ const keyWithParent = parentColName ? `${parentColName}.${selectedPostSendOption.columnName}` : "";
10813
+ const keyDirect = selectedPostSendOption.columnName;
10814
+ const optionId = selectedPostSendOption.id;
10815
+ if (keyWithParent && fullyFetchedRelationKeysRef.current.has(keyWithParent) || fullyFetchedRelationKeysRef.current.has(keyDirect) || fullyFetchedRelationKeysRef.current.has(refId) || optionId && fullyFetchedRelationKeysRef.current.has(optionId)) {
10816
+ return;
10817
+ }
10818
+ const displayField = ((_b2 = selectedPostSendOption.config) == null ? void 0 : _b2.displayField) || (selectedPostSendOption == null ? void 0 : selectedPostSendOption.displayField);
10819
+ (async () => {
10820
+ try {
10821
+ const res = await executeAction("FETCH_RELATION", __spreadValues({
10822
+ referencedTableId: refId,
10823
+ displayField,
10824
+ take: 1e3,
10825
+ limit: 1e3,
10826
+ isFilter: false,
10827
+ bypassScoping: true,
10828
+ allOptions: true
10829
+ }, orgId ? { orgId, organizationId: orgId } : {}));
10830
+ const list = Array.isArray(res) ? res : (res == null ? void 0 : res.data) && Array.isArray(res.data) ? res.data : [];
10831
+ if (list.length > 0) {
10832
+ if (keyWithParent) fullyFetchedRelationKeysRef.current.add(keyWithParent);
10833
+ fullyFetchedRelationKeysRef.current.add(keyDirect);
10834
+ fullyFetchedRelationKeysRef.current.add(refId);
10835
+ if (optionId) fullyFetchedRelationKeysRef.current.add(optionId);
10836
+ setRelationOptions((prev) => {
10837
+ const existing = prev[keyDirect] || [];
10838
+ const existingMap = new Map(existing.map((o) => [String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id)), o]));
10839
+ list.forEach((o) => {
10840
+ const id = String((o == null ? void 0 : o.id) || (o == null ? void 0 : o._id));
10841
+ if (id) existingMap.set(id, o);
10842
+ });
10843
+ const mergedList = Array.from(existingMap.values());
10844
+ return __spreadValues(__spreadProps(__spreadValues(__spreadValues({}, prev), keyWithParent ? { [keyWithParent]: mergedList } : {}), {
10845
+ [keyDirect]: mergedList,
10846
+ [refId]: mergedList
10847
+ }), optionId ? { [optionId]: mergedList } : {});
10848
+ });
10849
+ }
10850
+ } catch (err) {
10851
+ console.warn(
10852
+ `[useWhatsAppState] Failed to fetch relation options for post-send column ${selectedPostSendOption.columnName}:`,
10853
+ err
10854
+ );
10855
+ }
10856
+ })();
10857
+ }, [selectedPostSendOption, executeAction, orgId]);
10669
10858
  const filteredRecords = (0, import_react17.useMemo)(() => {
10670
10859
  const activeEntries = Object.entries(filters).filter(
10671
10860
  ([_, val]) => val !== void 0 && val !== null && val !== ""
@@ -10697,6 +10886,25 @@ function useWhatsAppState(props) {
10697
10886
  return true;
10698
10887
  });
10699
10888
  }, [rawRecords, filters, filterableColumns]);
10889
+ const filteredData = filteredRecords;
10890
+ (0, import_react17.useEffect)(() => {
10891
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10892
+ isAutoSelectingRef.current = true;
10893
+ const sliced = filteredData.slice(0, autoSelectCount);
10894
+ const slicedIds = sliced.map((r) => r.id);
10895
+ setSelectedRowIds(slicedIds);
10896
+ const timer = setTimeout(() => {
10897
+ isAutoSelectingRef.current = false;
10898
+ }, 0);
10899
+ return () => clearTimeout(timer);
10900
+ } else if (autoSelectCount === 0 || autoSelectCount === null) {
10901
+ if (!isManualOverrideRef.current && prevAutoSelectCountRef.current !== null) {
10902
+ setSelectedRowIds([]);
10903
+ }
10904
+ }
10905
+ isManualOverrideRef.current = false;
10906
+ prevAutoSelectCountRef.current = autoSelectCount;
10907
+ }, [autoSelectCount, filteredData]);
10700
10908
  const embeddedTableExecuteAction = (0, import_react17.useCallback)(async (actionType, payload) => {
10701
10909
  if (actionType === "FETCH_TABLE_DATA") {
10702
10910
  const colFilters = (payload == null ? void 0 : payload.columnFilters) || (payload == null ? void 0 : payload.filters);
@@ -10718,6 +10926,15 @@ function useWhatsAppState(props) {
10718
10926
  relationOptions
10719
10927
  };
10720
10928
  }
10929
+ if (actionType === "FETCH_RELATION") {
10930
+ if (executeAction) {
10931
+ return executeAction("FETCH_RELATION", __spreadProps(__spreadValues({}, payload), {
10932
+ isFilter: false,
10933
+ bypassScoping: true,
10934
+ allOptions: true
10935
+ }));
10936
+ }
10937
+ }
10721
10938
  if (executeAction) {
10722
10939
  return executeAction(actionType, payload);
10723
10940
  }
@@ -10739,11 +10956,37 @@ function useWhatsAppState(props) {
10739
10956
  if (prev.length === selectedIds.length && prev.every((id, idx) => id === selectedIds[idx])) {
10740
10957
  return prev;
10741
10958
  }
10959
+ if (!isAutoSelectingRef.current && autoSelectCount !== null && autoSelectCount > 0) {
10960
+ isManualOverrideRef.current = true;
10961
+ setAutoSelectCount(null);
10962
+ }
10742
10963
  setBroadcastSummary(null);
10743
10964
  setRowStatusMap({});
10744
10965
  return selectedIds;
10745
10966
  });
10746
- }, []);
10967
+ }, [autoSelectCount]);
10968
+ const handleRowToggle = (0, import_react17.useCallback)((rowId, checked) => {
10969
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10970
+ isManualOverrideRef.current = true;
10971
+ setAutoSelectCount(null);
10972
+ }
10973
+ }, [autoSelectCount]);
10974
+ const toggleRowSelection = (0, import_react17.useCallback)((rowId, checked) => {
10975
+ if (autoSelectCount !== null && autoSelectCount > 0) {
10976
+ isManualOverrideRef.current = true;
10977
+ setAutoSelectCount(null);
10978
+ }
10979
+ setSelectedRowIds((prev) => {
10980
+ const isSelected = prev.includes(rowId);
10981
+ const nextChecked = checked !== void 0 ? checked : !isSelected;
10982
+ if (nextChecked && !isSelected) {
10983
+ return [...prev, rowId];
10984
+ } else if (!nextChecked && isSelected) {
10985
+ return prev.filter((id) => id !== rowId);
10986
+ }
10987
+ return prev;
10988
+ });
10989
+ }, [autoSelectCount]);
10747
10990
  const [templates, setTemplates] = (0, import_react17.useState)([]);
10748
10991
  const [selectedTemplateId, setSelectedTemplateId] = (0, import_react17.useState)(null);
10749
10992
  const [isLoading, setIsLoading] = (0, import_react17.useState)(true);
@@ -11301,6 +11544,11 @@ function useWhatsAppState(props) {
11301
11544
  // Selection
11302
11545
  selectedRowIds,
11303
11546
  handleSelectionChange,
11547
+ handleRowToggle,
11548
+ toggleRowSelection,
11549
+ autoSelectCount,
11550
+ setAutoSelectCount,
11551
+ filteredData,
11304
11552
  // Phone & Subtable settings
11305
11553
  targetPhoneOptions,
11306
11554
  phoneColumns,
@@ -11720,6 +11968,7 @@ function DynamicFiltersBlock({
11720
11968
  handleClearFilters,
11721
11969
  activeFiltersCount,
11722
11970
  relationOptions,
11971
+ getRelationOptionsForCol,
11723
11972
  selectedRowIds,
11724
11973
  filteredRecordsCount,
11725
11974
  rawRecordsCount,
@@ -11751,12 +12000,13 @@ function DynamicFiltersBlock({
11751
12000
  /* @__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
12001
  /* @__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
12002
  ] }) : /* @__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;
12003
+ var _a, _b, _c;
11755
12004
  const colType = (_a = col.type) == null ? void 0 : _a.toUpperCase();
11756
12005
  const isBoolean = colType === "BOOLEAN";
11757
12006
  const currentValue = filters[col.name] || "";
11758
12007
  const isActive = Boolean(currentValue);
11759
- const options = relationOptions[col.name] || [];
12008
+ const refTableId = ((_b = col == null ? void 0 : col.config) == null ? void 0 : _b.referencedTableId) || (col == null ? void 0 : col.referencedTableId);
12009
+ 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
12010
  return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "space-y-1", children: [
11761
12011
  /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("div", { className: "flex items-center justify-between", children: [
11762
12012
  /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
@@ -11838,6 +12088,8 @@ function SettingsAndActionsBlock({
11838
12088
  phoneColumnId,
11839
12089
  setPhoneColumnId,
11840
12090
  selectedPhoneOption,
12091
+ autoSelectCount = null,
12092
+ setAutoSelectCount,
11841
12093
  subtableFilterColumn,
11842
12094
  setSubtableFilterColumn,
11843
12095
  subtableFilterValue,
@@ -11927,6 +12179,72 @@ function SettingsAndActionsBlock({
11927
12179
  /* @__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
12180
  ] })
11929
12181
  ] }),
12182
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "space-y-1", children: [
12183
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center justify-between", children: [
12184
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
12185
+ "label",
12186
+ {
12187
+ htmlFor: "whatsapp-auto-select-records",
12188
+ className: "text-[11px] font-semibold text-slate-700 flex items-center gap-1 cursor-pointer",
12189
+ children: [
12190
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.CheckSquare, { className: "w-3 h-3 text-slate-400" }),
12191
+ /* @__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)" })
12192
+ ]
12193
+ }
12194
+ ),
12195
+ 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: [
12196
+ /* @__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: [
12197
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { className: "w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse" }),
12198
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("span", { children: [
12199
+ "\u05E0\u05D1\u05D7\u05E8\u05D5 ",
12200
+ selectedRowIdsCount,
12201
+ " \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA"
12202
+ ] })
12203
+ ] }),
12204
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(
12205
+ "button",
12206
+ {
12207
+ type: "button",
12208
+ onClick: () => setAutoSelectCount == null ? void 0 : setAutoSelectCount(null),
12209
+ 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",
12210
+ title: "\u05E0\u05E7\u05D4 \u05D1\u05D7\u05D9\u05E8\u05D4 \u05D0\u05D5\u05D8\u05D5\u05DE\u05D8\u05D9\u05EA",
12211
+ "aria-label": "Clear auto select count",
12212
+ children: [
12213
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.X, { className: "w-3 h-3" }),
12214
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("span", { children: "\u05E0\u05E7\u05D4" })
12215
+ ]
12216
+ }
12217
+ )
12218
+ ] })
12219
+ ] }),
12220
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { className: "relative", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
12221
+ "input",
12222
+ {
12223
+ id: "whatsapp-auto-select-records",
12224
+ name: "autoSelectCount",
12225
+ type: "number",
12226
+ min: "0",
12227
+ placeholder: "\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA",
12228
+ "aria-label": "\u05DB\u05DE\u05D5\u05EA \u05E8\u05E9\u05D5\u05DE\u05D5\u05EA \u05DE\u05E8\u05D1\u05D9\u05EA",
12229
+ "data-testid": "auto-select-records-input",
12230
+ value: autoSelectCount === null || autoSelectCount === void 0 ? "" : autoSelectCount,
12231
+ onChange: (e) => {
12232
+ const val = e.target.value.trim();
12233
+ if (val === "") {
12234
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(null);
12235
+ } else {
12236
+ const num = parseInt(val, 10);
12237
+ if (isNaN(num) || num < 0) {
12238
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(null);
12239
+ } else {
12240
+ setAutoSelectCount == null ? void 0 : setAutoSelectCount(num);
12241
+ }
12242
+ }
12243
+ },
12244
+ 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"
12245
+ }
12246
+ ) })
12247
+ ] }),
11930
12248
  (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
12249
  /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { className: "flex items-center gap-1.5 pb-1 border-b border-emerald-200/60", children: [
11932
12250
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_lucide_react13.Users, { className: "w-3.5 h-3.5 text-emerald-700" }),
@@ -12331,6 +12649,7 @@ function WhatsAppComponent(props) {
12331
12649
  handleClearFilters: state.handleClearFilters,
12332
12650
  activeFiltersCount: state.activeFiltersCount,
12333
12651
  relationOptions: state.relationOptions,
12652
+ getRelationOptionsForCol: state.getRelationOptionsForCol,
12334
12653
  selectedRowIds: state.selectedRowIds,
12335
12654
  filteredRecordsCount: state.filteredRecords.length,
12336
12655
  rawRecordsCount: state.rawRecords.length,
@@ -12346,6 +12665,8 @@ function WhatsAppComponent(props) {
12346
12665
  phoneColumnId: state.phoneColumnId,
12347
12666
  setPhoneColumnId: state.setPhoneColumnId,
12348
12667
  selectedPhoneOption: state.selectedPhoneOption,
12668
+ autoSelectCount: state.autoSelectCount,
12669
+ setAutoSelectCount: state.setAutoSelectCount,
12349
12670
  subtableFilterColumn: state.subtableFilterColumn,
12350
12671
  setSubtableFilterColumn: state.setSubtableFilterColumn,
12351
12672
  subtableFilterValue: state.subtableFilterValue,
@@ -12399,7 +12720,9 @@ function WhatsAppComponent(props) {
12399
12720
  },
12400
12721
  data: state.filteredRecords,
12401
12722
  readOnly: true,
12723
+ selectedRowIds: state.selectedRowIds,
12402
12724
  onSelectionChange: state.handleSelectionChange,
12725
+ onRowToggle: state.handleRowToggle,
12403
12726
  executeAction: state.embeddedTableExecuteAction,
12404
12727
  orgId,
12405
12728
  componentId: `${componentId || "whatsapp"}-embedded-table`,
@@ -12596,13 +12919,16 @@ var UNIVERSE_COMPONENTS = {
12596
12919
  ColumnHeaderTitle,
12597
12920
  CreateTemplateModal,
12598
12921
  DatePickerCell,
12922
+ DynamicFiltersBlock,
12599
12923
  LinkPickerCell,
12600
12924
  PASTEL_PALETTES,
12601
12925
  RelationFilterPopover,
12602
12926
  RelationPickerCell,
12927
+ SettingsAndActionsBlock,
12603
12928
  SmartTextCell,
12604
12929
  TEXT_REPRESENTABLE_TYPES,
12605
12930
  TableBlock,
12931
+ TableBlockClient,
12606
12932
  TimePickerCell,
12607
12933
  ToastContext,
12608
12934
  ToastProvider,
@@ -12653,6 +12979,7 @@ var UNIVERSE_COMPONENTS = {
12653
12979
  useColumnResize,
12654
12980
  useSmartTooltip,
12655
12981
  useToast,
12982
+ useWhatsAppState,
12656
12983
  validateSequentialVariables,
12657
12984
  validateTemplateBody,
12658
12985
  validateTemplateButtons,