strapi-plugin-bulk-updater 1.6.0 → 1.6.2

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.
@@ -354,6 +354,89 @@ function getEntryLifecycleStatus(entry, col, pendingBatches = []) {
354
354
  textColor: "neutral700"
355
355
  };
356
356
  }
357
+ const EMPTY_SEARCH_FILTER = {
358
+ searchAttribute: "",
359
+ filterOperator: "none",
360
+ filterQuery: "",
361
+ entrySearch: "",
362
+ statusFilter: "all",
363
+ useRegex: false,
364
+ regexPattern: ""
365
+ };
366
+ function areSearchFiltersEqual(a, b, options = {}) {
367
+ if ((a.searchAttribute || "") !== (b.searchAttribute || "") || (a.filterOperator || "none") !== (b.filterOperator || "none") || (a.filterQuery || "") !== (b.filterQuery || "") || (a.entrySearch || "") !== (b.entrySearch || "")) {
368
+ return false;
369
+ }
370
+ if (options.includeWorkspaceExtras) {
371
+ if ((a.statusFilter || "all") !== (b.statusFilter || "all") || Boolean(a.useRegex) !== Boolean(b.useRegex) || (a.regexPattern || "") !== (b.regexPattern || "")) {
372
+ return false;
373
+ }
374
+ }
375
+ return true;
376
+ }
377
+ function isSearchFilterActive(filter, selectedTargetAttribute = "") {
378
+ const hasAttrFilter = Boolean(filter.searchAttribute && filter.searchAttribute !== selectedTargetAttribute);
379
+ const hasOp = filter.filterOperator !== "none" && (["empty", "not_empty"].includes(filter.filterOperator) || Boolean((filter.filterQuery || "").trim()));
380
+ const hasSearchText = Boolean((filter.entrySearch || "").trim());
381
+ const hasStatus = Boolean(filter.statusFilter && filter.statusFilter !== "all");
382
+ const hasRegex = Boolean(filter.useRegex && (filter.regexPattern || "").trim());
383
+ return hasAttrFilter || hasOp || hasSearchText || hasStatus || hasRegex;
384
+ }
385
+ function buildEntriesQueryParams(options) {
386
+ const { page, pageSize, filter, selectedAttribute, sortField, sortOrder, includeAttributeEvenIfSame } = options;
387
+ const params = new URLSearchParams({
388
+ page: String(page),
389
+ pageSize: String(pageSize)
390
+ });
391
+ if (includeAttributeEvenIfSame) {
392
+ if (filter.searchAttribute) {
393
+ params.set("attribute", filter.searchAttribute);
394
+ params.set("searchAttribute", filter.searchAttribute);
395
+ }
396
+ } else {
397
+ if (selectedAttribute) params.set("attribute", selectedAttribute);
398
+ if (filter.searchAttribute && filter.searchAttribute !== selectedAttribute) {
399
+ params.set("searchAttribute", filter.searchAttribute);
400
+ }
401
+ }
402
+ if (filter.filterOperator && filter.filterOperator !== "none") {
403
+ params.set("filterOperator", filter.filterOperator);
404
+ if (filter.filterQuery) {
405
+ params.set("filterQuery", filter.filterQuery);
406
+ }
407
+ }
408
+ if (filter.entrySearch && filter.entrySearch.trim()) {
409
+ params.set("search", filter.entrySearch.trim());
410
+ }
411
+ if (sortField) {
412
+ params.set("sortField", sortField);
413
+ if (sortOrder) params.set("sortOrder", sortOrder);
414
+ }
415
+ return params;
416
+ }
417
+ function buildCsvExportQueryParams(options) {
418
+ const { limit, filter, exportMode } = options;
419
+ const queryParams = new URLSearchParams();
420
+ if (limit && limit > 0) {
421
+ queryParams.set("limit", String(limit));
422
+ }
423
+ if (exportMode) {
424
+ queryParams.set("exportMode", exportMode);
425
+ }
426
+ if (filter.searchAttribute) {
427
+ queryParams.set("searchAttribute", filter.searchAttribute);
428
+ }
429
+ if (filter.filterOperator && filter.filterOperator !== "none") {
430
+ queryParams.set("filterOperator", filter.filterOperator);
431
+ if (filter.filterQuery) {
432
+ queryParams.set("filterQuery", filter.filterQuery);
433
+ }
434
+ }
435
+ if (filter.entrySearch && filter.entrySearch.trim()) {
436
+ queryParams.set("search", filter.entrySearch.trim());
437
+ }
438
+ return queryParams;
439
+ }
357
440
  function CsvManagerTab() {
358
441
  const { get, post } = admin.useFetchClient();
359
442
  const { toggleNotification } = admin.useNotification();
@@ -370,10 +453,20 @@ function CsvManagerTab() {
370
453
  const [filterOperator, setFilterOperator] = React.useState("none");
371
454
  const [filterQuery, setFilterQuery] = React.useState("");
372
455
  const [entrySearch, setEntrySearch] = React.useState("");
456
+ const [appliedFilter, setAppliedFilter] = React.useState(EMPTY_SEARCH_FILTER);
457
+ const appliedFilterRef = React.useRef(EMPTY_SEARCH_FILTER);
373
458
  const [matchingCount, setMatchingCount] = React.useState(null);
374
459
  const [countLoading, setCountLoading] = React.useState(false);
460
+ const draftFilter = {
461
+ searchAttribute,
462
+ filterOperator,
463
+ filterQuery,
464
+ entrySearch
465
+ };
466
+ const hasPendingFilterChanges = !areSearchFiltersEqual(draftFilter, appliedFilter);
375
467
  const [searchRelationOptions, setSearchRelationOptions] = React.useState([]);
376
468
  const [searchRelationOptionsLoading, setSearchRelationOptionsLoading] = React.useState(false);
469
+ const [exportMode, setExportMode] = React.useState("all");
377
470
  const [exportLimit, setExportLimit] = React.useState(0);
378
471
  const [exportLimitInput, setExportLimitInput] = React.useState("");
379
472
  const [exportingCollection, setExportingCollection] = React.useState(false);
@@ -491,53 +584,78 @@ function CsvManagerTab() {
491
584
  setFilterOperator("none");
492
585
  setFilterQuery("");
493
586
  setEntrySearch("");
587
+ appliedFilterRef.current = EMPTY_SEARCH_FILTER;
588
+ setAppliedFilter(EMPTY_SEARCH_FILTER);
494
589
  setMatchingCount(null);
495
590
  setCountLoading(Boolean(newUid));
496
591
  };
497
- React.useEffect(() => {
498
- if (!selectedUid) {
592
+ const executeMatchingCountSearch = async (targetUid, filterToApply) => {
593
+ if (!targetUid) {
499
594
  setMatchingCount(null);
500
595
  setCountLoading(false);
501
596
  return;
502
597
  }
598
+ if (countAbortControllerRef.current) {
599
+ countAbortControllerRef.current.abort();
600
+ }
601
+ const controller = new AbortController();
602
+ countAbortControllerRef.current = controller;
503
603
  setCountLoading(true);
504
- const timer = setTimeout(async () => {
505
- if (countAbortControllerRef.current) {
506
- countAbortControllerRef.current.abort();
604
+ try {
605
+ const params = buildEntriesQueryParams({
606
+ page: 1,
607
+ pageSize: 1,
608
+ filter: filterToApply,
609
+ includeAttributeEvenIfSame: true
610
+ });
611
+ const res = await get(`/bulk-updater/collections/${targetUid}/entries?${params.toString()}`, {
612
+ signal: controller.signal
613
+ });
614
+ if (countAbortControllerRef.current !== controller) return;
615
+ if (res.data) {
616
+ const total = res.data.pagination?.total ?? (Array.isArray(res.data.entries) ? res.data.entries.length : 0);
617
+ setMatchingCount(total);
507
618
  }
508
- const controller = new AbortController();
509
- countAbortControllerRef.current = controller;
510
- try {
511
- const params = new URLSearchParams({
512
- page: "1",
513
- pageSize: "1"
514
- });
515
- if (searchAttribute) {
516
- params.set("attribute", searchAttribute);
517
- params.set("searchAttribute", searchAttribute);
518
- }
519
- if (filterOperator && filterOperator !== "none") {
520
- params.set("filterOperator", filterOperator);
521
- if (filterQuery) params.set("filterQuery", filterQuery);
522
- }
523
- if (entrySearch && entrySearch.trim()) {
524
- params.set("search", entrySearch.trim());
525
- }
526
- const res = await get(`/bulk-updater/collections/${selectedUid}/entries?${params.toString()}`, {
527
- signal: controller.signal
528
- });
529
- if (res.data) {
530
- const total = res.data.pagination?.total ?? (Array.isArray(res.data.entries) ? res.data.entries.length : 0);
531
- setMatchingCount(total);
532
- }
533
- } catch (err) {
534
- if (!ValidationRulesTab.isAbortError(err)) ;
535
- } finally {
619
+ } catch (err) {
620
+ if (!ValidationRulesTab.isAbortError(err)) ;
621
+ } finally {
622
+ if (countAbortControllerRef.current === controller) {
536
623
  setCountLoading(false);
537
624
  }
538
- }, 300);
539
- return () => clearTimeout(timer);
540
- }, [selectedUid, searchAttribute, filterOperator, filterQuery, entrySearch]);
625
+ }
626
+ };
627
+ React.useEffect(() => {
628
+ if (!selectedUid) {
629
+ setMatchingCount(null);
630
+ setCountLoading(false);
631
+ return;
632
+ }
633
+ executeMatchingCountSearch(selectedUid, appliedFilterRef.current);
634
+ }, [selectedUid]);
635
+ const handleApplySearch = () => {
636
+ const nextApplied = {
637
+ searchAttribute,
638
+ filterOperator,
639
+ filterQuery,
640
+ entrySearch
641
+ };
642
+ appliedFilterRef.current = nextApplied;
643
+ setAppliedFilter(nextApplied);
644
+ if (selectedUid) {
645
+ executeMatchingCountSearch(selectedUid, nextApplied);
646
+ }
647
+ };
648
+ const handleClearFilters = () => {
649
+ setSearchAttribute("");
650
+ setFilterOperator("none");
651
+ setFilterQuery("");
652
+ setEntrySearch("");
653
+ appliedFilterRef.current = EMPTY_SEARCH_FILTER;
654
+ setAppliedFilter(EMPTY_SEARCH_FILTER);
655
+ if (selectedUid) {
656
+ executeMatchingCountSearch(selectedUid, EMPTY_SEARCH_FILTER);
657
+ }
658
+ };
541
659
  const fetchAndEnrichEntries = async (colUid, cols = collections, batches = pendingBatches) => {
542
660
  if (!colUid) return [];
543
661
  try {
@@ -620,16 +738,11 @@ function CsvManagerTab() {
620
738
  if (!selectedUid || exportingCollection) return;
621
739
  try {
622
740
  setExportingCollection(true);
623
- const queryParams = new URLSearchParams();
624
- if (exportLimit > 0) queryParams.set("limit", String(exportLimit));
625
- if (searchAttribute) queryParams.set("searchAttribute", searchAttribute);
626
- if (filterOperator && filterOperator !== "none") {
627
- queryParams.set("filterOperator", filterOperator);
628
- if (filterQuery) queryParams.set("filterQuery", filterQuery);
629
- }
630
- if (entrySearch && entrySearch.trim()) {
631
- queryParams.set("search", entrySearch.trim());
632
- }
741
+ const queryParams = buildCsvExportQueryParams({
742
+ limit: exportLimit,
743
+ filter: appliedFilterRef.current,
744
+ exportMode
745
+ });
633
746
  const res = await get(`/bulk-updater/csv/export/${selectedUid}?${queryParams.toString()}`);
634
747
  const csvStr = res.data?.csvContent || (typeof res.data === "string" ? res.data : "");
635
748
  const filename = res.data?.filename || `${selectedUid.split(".").pop()}_export.csv`;
@@ -1099,20 +1212,8 @@ function CsvManagerTab() {
1099
1212
  ]
1100
1213
  }
1101
1214
  ) : null,
1102
- (searchAttribute || filterOperator !== "none" || entrySearch.trim()) && /* @__PURE__ */ jsxRuntime.jsx(
1103
- designSystem.Button,
1104
- {
1105
- variant: "ghost",
1106
- size: "S",
1107
- onClick: () => {
1108
- setSearchAttribute("");
1109
- setFilterOperator("none");
1110
- setFilterQuery("");
1111
- setEntrySearch("");
1112
- },
1113
- children: "Clear Filters"
1114
- }
1115
- )
1215
+ hasPendingFilterChanges && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "warning100", textColor: "warning700", size: "S", children: "Filters modified — click Search to apply" }),
1216
+ (searchAttribute || filterOperator !== "none" || entrySearch.trim() || hasPendingFilterChanges) && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "ghost", size: "S", onClick: handleClearFilters, children: "Clear Filters" })
1116
1217
  ] })
1117
1218
  ] }),
1118
1219
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
@@ -1198,7 +1299,13 @@ function CsvManagerTab() {
1198
1299
  {
1199
1300
  placeholder: "Type value to match...",
1200
1301
  value: filterQuery,
1201
- onChange: (e) => setFilterQuery(e.target.value)
1302
+ onChange: (e) => setFilterQuery(e.target.value),
1303
+ onKeyDown: (e) => {
1304
+ if (e.key === "Enter") {
1305
+ e.preventDefault();
1306
+ handleApplySearch();
1307
+ }
1308
+ }
1202
1309
  }
1203
1310
  )
1204
1311
  ] }),
@@ -1209,10 +1316,27 @@ function CsvManagerTab() {
1209
1316
  {
1210
1317
  placeholder: "Search title, name, or text across records...",
1211
1318
  value: entrySearch,
1212
- onChange: (e) => setEntrySearch(e.target.value)
1319
+ onChange: (e) => setEntrySearch(e.target.value),
1320
+ onKeyDown: (e) => {
1321
+ if (e.key === "Enter") {
1322
+ e.preventDefault();
1323
+ handleApplySearch();
1324
+ }
1325
+ }
1213
1326
  }
1214
1327
  )
1215
- ] })
1328
+ ] }),
1329
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
1330
+ designSystem.Button,
1331
+ {
1332
+ variant: hasPendingFilterChanges ? "default" : "secondary",
1333
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Search, {}),
1334
+ onClick: handleApplySearch,
1335
+ loading: countLoading,
1336
+ disabled: !selectedUid || countLoading,
1337
+ children: "Search"
1338
+ }
1339
+ ) })
1216
1340
  ] })
1217
1341
  ] }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 4, background: "neutral0", hasRadius: true, marginBottom: 4, style: { border: "1px solid #eaeaef", textAlign: "center" }, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "neutral500", children: "Please select a Target Collection Type above to configure search filters and export data." }) }),
1218
1342
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 4, wrap: "wrap", alignItems: "flex-end", marginTop: 3, children: [
@@ -1261,6 +1385,22 @@ function CsvManagerTab() {
1261
1385
  );
1262
1386
  }) })
1263
1387
  ] }),
1388
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { style: { width: 220 }, children: [
1389
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Object Export Mode" }),
1390
+ /* @__PURE__ */ jsxRuntime.jsxs(
1391
+ designSystem.SingleSelect,
1392
+ {
1393
+ value: exportMode,
1394
+ onChange: (val) => setExportMode(val === "metafields" || val === "topbarconfig" ? val : "all"),
1395
+ disabled: exportingCollection,
1396
+ children: [
1397
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "all", children: "All" }),
1398
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "metafields", children: "Metafields" }),
1399
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: "topbarconfig", children: "Topbarconfig" })
1400
+ ]
1401
+ }
1402
+ )
1403
+ ] }),
1264
1404
  /* @__PURE__ */ jsxRuntime.jsx(
1265
1405
  designSystem.Button,
1266
1406
  {
@@ -1297,7 +1437,8 @@ function CsvManagerTab() {
1297
1437
  }
1298
1438
  )
1299
1439
  ] })
1300
- ] })
1440
+ ] }),
1441
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 3, children: exportMode === "all" ? /* @__PURE__ */ jsxRuntime.jsx(designSystem.Alert, { closeLabel: "Close", variant: "warning", title: "Data Migration Export Mode", children: "All exports the complete collection data and is intended for data migration. Do not use this mode for routine updates. For targeted updates, select Metafields or Topbarconfig." }) : /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, background: "primary100", hasRadius: true, children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "pi", textColor: "primary700", children: exportMode === "metafields" ? "Exports metafields as individual first-level columns for targeted updates. Other fields retain their existing structure." : "Exports topbarconfig as individual first-level columns for targeted updates. Other fields retain their existing structure." }) }) })
1301
1442
  ] }),
1302
1443
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Box, { padding: 5, background: "neutral100", hasRadius: true, children: [
1303
1444
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "delta", tag: "h3", fontWeight: "bold", marginBottom: 2, children: "2. Import & Batch Override CSV" }),
@@ -1367,7 +1508,21 @@ function CsvManagerTab() {
1367
1508
  const totalRows = allParsedRecords.length;
1368
1509
  const missingDocIdCount = allParsedRecords.filter((row) => !extractDocId(row)).length;
1369
1510
  const updateCount = totalRows - missingDocIdCount;
1370
- const headers = Object.keys(allParsedRecords[0]);
1511
+ const headers = Object.keys(allParsedRecords[0]).filter(
1512
+ (h) => h !== "__bulk_updater_metadata" && h !== "_bulk_updater_metadata"
1513
+ );
1514
+ let detectedPreviewMode = "legacy";
1515
+ try {
1516
+ const rawMetaCell = allParsedRecords[0]["__bulk_updater_metadata"] || allParsedRecords[0]["_bulk_updater_metadata"];
1517
+ if (rawMetaCell) {
1518
+ const parsedMeta = typeof rawMetaCell === "string" ? JSON.parse(rawMetaCell) : rawMetaCell;
1519
+ if (parsedMeta?.exportMode) {
1520
+ detectedPreviewMode = String(parsedMeta.exportMode);
1521
+ }
1522
+ }
1523
+ } catch {
1524
+ }
1525
+ const modeDisplayLabel = detectedPreviewMode === "metafields" ? "Metafields (1-Level Targeted)" : detectedPreviewMode === "topbarconfig" ? "Topbarconfig (1-Level Targeted)" : detectedPreviewMode === "all" ? "All (Full Migration Export)" : "Legacy";
1371
1526
  const totalPages = Math.ceil(totalRows / previewPageSize) || 1;
1372
1527
  const safePage = Math.min(Math.max(1, previewPage), totalPages);
1373
1528
  const startIndex = (safePage - 1) * previewPageSize;
@@ -1392,7 +1547,11 @@ function CsvManagerTab() {
1392
1547
  missingDocIdCount > 0 ? `${missingDocIdCount.toLocaleString()} new entries (missing documentId)` : ""
1393
1548
  ] })
1394
1549
  ] }),
1395
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
1550
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, wrap: "wrap", children: [
1551
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "neutral150", textColor: "neutral700", children: [
1552
+ "Mode: ",
1553
+ modeDisplayLabel
1554
+ ] }),
1396
1555
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "primary100", textColor: "primary700", children: [
1397
1556
  "🔄 ",
1398
1557
  updateCount.toLocaleString(),
@@ -5748,7 +5907,27 @@ const BulkUpdater = () => {
5748
5907
  const [entrySearch, setEntrySearch] = React.useState("");
5749
5908
  const abortControllersRef = React.useRef({});
5750
5909
  const [statusFilter, setStatusFilter] = React.useState("all");
5751
- const isFilterActive = Boolean(searchAttribute && searchAttribute !== selectedAttribute) || filterOperator !== "none" && (["empty", "not_empty"].includes(filterOperator) || Boolean(filterQuery.trim())) || Boolean(entrySearch.trim()) || Boolean(statusFilter !== "all") || Boolean(useRegex && regexPattern.trim());
5910
+ const [appliedSearchFilter, setAppliedSearchFilter] = React.useState(EMPTY_SEARCH_FILTER);
5911
+ const appliedSearchFilterRef = React.useRef(EMPTY_SEARCH_FILTER);
5912
+ const draftSearchFilter = React.useMemo(
5913
+ () => ({
5914
+ searchAttribute,
5915
+ filterOperator,
5916
+ filterQuery,
5917
+ entrySearch,
5918
+ statusFilter,
5919
+ useRegex,
5920
+ regexPattern
5921
+ }),
5922
+ [searchAttribute, filterOperator, filterQuery, entrySearch, statusFilter, useRegex, regexPattern]
5923
+ );
5924
+ const hasPendingFilterChanges = React.useMemo(
5925
+ () => !areSearchFiltersEqual(draftSearchFilter, appliedSearchFilter, {
5926
+ includeWorkspaceExtras: true
5927
+ }),
5928
+ [draftSearchFilter, appliedSearchFilter]
5929
+ );
5930
+ const isFilterActive = isSearchFilterActive(appliedSearchFilter, selectedAttribute);
5752
5931
  const [lastResults, setLastResults] = React.useState(null);
5753
5932
  const [updateSummary, setUpdateSummary] = React.useState(null);
5754
5933
  const [collectionPages, setCollectionPages] = React.useState({});
@@ -5915,10 +6094,11 @@ const BulkUpdater = () => {
5915
6094
  const currentSort = collectionSorts[colUid] || { field: "createdAt", order: "desc" };
5916
6095
  const sortField = customSortField !== void 0 ? customSortField : currentSort.field;
5917
6096
  const sortOrder = customSortOrder !== void 0 ? customSortOrder : currentSort.order;
5918
- const op = overrideFilterOp !== void 0 ? overrideFilterOp : filterOperator;
5919
- const q = overrideFilterQuery !== void 0 ? overrideFilterQuery : filterQuery;
5920
- const s = overrideEntrySearch !== void 0 ? overrideEntrySearch : entrySearch;
5921
- const searchAttr = overrideSearchAttr !== void 0 ? overrideSearchAttr : searchAttribute;
6097
+ const appliedSnapshot = appliedSearchFilterRef.current;
6098
+ const op = overrideFilterOp !== void 0 ? overrideFilterOp : appliedSnapshot.filterOperator;
6099
+ const q = overrideFilterQuery !== void 0 ? overrideFilterQuery : appliedSnapshot.filterQuery;
6100
+ const s = overrideEntrySearch !== void 0 ? overrideEntrySearch : appliedSnapshot.entrySearch;
6101
+ const searchAttr = overrideSearchAttr !== void 0 ? overrideSearchAttr : appliedSnapshot.searchAttribute;
5922
6102
  setCollectionPages((prev) => ({
5923
6103
  ...prev,
5924
6104
  [colUid]: {
@@ -5926,34 +6106,30 @@ const BulkUpdater = () => {
5926
6106
  loading: true
5927
6107
  }
5928
6108
  }));
6109
+ let controller = null;
5929
6110
  try {
5930
- const params = new URLSearchParams({
5931
- page: String(targetPage),
5932
- pageSize: String(size)
6111
+ const params = buildEntriesQueryParams({
6112
+ page: targetPage,
6113
+ pageSize: size,
6114
+ filter: {
6115
+ searchAttribute: searchAttr,
6116
+ filterOperator: op,
6117
+ filterQuery: q,
6118
+ entrySearch: s
6119
+ },
6120
+ selectedAttribute,
6121
+ sortField,
6122
+ sortOrder
5933
6123
  });
5934
- if (selectedAttribute) params.set("attribute", selectedAttribute);
5935
- if (searchAttr && searchAttr !== selectedAttribute) {
5936
- params.set("searchAttribute", searchAttr);
5937
- }
5938
- if (op && op !== "none") {
5939
- params.set("filterOperator", op);
5940
- if (q) params.set("filterQuery", q);
5941
- }
5942
- if (s && s.trim()) {
5943
- params.set("search", s.trim());
5944
- }
5945
- if (sortField) {
5946
- params.set("sortField", sortField);
5947
- params.set("sortOrder", sortOrder);
5948
- }
5949
6124
  if (abortControllersRef.current[colUid]) {
5950
6125
  abortControllersRef.current[colUid].abort();
5951
6126
  }
5952
- const controller = new AbortController();
6127
+ controller = new AbortController();
5953
6128
  abortControllersRef.current[colUid] = controller;
5954
6129
  const res = await get(`/bulk-updater/collections/${colUid}/entries?${params.toString()}`, {
5955
6130
  signal: controller.signal
5956
6131
  });
6132
+ if (abortControllersRef.current[colUid] !== controller) return;
5957
6133
  if (res.data && (res.data.success || res.data.entries !== void 0)) {
5958
6134
  const fetchedEntries = res.data.entries || [];
5959
6135
  const pageNum = res.data.pagination?.page ?? targetPage ?? 1;
@@ -6001,13 +6177,15 @@ const BulkUpdater = () => {
6001
6177
  message: `Failed to load entries for ${colUid}: ${err?.message || "Network error"}`
6002
6178
  });
6003
6179
  }
6004
- setCollectionPages((prev) => ({
6005
- ...prev,
6006
- [colUid]: {
6007
- ...prev[colUid] || {},
6008
- loading: false
6009
- }
6010
- }));
6180
+ if (abortControllersRef.current[colUid] === controller) {
6181
+ setCollectionPages((prev) => ({
6182
+ ...prev,
6183
+ [colUid]: {
6184
+ ...prev[colUid] || {},
6185
+ loading: false
6186
+ }
6187
+ }));
6188
+ }
6011
6189
  }
6012
6190
  };
6013
6191
  const fetchAuditHistory = async () => {
@@ -6070,44 +6248,46 @@ const BulkUpdater = () => {
6070
6248
  fetchPendingBatches();
6071
6249
  }
6072
6250
  }, [activeTab]);
6073
- const isInitialFilterMount = React.useRef(true);
6074
- React.useEffect(() => {
6075
- if (isInitialFilterMount.current) {
6076
- isInitialFilterMount.current = false;
6077
- return;
6078
- }
6079
- const timer = setTimeout(() => {
6080
- if (selectedCollectionUid) {
6081
- const isFilterActiveNow = Boolean(searchAttribute && searchAttribute !== selectedAttribute) || filterOperator !== "none" && (["empty", "not_empty"].includes(filterOperator) || Boolean(filterQuery.trim())) || Boolean(entrySearch.trim()) || Boolean(useRegex && regexPattern.trim());
6082
- if (isFilterActiveNow) {
6083
- if (gridEditMode) {
6084
- setSelectedEntries((prev) => {
6085
- const retained = {};
6086
- Object.keys(gridEdits).forEach((k) => {
6087
- if (prev[k]) retained[k] = true;
6088
- });
6089
- return retained;
6090
- });
6091
- } else {
6092
- setSelectedEntries({});
6093
- }
6094
- }
6095
- loadCollectionPage(
6096
- selectedCollectionUid,
6097
- 1,
6098
- void 0,
6099
- void 0,
6100
- void 0,
6101
- filterOperator,
6102
- filterQuery,
6103
- entrySearch,
6104
- true,
6105
- searchAttribute
6106
- );
6251
+ const handleApplySearch = () => {
6252
+ const nextApplied = {
6253
+ searchAttribute,
6254
+ filterOperator,
6255
+ filterQuery,
6256
+ entrySearch,
6257
+ statusFilter,
6258
+ useRegex,
6259
+ regexPattern
6260
+ };
6261
+ appliedSearchFilterRef.current = nextApplied;
6262
+ setAppliedSearchFilter(nextApplied);
6263
+ if (!selectedCollectionUid) return;
6264
+ const isFilterActiveNow = isSearchFilterActive(nextApplied, selectedAttribute);
6265
+ if (isFilterActiveNow) {
6266
+ if (gridEditMode) {
6267
+ setSelectedEntries((prev) => {
6268
+ const retained = {};
6269
+ Object.keys(gridEdits).forEach((k) => {
6270
+ if (prev[k]) retained[k] = true;
6271
+ });
6272
+ return retained;
6273
+ });
6274
+ } else {
6275
+ setSelectedEntries({});
6107
6276
  }
6108
- }, 350);
6109
- return () => clearTimeout(timer);
6110
- }, [selectedCollectionUid, searchAttribute, filterOperator, filterQuery, entrySearch, useRegex, regexPattern]);
6277
+ }
6278
+ loadCollectionPage(
6279
+ selectedCollectionUid,
6280
+ 1,
6281
+ void 0,
6282
+ void 0,
6283
+ void 0,
6284
+ nextApplied.filterOperator,
6285
+ nextApplied.filterQuery,
6286
+ nextApplied.entrySearch,
6287
+ true,
6288
+ nextApplied.searchAttribute
6289
+ );
6290
+ };
6111
6291
  const KEY_SEP = "@@@";
6112
6292
  const selectedCol = React.useMemo(() => {
6113
6293
  if (!collections.length || !selectedCollectionUid) return null;
@@ -6248,6 +6428,12 @@ const BulkUpdater = () => {
6248
6428
  }
6249
6429
  setSelectedEntries({});
6250
6430
  setSearchAttribute("");
6431
+ const nextAppliedOnColSwitch = {
6432
+ ...appliedSearchFilterRef.current,
6433
+ searchAttribute: ""
6434
+ };
6435
+ appliedSearchFilterRef.current = nextAppliedOnColSwitch;
6436
+ setAppliedSearchFilter(nextAppliedOnColSwitch);
6251
6437
  if (!newUid || !newUid.trim()) {
6252
6438
  setAttributes([]);
6253
6439
  setSelectedAttribute("");
@@ -6267,7 +6453,18 @@ const BulkUpdater = () => {
6267
6453
  setSelectedRelationDocId("");
6268
6454
  setAttributeValue("");
6269
6455
  }
6270
- loadCollectionPage(newUid, 1, void 0, void 0, void 0, filterOperator, filterQuery, entrySearch, true, "");
6456
+ loadCollectionPage(
6457
+ newUid,
6458
+ 1,
6459
+ void 0,
6460
+ void 0,
6461
+ void 0,
6462
+ nextAppliedOnColSwitch.filterOperator,
6463
+ nextAppliedOnColSwitch.filterQuery,
6464
+ nextAppliedOnColSwitch.entrySearch,
6465
+ true,
6466
+ ""
6467
+ );
6271
6468
  };
6272
6469
  const handleAttributeChange = (newAttr) => {
6273
6470
  if (newAttr !== selectedAttribute) {
@@ -6355,20 +6552,6 @@ const BulkUpdater = () => {
6355
6552
  const handleSearchAttributeChange = (newAttr) => {
6356
6553
  const finalAttr = newAttr === "__default__" ? "" : newAttr;
6357
6554
  setSearchAttribute(finalAttr);
6358
- if (selectedCollectionUid) {
6359
- loadCollectionPage(
6360
- selectedCollectionUid,
6361
- 1,
6362
- void 0,
6363
- void 0,
6364
- void 0,
6365
- filterOperator,
6366
- filterQuery,
6367
- entrySearch,
6368
- true,
6369
- finalAttr
6370
- );
6371
- }
6372
6555
  };
6373
6556
  const handleCollectionPageSizeChange = (colUid, newSize) => {
6374
6557
  const capped = Math.min(500, Math.max(1, newSize));
@@ -6424,9 +6607,13 @@ const BulkUpdater = () => {
6424
6607
  };
6425
6608
  const entryMatchesFilter = (entry, attr) => {
6426
6609
  const matches = getAllNestedValues(entry, attr);
6427
- if (useRegex && regexPattern.trim()) {
6610
+ const activeOp = appliedSearchFilter.filterOperator;
6611
+ const activeQuery = appliedSearchFilter.filterQuery || "";
6612
+ const activeUseRegex = Boolean(appliedSearchFilter.useRegex);
6613
+ const activeRegexPattern = appliedSearchFilter.regexPattern || "";
6614
+ if (activeUseRegex && activeRegexPattern.trim()) {
6428
6615
  try {
6429
- const regex = new RegExp(regexPattern, "i");
6616
+ const regex = new RegExp(activeRegexPattern, "i");
6430
6617
  const anyRegexMatch = matches.some((m) => regex.test(formatDisplayValue(m.value)));
6431
6618
  if (!anyRegexMatch) {
6432
6619
  return false;
@@ -6434,22 +6621,22 @@ const BulkUpdater = () => {
6434
6621
  } catch {
6435
6622
  }
6436
6623
  }
6437
- if (filterOperator === "none") return true;
6624
+ if (activeOp === "none") return true;
6438
6625
  if (matches.length === 0) {
6439
- return filterOperator === "empty";
6626
+ return activeOp === "empty";
6440
6627
  }
6441
6628
  const checkMatch = (val) => {
6442
6629
  const displayStr = formatDisplayValue(val);
6443
6630
  const isValEmpty = val === void 0 || val === null || Array.isArray(val) && val.length === 0 || displayStr.trim() === "" || displayStr.trim().toLowerCase() === "(not set)" || displayStr.trim().toLowerCase() === "(empty / not set)" || displayStr.trim().toLowerCase() === "(empty / unlinked)";
6444
- if (filterOperator === "empty") return isValEmpty;
6445
- if (filterOperator === "not_empty") return !isValEmpty;
6631
+ if (activeOp === "empty") return isValEmpty;
6632
+ if (activeOp === "not_empty") return !isValEmpty;
6446
6633
  if (isValEmpty) return false;
6447
- const q = filterQuery.trim().toLowerCase();
6634
+ const q = activeQuery.trim().toLowerCase();
6448
6635
  if (!q) return true;
6449
6636
  const testString = (str) => {
6450
6637
  if (str === void 0 || str === null) return false;
6451
6638
  const s = String(str).trim().toLowerCase();
6452
- switch (filterOperator) {
6639
+ switch (activeOp) {
6453
6640
  case "equals":
6454
6641
  return s === q;
6455
6642
  case "contains":
@@ -6480,7 +6667,7 @@ const BulkUpdater = () => {
6480
6667
  }
6481
6668
  return testString(displayStr);
6482
6669
  };
6483
- if (filterOperator === "empty") {
6670
+ if (activeOp === "empty") {
6484
6671
  return matches.every((m) => checkMatch(m.value));
6485
6672
  }
6486
6673
  return matches.some((m) => checkMatch(m.value));
@@ -6491,10 +6678,11 @@ const BulkUpdater = () => {
6491
6678
  if (gridEditMode && gridFilterModifiedOnly) {
6492
6679
  raw = raw.filter((entry) => Boolean(gridEdits[`${col.uid}${KEY_SEP}${entry.documentId}`]));
6493
6680
  }
6494
- if (statusFilter === "all") return raw;
6681
+ const activeStatus = appliedSearchFilter.statusFilter || "all";
6682
+ if (activeStatus === "all") return raw;
6495
6683
  return raw.filter((entry) => {
6496
6684
  const lifecycle = getEntryLifecycleStatus(entry, col, pendingBatches);
6497
- return lifecycle.status === statusFilter;
6685
+ return lifecycle.status === activeStatus;
6498
6686
  });
6499
6687
  };
6500
6688
  const matchingEntriesCount = React__default.default.useMemo(() => {
@@ -6504,7 +6692,7 @@ const BulkUpdater = () => {
6504
6692
  count += getVisibleEntries(col).length;
6505
6693
  });
6506
6694
  return count;
6507
- }, [filteredCollections, collectionPages, isFilterActive, statusFilter, pendingBatches, gridEditMode, gridFilterModifiedOnly, gridEdits]);
6695
+ }, [filteredCollections, collectionPages, isFilterActive, appliedSearchFilter, pendingBatches, gridEditMode, gridFilterModifiedOnly, gridEdits]);
6508
6696
  const selectAllMatching = () => {
6509
6697
  const updated = { ...selectedEntries };
6510
6698
  filteredCollections.forEach((col) => {
@@ -6532,6 +6720,8 @@ const BulkUpdater = () => {
6532
6720
  setEntrySearch("");
6533
6721
  setStatusFilter("all");
6534
6722
  setRegexPattern("");
6723
+ appliedSearchFilterRef.current = EMPTY_SEARCH_FILTER;
6724
+ setAppliedSearchFilter(EMPTY_SEARCH_FILTER);
6535
6725
  if (gridEditMode) {
6536
6726
  setSelectedEntries((prev) => {
6537
6727
  const retained = {};
@@ -6931,17 +7121,18 @@ const BulkUpdater = () => {
6931
7121
  await fetchModels();
6932
7122
  await fetchAuditHistory();
6933
7123
  if (selectedCollectionUid) {
7124
+ const appliedNow = appliedSearchFilterRef.current;
6934
7125
  loadCollectionPage(
6935
7126
  selectedCollectionUid,
6936
7127
  collectionPages[selectedCollectionUid]?.page || 1,
6937
7128
  void 0,
6938
7129
  void 0,
6939
7130
  void 0,
6940
- filterOperator,
6941
- filterQuery,
6942
- entrySearch,
7131
+ appliedNow.filterOperator,
7132
+ appliedNow.filterQuery,
7133
+ appliedNow.entrySearch,
6943
7134
  false,
6944
- searchAttribute
7135
+ appliedNow.searchAttribute
6945
7136
  );
6946
7137
  }
6947
7138
  }
@@ -7641,14 +7832,15 @@ const BulkUpdater = () => {
7641
7832
  matchingEntriesCount === 1 ? "entry" : "entries",
7642
7833
  " found in database"
7643
7834
  ] }),
7644
- searchAttribute && searchAttribute !== selectedAttribute && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: [
7835
+ appliedSearchFilter.searchAttribute && appliedSearchFilter.searchAttribute !== selectedAttribute && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: [
7645
7836
  "Searching by: ",
7646
- searchAttribute,
7837
+ appliedSearchFilter.searchAttribute,
7647
7838
  " → Target to update: ",
7648
7839
  selectedAttribute
7649
- ] })
7840
+ ] }),
7841
+ hasPendingFilterChanges && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Badge, { backgroundColor: "warning100", textColor: "warning700", children: "Filters modified — click Search to apply" })
7650
7842
  ] }),
7651
- isFilterActive && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "ghost", size: "S", onClick: clearFilter, children: "Clear Search & Filter" })
7843
+ (isFilterActive || hasPendingFilterChanges || Boolean(searchAttribute) || filterOperator !== "none" || Boolean(entrySearch.trim()) || statusFilter !== "all" || Boolean(useRegex && regexPattern.trim())) && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "ghost", size: "S", onClick: clearFilter, children: "Clear Search & Filter" })
7652
7844
  ] }),
7653
7845
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
7654
7846
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: 280, minWidth: 230 }, children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { children: [
@@ -7717,7 +7909,13 @@ const BulkUpdater = () => {
7717
7909
  label: effectiveSearchAttribute ? `Value for "${effectiveSearchAttribute}"` : "Value to match",
7718
7910
  placeholder: "Type value to match...",
7719
7911
  value: filterQuery,
7720
- onChange: (e) => setFilterQuery(e.target.value)
7912
+ onChange: (e) => setFilterQuery(e.target.value),
7913
+ onKeyDown: (e) => {
7914
+ if (e.key === "Enter") {
7915
+ e.preventDefault();
7916
+ handleApplySearch();
7917
+ }
7918
+ }
7721
7919
  }
7722
7920
  ) }),
7723
7921
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { flex: 1, minWidth: 180 }, children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -7726,7 +7924,13 @@ const BulkUpdater = () => {
7726
7924
  label: "Full-text Entry Search",
7727
7925
  placeholder: "Search title, name, or text across records...",
7728
7926
  value: entrySearch,
7729
- onChange: (e) => setEntrySearch(e.target.value)
7927
+ onChange: (e) => setEntrySearch(e.target.value),
7928
+ onKeyDown: (e) => {
7929
+ if (e.key === "Enter") {
7930
+ e.preventDefault();
7931
+ handleApplySearch();
7932
+ }
7933
+ }
7730
7934
  }
7731
7935
  ) }),
7732
7936
  /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { style: { width: 190, minWidth: 160 }, children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -7745,6 +7949,17 @@ const BulkUpdater = () => {
7745
7949
  ]
7746
7950
  }
7747
7951
  ) }),
7952
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
7953
+ designSystem.Button,
7954
+ {
7955
+ variant: hasPendingFilterChanges ? "default" : "secondary",
7956
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(icons.Search, {}),
7957
+ onClick: handleApplySearch,
7958
+ loading: Boolean(selectedCollectionUid && collectionPages[selectedCollectionUid]?.loading),
7959
+ disabled: !selectedCollectionUid || Boolean(selectedCollectionUid && collectionPages[selectedCollectionUid]?.loading),
7960
+ children: "Search"
7961
+ }
7962
+ ) }),
7748
7963
  isFilterActive && /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, alignItems: "center", children: [
7749
7964
  /* @__PURE__ */ jsxRuntime.jsx(
7750
7965
  designSystem.Button,
@@ -9953,4 +10168,4 @@ exports.getNestedValue = getNestedValue;
9953
10168
  exports.getPropertyValue = getPropertyValue;
9954
10169
  exports.getSortOptionsForCollection = getSortOptionsForCollection;
9955
10170
  exports.parseDynamicZonePath = parseDynamicZonePath;
9956
- //# sourceMappingURL=BulkUpdater-D12SUhTd.js.map
10171
+ //# sourceMappingURL=BulkUpdater-Y09TGkcC.js.map