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.
@@ -1,8 +1,8 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
2
  import React__default, { useRef, useState, useEffect, useMemo } from "react";
3
3
  import { useFetchClient, useNotification } from "@strapi/strapi/admin";
4
- import { Box, Flex, Typography, Button, Combobox, ComboboxOption, Badge, SingleSelect, SingleSelectOption, TextInput, Checkbox, Alert, Table, Thead, Tr, Th, Tbody, Td, Loader, Textarea, Field } from "@strapi/design-system";
5
- import { ArrowClockwise, Download, Upload, ChevronLeft, ChevronRight, Eye, Check, Search, Cog, Play } from "@strapi/icons";
4
+ import { Box, Flex, Typography, Button, Combobox, ComboboxOption, Badge, SingleSelect, SingleSelectOption, TextInput, Alert, Checkbox, Table, Thead, Tr, Th, Tbody, Td, Loader, Textarea, Field } from "@strapi/design-system";
5
+ import { ArrowClockwise, Download, Search, Upload, ChevronLeft, ChevronRight, Eye, Check, Cog, Play } from "@strapi/icons";
6
6
  import { i as isAbortError, V as ValidationRulesTab } from "./ValidationRulesTab-BtOCWK8E.mjs";
7
7
  function parseCsvRows(csvText) {
8
8
  if (!csvText) return [];
@@ -350,6 +350,89 @@ function getEntryLifecycleStatus(entry, col, pendingBatches = []) {
350
350
  textColor: "neutral700"
351
351
  };
352
352
  }
353
+ const EMPTY_SEARCH_FILTER = {
354
+ searchAttribute: "",
355
+ filterOperator: "none",
356
+ filterQuery: "",
357
+ entrySearch: "",
358
+ statusFilter: "all",
359
+ useRegex: false,
360
+ regexPattern: ""
361
+ };
362
+ function areSearchFiltersEqual(a, b, options = {}) {
363
+ if ((a.searchAttribute || "") !== (b.searchAttribute || "") || (a.filterOperator || "none") !== (b.filterOperator || "none") || (a.filterQuery || "") !== (b.filterQuery || "") || (a.entrySearch || "") !== (b.entrySearch || "")) {
364
+ return false;
365
+ }
366
+ if (options.includeWorkspaceExtras) {
367
+ if ((a.statusFilter || "all") !== (b.statusFilter || "all") || Boolean(a.useRegex) !== Boolean(b.useRegex) || (a.regexPattern || "") !== (b.regexPattern || "")) {
368
+ return false;
369
+ }
370
+ }
371
+ return true;
372
+ }
373
+ function isSearchFilterActive(filter, selectedTargetAttribute = "") {
374
+ const hasAttrFilter = Boolean(filter.searchAttribute && filter.searchAttribute !== selectedTargetAttribute);
375
+ const hasOp = filter.filterOperator !== "none" && (["empty", "not_empty"].includes(filter.filterOperator) || Boolean((filter.filterQuery || "").trim()));
376
+ const hasSearchText = Boolean((filter.entrySearch || "").trim());
377
+ const hasStatus = Boolean(filter.statusFilter && filter.statusFilter !== "all");
378
+ const hasRegex = Boolean(filter.useRegex && (filter.regexPattern || "").trim());
379
+ return hasAttrFilter || hasOp || hasSearchText || hasStatus || hasRegex;
380
+ }
381
+ function buildEntriesQueryParams(options) {
382
+ const { page, pageSize, filter, selectedAttribute, sortField, sortOrder, includeAttributeEvenIfSame } = options;
383
+ const params = new URLSearchParams({
384
+ page: String(page),
385
+ pageSize: String(pageSize)
386
+ });
387
+ if (includeAttributeEvenIfSame) {
388
+ if (filter.searchAttribute) {
389
+ params.set("attribute", filter.searchAttribute);
390
+ params.set("searchAttribute", filter.searchAttribute);
391
+ }
392
+ } else {
393
+ if (selectedAttribute) params.set("attribute", selectedAttribute);
394
+ if (filter.searchAttribute && filter.searchAttribute !== selectedAttribute) {
395
+ params.set("searchAttribute", filter.searchAttribute);
396
+ }
397
+ }
398
+ if (filter.filterOperator && filter.filterOperator !== "none") {
399
+ params.set("filterOperator", filter.filterOperator);
400
+ if (filter.filterQuery) {
401
+ params.set("filterQuery", filter.filterQuery);
402
+ }
403
+ }
404
+ if (filter.entrySearch && filter.entrySearch.trim()) {
405
+ params.set("search", filter.entrySearch.trim());
406
+ }
407
+ if (sortField) {
408
+ params.set("sortField", sortField);
409
+ if (sortOrder) params.set("sortOrder", sortOrder);
410
+ }
411
+ return params;
412
+ }
413
+ function buildCsvExportQueryParams(options) {
414
+ const { limit, filter, exportMode } = options;
415
+ const queryParams = new URLSearchParams();
416
+ if (limit && limit > 0) {
417
+ queryParams.set("limit", String(limit));
418
+ }
419
+ if (exportMode) {
420
+ queryParams.set("exportMode", exportMode);
421
+ }
422
+ if (filter.searchAttribute) {
423
+ queryParams.set("searchAttribute", filter.searchAttribute);
424
+ }
425
+ if (filter.filterOperator && filter.filterOperator !== "none") {
426
+ queryParams.set("filterOperator", filter.filterOperator);
427
+ if (filter.filterQuery) {
428
+ queryParams.set("filterQuery", filter.filterQuery);
429
+ }
430
+ }
431
+ if (filter.entrySearch && filter.entrySearch.trim()) {
432
+ queryParams.set("search", filter.entrySearch.trim());
433
+ }
434
+ return queryParams;
435
+ }
353
436
  function CsvManagerTab() {
354
437
  const { get, post } = useFetchClient();
355
438
  const { toggleNotification } = useNotification();
@@ -366,10 +449,20 @@ function CsvManagerTab() {
366
449
  const [filterOperator, setFilterOperator] = useState("none");
367
450
  const [filterQuery, setFilterQuery] = useState("");
368
451
  const [entrySearch, setEntrySearch] = useState("");
452
+ const [appliedFilter, setAppliedFilter] = useState(EMPTY_SEARCH_FILTER);
453
+ const appliedFilterRef = useRef(EMPTY_SEARCH_FILTER);
369
454
  const [matchingCount, setMatchingCount] = useState(null);
370
455
  const [countLoading, setCountLoading] = useState(false);
456
+ const draftFilter = {
457
+ searchAttribute,
458
+ filterOperator,
459
+ filterQuery,
460
+ entrySearch
461
+ };
462
+ const hasPendingFilterChanges = !areSearchFiltersEqual(draftFilter, appliedFilter);
371
463
  const [searchRelationOptions, setSearchRelationOptions] = useState([]);
372
464
  const [searchRelationOptionsLoading, setSearchRelationOptionsLoading] = useState(false);
465
+ const [exportMode, setExportMode] = useState("all");
373
466
  const [exportLimit, setExportLimit] = useState(0);
374
467
  const [exportLimitInput, setExportLimitInput] = useState("");
375
468
  const [exportingCollection, setExportingCollection] = useState(false);
@@ -487,53 +580,78 @@ function CsvManagerTab() {
487
580
  setFilterOperator("none");
488
581
  setFilterQuery("");
489
582
  setEntrySearch("");
583
+ appliedFilterRef.current = EMPTY_SEARCH_FILTER;
584
+ setAppliedFilter(EMPTY_SEARCH_FILTER);
490
585
  setMatchingCount(null);
491
586
  setCountLoading(Boolean(newUid));
492
587
  };
493
- useEffect(() => {
494
- if (!selectedUid) {
588
+ const executeMatchingCountSearch = async (targetUid, filterToApply) => {
589
+ if (!targetUid) {
495
590
  setMatchingCount(null);
496
591
  setCountLoading(false);
497
592
  return;
498
593
  }
594
+ if (countAbortControllerRef.current) {
595
+ countAbortControllerRef.current.abort();
596
+ }
597
+ const controller = new AbortController();
598
+ countAbortControllerRef.current = controller;
499
599
  setCountLoading(true);
500
- const timer = setTimeout(async () => {
501
- if (countAbortControllerRef.current) {
502
- countAbortControllerRef.current.abort();
600
+ try {
601
+ const params = buildEntriesQueryParams({
602
+ page: 1,
603
+ pageSize: 1,
604
+ filter: filterToApply,
605
+ includeAttributeEvenIfSame: true
606
+ });
607
+ const res = await get(`/bulk-updater/collections/${targetUid}/entries?${params.toString()}`, {
608
+ signal: controller.signal
609
+ });
610
+ if (countAbortControllerRef.current !== controller) return;
611
+ if (res.data) {
612
+ const total = res.data.pagination?.total ?? (Array.isArray(res.data.entries) ? res.data.entries.length : 0);
613
+ setMatchingCount(total);
503
614
  }
504
- const controller = new AbortController();
505
- countAbortControllerRef.current = controller;
506
- try {
507
- const params = new URLSearchParams({
508
- page: "1",
509
- pageSize: "1"
510
- });
511
- if (searchAttribute) {
512
- params.set("attribute", searchAttribute);
513
- params.set("searchAttribute", searchAttribute);
514
- }
515
- if (filterOperator && filterOperator !== "none") {
516
- params.set("filterOperator", filterOperator);
517
- if (filterQuery) params.set("filterQuery", filterQuery);
518
- }
519
- if (entrySearch && entrySearch.trim()) {
520
- params.set("search", entrySearch.trim());
521
- }
522
- const res = await get(`/bulk-updater/collections/${selectedUid}/entries?${params.toString()}`, {
523
- signal: controller.signal
524
- });
525
- if (res.data) {
526
- const total = res.data.pagination?.total ?? (Array.isArray(res.data.entries) ? res.data.entries.length : 0);
527
- setMatchingCount(total);
528
- }
529
- } catch (err) {
530
- if (!isAbortError(err)) ;
531
- } finally {
615
+ } catch (err) {
616
+ if (!isAbortError(err)) ;
617
+ } finally {
618
+ if (countAbortControllerRef.current === controller) {
532
619
  setCountLoading(false);
533
620
  }
534
- }, 300);
535
- return () => clearTimeout(timer);
536
- }, [selectedUid, searchAttribute, filterOperator, filterQuery, entrySearch]);
621
+ }
622
+ };
623
+ useEffect(() => {
624
+ if (!selectedUid) {
625
+ setMatchingCount(null);
626
+ setCountLoading(false);
627
+ return;
628
+ }
629
+ executeMatchingCountSearch(selectedUid, appliedFilterRef.current);
630
+ }, [selectedUid]);
631
+ const handleApplySearch = () => {
632
+ const nextApplied = {
633
+ searchAttribute,
634
+ filterOperator,
635
+ filterQuery,
636
+ entrySearch
637
+ };
638
+ appliedFilterRef.current = nextApplied;
639
+ setAppliedFilter(nextApplied);
640
+ if (selectedUid) {
641
+ executeMatchingCountSearch(selectedUid, nextApplied);
642
+ }
643
+ };
644
+ const handleClearFilters = () => {
645
+ setSearchAttribute("");
646
+ setFilterOperator("none");
647
+ setFilterQuery("");
648
+ setEntrySearch("");
649
+ appliedFilterRef.current = EMPTY_SEARCH_FILTER;
650
+ setAppliedFilter(EMPTY_SEARCH_FILTER);
651
+ if (selectedUid) {
652
+ executeMatchingCountSearch(selectedUid, EMPTY_SEARCH_FILTER);
653
+ }
654
+ };
537
655
  const fetchAndEnrichEntries = async (colUid, cols = collections, batches = pendingBatches) => {
538
656
  if (!colUid) return [];
539
657
  try {
@@ -616,16 +734,11 @@ function CsvManagerTab() {
616
734
  if (!selectedUid || exportingCollection) return;
617
735
  try {
618
736
  setExportingCollection(true);
619
- const queryParams = new URLSearchParams();
620
- if (exportLimit > 0) queryParams.set("limit", String(exportLimit));
621
- if (searchAttribute) queryParams.set("searchAttribute", searchAttribute);
622
- if (filterOperator && filterOperator !== "none") {
623
- queryParams.set("filterOperator", filterOperator);
624
- if (filterQuery) queryParams.set("filterQuery", filterQuery);
625
- }
626
- if (entrySearch && entrySearch.trim()) {
627
- queryParams.set("search", entrySearch.trim());
628
- }
737
+ const queryParams = buildCsvExportQueryParams({
738
+ limit: exportLimit,
739
+ filter: appliedFilterRef.current,
740
+ exportMode
741
+ });
629
742
  const res = await get(`/bulk-updater/csv/export/${selectedUid}?${queryParams.toString()}`);
630
743
  const csvStr = res.data?.csvContent || (typeof res.data === "string" ? res.data : "");
631
744
  const filename = res.data?.filename || `${selectedUid.split(".").pop()}_export.csv`;
@@ -1095,20 +1208,8 @@ function CsvManagerTab() {
1095
1208
  ]
1096
1209
  }
1097
1210
  ) : null,
1098
- (searchAttribute || filterOperator !== "none" || entrySearch.trim()) && /* @__PURE__ */ jsx(
1099
- Button,
1100
- {
1101
- variant: "ghost",
1102
- size: "S",
1103
- onClick: () => {
1104
- setSearchAttribute("");
1105
- setFilterOperator("none");
1106
- setFilterQuery("");
1107
- setEntrySearch("");
1108
- },
1109
- children: "Clear Filters"
1110
- }
1111
- )
1211
+ hasPendingFilterChanges && /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", size: "S", children: "Filters modified — click Search to apply" }),
1212
+ (searchAttribute || filterOperator !== "none" || entrySearch.trim() || hasPendingFilterChanges) && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "S", onClick: handleClearFilters, children: "Clear Filters" })
1112
1213
  ] })
1113
1214
  ] }),
1114
1215
  /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
@@ -1194,7 +1295,13 @@ function CsvManagerTab() {
1194
1295
  {
1195
1296
  placeholder: "Type value to match...",
1196
1297
  value: filterQuery,
1197
- onChange: (e) => setFilterQuery(e.target.value)
1298
+ onChange: (e) => setFilterQuery(e.target.value),
1299
+ onKeyDown: (e) => {
1300
+ if (e.key === "Enter") {
1301
+ e.preventDefault();
1302
+ handleApplySearch();
1303
+ }
1304
+ }
1198
1305
  }
1199
1306
  )
1200
1307
  ] }),
@@ -1205,10 +1312,27 @@ function CsvManagerTab() {
1205
1312
  {
1206
1313
  placeholder: "Search title, name, or text across records...",
1207
1314
  value: entrySearch,
1208
- onChange: (e) => setEntrySearch(e.target.value)
1315
+ onChange: (e) => setEntrySearch(e.target.value),
1316
+ onKeyDown: (e) => {
1317
+ if (e.key === "Enter") {
1318
+ e.preventDefault();
1319
+ handleApplySearch();
1320
+ }
1321
+ }
1209
1322
  }
1210
1323
  )
1211
- ] })
1324
+ ] }),
1325
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
1326
+ Button,
1327
+ {
1328
+ variant: hasPendingFilterChanges ? "default" : "secondary",
1329
+ startIcon: /* @__PURE__ */ jsx(Search, {}),
1330
+ onClick: handleApplySearch,
1331
+ loading: countLoading,
1332
+ disabled: !selectedUid || countLoading,
1333
+ children: "Search"
1334
+ }
1335
+ ) })
1212
1336
  ] })
1213
1337
  ] }) : /* @__PURE__ */ jsx(Box, { padding: 4, background: "neutral0", hasRadius: true, marginBottom: 4, style: { border: "1px solid #eaeaef", textAlign: "center" }, children: /* @__PURE__ */ jsx(Typography, { variant: "pi", textColor: "neutral500", children: "Please select a Target Collection Type above to configure search filters and export data." }) }),
1214
1338
  /* @__PURE__ */ jsxs(Flex, { gap: 4, wrap: "wrap", alignItems: "flex-end", marginTop: 3, children: [
@@ -1257,6 +1381,22 @@ function CsvManagerTab() {
1257
1381
  );
1258
1382
  }) })
1259
1383
  ] }),
1384
+ /* @__PURE__ */ jsxs(Box, { style: { width: 220 }, children: [
1385
+ /* @__PURE__ */ jsx(Typography, { variant: "pi", fontWeight: "bold", textColor: "neutral800", marginBottom: 1, display: "block", children: "Object Export Mode" }),
1386
+ /* @__PURE__ */ jsxs(
1387
+ SingleSelect,
1388
+ {
1389
+ value: exportMode,
1390
+ onChange: (val) => setExportMode(val === "metafields" || val === "topbarconfig" ? val : "all"),
1391
+ disabled: exportingCollection,
1392
+ children: [
1393
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "all", children: "All" }),
1394
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "metafields", children: "Metafields" }),
1395
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "topbarconfig", children: "Topbarconfig" })
1396
+ ]
1397
+ }
1398
+ )
1399
+ ] }),
1260
1400
  /* @__PURE__ */ jsx(
1261
1401
  Button,
1262
1402
  {
@@ -1293,7 +1433,8 @@ function CsvManagerTab() {
1293
1433
  }
1294
1434
  )
1295
1435
  ] })
1296
- ] })
1436
+ ] }),
1437
+ /* @__PURE__ */ jsx(Box, { marginTop: 3, children: exportMode === "all" ? /* @__PURE__ */ jsx(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__ */ jsx(Box, { padding: 3, background: "primary100", hasRadius: true, children: /* @__PURE__ */ jsx(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." }) }) })
1297
1438
  ] }),
1298
1439
  /* @__PURE__ */ jsxs(Box, { padding: 5, background: "neutral100", hasRadius: true, children: [
1299
1440
  /* @__PURE__ */ jsx(Typography, { variant: "delta", tag: "h3", fontWeight: "bold", marginBottom: 2, children: "2. Import & Batch Override CSV" }),
@@ -1363,7 +1504,21 @@ function CsvManagerTab() {
1363
1504
  const totalRows = allParsedRecords.length;
1364
1505
  const missingDocIdCount = allParsedRecords.filter((row) => !extractDocId(row)).length;
1365
1506
  const updateCount = totalRows - missingDocIdCount;
1366
- const headers = Object.keys(allParsedRecords[0]);
1507
+ const headers = Object.keys(allParsedRecords[0]).filter(
1508
+ (h) => h !== "__bulk_updater_metadata" && h !== "_bulk_updater_metadata"
1509
+ );
1510
+ let detectedPreviewMode = "legacy";
1511
+ try {
1512
+ const rawMetaCell = allParsedRecords[0]["__bulk_updater_metadata"] || allParsedRecords[0]["_bulk_updater_metadata"];
1513
+ if (rawMetaCell) {
1514
+ const parsedMeta = typeof rawMetaCell === "string" ? JSON.parse(rawMetaCell) : rawMetaCell;
1515
+ if (parsedMeta?.exportMode) {
1516
+ detectedPreviewMode = String(parsedMeta.exportMode);
1517
+ }
1518
+ }
1519
+ } catch {
1520
+ }
1521
+ const modeDisplayLabel = detectedPreviewMode === "metafields" ? "Metafields (1-Level Targeted)" : detectedPreviewMode === "topbarconfig" ? "Topbarconfig (1-Level Targeted)" : detectedPreviewMode === "all" ? "All (Full Migration Export)" : "Legacy";
1367
1522
  const totalPages = Math.ceil(totalRows / previewPageSize) || 1;
1368
1523
  const safePage = Math.min(Math.max(1, previewPage), totalPages);
1369
1524
  const startIndex = (safePage - 1) * previewPageSize;
@@ -1388,7 +1543,11 @@ function CsvManagerTab() {
1388
1543
  missingDocIdCount > 0 ? `${missingDocIdCount.toLocaleString()} new entries (missing documentId)` : ""
1389
1544
  ] })
1390
1545
  ] }),
1391
- /* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
1546
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, wrap: "wrap", children: [
1547
+ /* @__PURE__ */ jsxs(Badge, { backgroundColor: "neutral150", textColor: "neutral700", children: [
1548
+ "Mode: ",
1549
+ modeDisplayLabel
1550
+ ] }),
1392
1551
  /* @__PURE__ */ jsxs(Badge, { backgroundColor: "primary100", textColor: "primary700", children: [
1393
1552
  "🔄 ",
1394
1553
  updateCount.toLocaleString(),
@@ -5744,7 +5903,27 @@ const BulkUpdater = () => {
5744
5903
  const [entrySearch, setEntrySearch] = useState("");
5745
5904
  const abortControllersRef = useRef({});
5746
5905
  const [statusFilter, setStatusFilter] = useState("all");
5747
- 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());
5906
+ const [appliedSearchFilter, setAppliedSearchFilter] = useState(EMPTY_SEARCH_FILTER);
5907
+ const appliedSearchFilterRef = useRef(EMPTY_SEARCH_FILTER);
5908
+ const draftSearchFilter = useMemo(
5909
+ () => ({
5910
+ searchAttribute,
5911
+ filterOperator,
5912
+ filterQuery,
5913
+ entrySearch,
5914
+ statusFilter,
5915
+ useRegex,
5916
+ regexPattern
5917
+ }),
5918
+ [searchAttribute, filterOperator, filterQuery, entrySearch, statusFilter, useRegex, regexPattern]
5919
+ );
5920
+ const hasPendingFilterChanges = useMemo(
5921
+ () => !areSearchFiltersEqual(draftSearchFilter, appliedSearchFilter, {
5922
+ includeWorkspaceExtras: true
5923
+ }),
5924
+ [draftSearchFilter, appliedSearchFilter]
5925
+ );
5926
+ const isFilterActive = isSearchFilterActive(appliedSearchFilter, selectedAttribute);
5748
5927
  const [lastResults, setLastResults] = useState(null);
5749
5928
  const [updateSummary, setUpdateSummary] = useState(null);
5750
5929
  const [collectionPages, setCollectionPages] = useState({});
@@ -5911,10 +6090,11 @@ const BulkUpdater = () => {
5911
6090
  const currentSort = collectionSorts[colUid] || { field: "createdAt", order: "desc" };
5912
6091
  const sortField = customSortField !== void 0 ? customSortField : currentSort.field;
5913
6092
  const sortOrder = customSortOrder !== void 0 ? customSortOrder : currentSort.order;
5914
- const op = overrideFilterOp !== void 0 ? overrideFilterOp : filterOperator;
5915
- const q = overrideFilterQuery !== void 0 ? overrideFilterQuery : filterQuery;
5916
- const s = overrideEntrySearch !== void 0 ? overrideEntrySearch : entrySearch;
5917
- const searchAttr = overrideSearchAttr !== void 0 ? overrideSearchAttr : searchAttribute;
6093
+ const appliedSnapshot = appliedSearchFilterRef.current;
6094
+ const op = overrideFilterOp !== void 0 ? overrideFilterOp : appliedSnapshot.filterOperator;
6095
+ const q = overrideFilterQuery !== void 0 ? overrideFilterQuery : appliedSnapshot.filterQuery;
6096
+ const s = overrideEntrySearch !== void 0 ? overrideEntrySearch : appliedSnapshot.entrySearch;
6097
+ const searchAttr = overrideSearchAttr !== void 0 ? overrideSearchAttr : appliedSnapshot.searchAttribute;
5918
6098
  setCollectionPages((prev) => ({
5919
6099
  ...prev,
5920
6100
  [colUid]: {
@@ -5922,34 +6102,30 @@ const BulkUpdater = () => {
5922
6102
  loading: true
5923
6103
  }
5924
6104
  }));
6105
+ let controller = null;
5925
6106
  try {
5926
- const params = new URLSearchParams({
5927
- page: String(targetPage),
5928
- pageSize: String(size)
6107
+ const params = buildEntriesQueryParams({
6108
+ page: targetPage,
6109
+ pageSize: size,
6110
+ filter: {
6111
+ searchAttribute: searchAttr,
6112
+ filterOperator: op,
6113
+ filterQuery: q,
6114
+ entrySearch: s
6115
+ },
6116
+ selectedAttribute,
6117
+ sortField,
6118
+ sortOrder
5929
6119
  });
5930
- if (selectedAttribute) params.set("attribute", selectedAttribute);
5931
- if (searchAttr && searchAttr !== selectedAttribute) {
5932
- params.set("searchAttribute", searchAttr);
5933
- }
5934
- if (op && op !== "none") {
5935
- params.set("filterOperator", op);
5936
- if (q) params.set("filterQuery", q);
5937
- }
5938
- if (s && s.trim()) {
5939
- params.set("search", s.trim());
5940
- }
5941
- if (sortField) {
5942
- params.set("sortField", sortField);
5943
- params.set("sortOrder", sortOrder);
5944
- }
5945
6120
  if (abortControllersRef.current[colUid]) {
5946
6121
  abortControllersRef.current[colUid].abort();
5947
6122
  }
5948
- const controller = new AbortController();
6123
+ controller = new AbortController();
5949
6124
  abortControllersRef.current[colUid] = controller;
5950
6125
  const res = await get(`/bulk-updater/collections/${colUid}/entries?${params.toString()}`, {
5951
6126
  signal: controller.signal
5952
6127
  });
6128
+ if (abortControllersRef.current[colUid] !== controller) return;
5953
6129
  if (res.data && (res.data.success || res.data.entries !== void 0)) {
5954
6130
  const fetchedEntries = res.data.entries || [];
5955
6131
  const pageNum = res.data.pagination?.page ?? targetPage ?? 1;
@@ -5997,13 +6173,15 @@ const BulkUpdater = () => {
5997
6173
  message: `Failed to load entries for ${colUid}: ${err?.message || "Network error"}`
5998
6174
  });
5999
6175
  }
6000
- setCollectionPages((prev) => ({
6001
- ...prev,
6002
- [colUid]: {
6003
- ...prev[colUid] || {},
6004
- loading: false
6005
- }
6006
- }));
6176
+ if (abortControllersRef.current[colUid] === controller) {
6177
+ setCollectionPages((prev) => ({
6178
+ ...prev,
6179
+ [colUid]: {
6180
+ ...prev[colUid] || {},
6181
+ loading: false
6182
+ }
6183
+ }));
6184
+ }
6007
6185
  }
6008
6186
  };
6009
6187
  const fetchAuditHistory = async () => {
@@ -6066,44 +6244,46 @@ const BulkUpdater = () => {
6066
6244
  fetchPendingBatches();
6067
6245
  }
6068
6246
  }, [activeTab]);
6069
- const isInitialFilterMount = useRef(true);
6070
- useEffect(() => {
6071
- if (isInitialFilterMount.current) {
6072
- isInitialFilterMount.current = false;
6073
- return;
6074
- }
6075
- const timer = setTimeout(() => {
6076
- if (selectedCollectionUid) {
6077
- const isFilterActiveNow = Boolean(searchAttribute && searchAttribute !== selectedAttribute) || filterOperator !== "none" && (["empty", "not_empty"].includes(filterOperator) || Boolean(filterQuery.trim())) || Boolean(entrySearch.trim()) || Boolean(useRegex && regexPattern.trim());
6078
- if (isFilterActiveNow) {
6079
- if (gridEditMode) {
6080
- setSelectedEntries((prev) => {
6081
- const retained = {};
6082
- Object.keys(gridEdits).forEach((k) => {
6083
- if (prev[k]) retained[k] = true;
6084
- });
6085
- return retained;
6086
- });
6087
- } else {
6088
- setSelectedEntries({});
6089
- }
6090
- }
6091
- loadCollectionPage(
6092
- selectedCollectionUid,
6093
- 1,
6094
- void 0,
6095
- void 0,
6096
- void 0,
6097
- filterOperator,
6098
- filterQuery,
6099
- entrySearch,
6100
- true,
6101
- searchAttribute
6102
- );
6247
+ const handleApplySearch = () => {
6248
+ const nextApplied = {
6249
+ searchAttribute,
6250
+ filterOperator,
6251
+ filterQuery,
6252
+ entrySearch,
6253
+ statusFilter,
6254
+ useRegex,
6255
+ regexPattern
6256
+ };
6257
+ appliedSearchFilterRef.current = nextApplied;
6258
+ setAppliedSearchFilter(nextApplied);
6259
+ if (!selectedCollectionUid) return;
6260
+ const isFilterActiveNow = isSearchFilterActive(nextApplied, selectedAttribute);
6261
+ if (isFilterActiveNow) {
6262
+ if (gridEditMode) {
6263
+ setSelectedEntries((prev) => {
6264
+ const retained = {};
6265
+ Object.keys(gridEdits).forEach((k) => {
6266
+ if (prev[k]) retained[k] = true;
6267
+ });
6268
+ return retained;
6269
+ });
6270
+ } else {
6271
+ setSelectedEntries({});
6103
6272
  }
6104
- }, 350);
6105
- return () => clearTimeout(timer);
6106
- }, [selectedCollectionUid, searchAttribute, filterOperator, filterQuery, entrySearch, useRegex, regexPattern]);
6273
+ }
6274
+ loadCollectionPage(
6275
+ selectedCollectionUid,
6276
+ 1,
6277
+ void 0,
6278
+ void 0,
6279
+ void 0,
6280
+ nextApplied.filterOperator,
6281
+ nextApplied.filterQuery,
6282
+ nextApplied.entrySearch,
6283
+ true,
6284
+ nextApplied.searchAttribute
6285
+ );
6286
+ };
6107
6287
  const KEY_SEP = "@@@";
6108
6288
  const selectedCol = useMemo(() => {
6109
6289
  if (!collections.length || !selectedCollectionUid) return null;
@@ -6244,6 +6424,12 @@ const BulkUpdater = () => {
6244
6424
  }
6245
6425
  setSelectedEntries({});
6246
6426
  setSearchAttribute("");
6427
+ const nextAppliedOnColSwitch = {
6428
+ ...appliedSearchFilterRef.current,
6429
+ searchAttribute: ""
6430
+ };
6431
+ appliedSearchFilterRef.current = nextAppliedOnColSwitch;
6432
+ setAppliedSearchFilter(nextAppliedOnColSwitch);
6247
6433
  if (!newUid || !newUid.trim()) {
6248
6434
  setAttributes([]);
6249
6435
  setSelectedAttribute("");
@@ -6263,7 +6449,18 @@ const BulkUpdater = () => {
6263
6449
  setSelectedRelationDocId("");
6264
6450
  setAttributeValue("");
6265
6451
  }
6266
- loadCollectionPage(newUid, 1, void 0, void 0, void 0, filterOperator, filterQuery, entrySearch, true, "");
6452
+ loadCollectionPage(
6453
+ newUid,
6454
+ 1,
6455
+ void 0,
6456
+ void 0,
6457
+ void 0,
6458
+ nextAppliedOnColSwitch.filterOperator,
6459
+ nextAppliedOnColSwitch.filterQuery,
6460
+ nextAppliedOnColSwitch.entrySearch,
6461
+ true,
6462
+ ""
6463
+ );
6267
6464
  };
6268
6465
  const handleAttributeChange = (newAttr) => {
6269
6466
  if (newAttr !== selectedAttribute) {
@@ -6351,20 +6548,6 @@ const BulkUpdater = () => {
6351
6548
  const handleSearchAttributeChange = (newAttr) => {
6352
6549
  const finalAttr = newAttr === "__default__" ? "" : newAttr;
6353
6550
  setSearchAttribute(finalAttr);
6354
- if (selectedCollectionUid) {
6355
- loadCollectionPage(
6356
- selectedCollectionUid,
6357
- 1,
6358
- void 0,
6359
- void 0,
6360
- void 0,
6361
- filterOperator,
6362
- filterQuery,
6363
- entrySearch,
6364
- true,
6365
- finalAttr
6366
- );
6367
- }
6368
6551
  };
6369
6552
  const handleCollectionPageSizeChange = (colUid, newSize) => {
6370
6553
  const capped = Math.min(500, Math.max(1, newSize));
@@ -6420,9 +6603,13 @@ const BulkUpdater = () => {
6420
6603
  };
6421
6604
  const entryMatchesFilter = (entry, attr) => {
6422
6605
  const matches = getAllNestedValues(entry, attr);
6423
- if (useRegex && regexPattern.trim()) {
6606
+ const activeOp = appliedSearchFilter.filterOperator;
6607
+ const activeQuery = appliedSearchFilter.filterQuery || "";
6608
+ const activeUseRegex = Boolean(appliedSearchFilter.useRegex);
6609
+ const activeRegexPattern = appliedSearchFilter.regexPattern || "";
6610
+ if (activeUseRegex && activeRegexPattern.trim()) {
6424
6611
  try {
6425
- const regex = new RegExp(regexPattern, "i");
6612
+ const regex = new RegExp(activeRegexPattern, "i");
6426
6613
  const anyRegexMatch = matches.some((m) => regex.test(formatDisplayValue(m.value)));
6427
6614
  if (!anyRegexMatch) {
6428
6615
  return false;
@@ -6430,22 +6617,22 @@ const BulkUpdater = () => {
6430
6617
  } catch {
6431
6618
  }
6432
6619
  }
6433
- if (filterOperator === "none") return true;
6620
+ if (activeOp === "none") return true;
6434
6621
  if (matches.length === 0) {
6435
- return filterOperator === "empty";
6622
+ return activeOp === "empty";
6436
6623
  }
6437
6624
  const checkMatch = (val) => {
6438
6625
  const displayStr = formatDisplayValue(val);
6439
6626
  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)";
6440
- if (filterOperator === "empty") return isValEmpty;
6441
- if (filterOperator === "not_empty") return !isValEmpty;
6627
+ if (activeOp === "empty") return isValEmpty;
6628
+ if (activeOp === "not_empty") return !isValEmpty;
6442
6629
  if (isValEmpty) return false;
6443
- const q = filterQuery.trim().toLowerCase();
6630
+ const q = activeQuery.trim().toLowerCase();
6444
6631
  if (!q) return true;
6445
6632
  const testString = (str) => {
6446
6633
  if (str === void 0 || str === null) return false;
6447
6634
  const s = String(str).trim().toLowerCase();
6448
- switch (filterOperator) {
6635
+ switch (activeOp) {
6449
6636
  case "equals":
6450
6637
  return s === q;
6451
6638
  case "contains":
@@ -6476,7 +6663,7 @@ const BulkUpdater = () => {
6476
6663
  }
6477
6664
  return testString(displayStr);
6478
6665
  };
6479
- if (filterOperator === "empty") {
6666
+ if (activeOp === "empty") {
6480
6667
  return matches.every((m) => checkMatch(m.value));
6481
6668
  }
6482
6669
  return matches.some((m) => checkMatch(m.value));
@@ -6487,10 +6674,11 @@ const BulkUpdater = () => {
6487
6674
  if (gridEditMode && gridFilterModifiedOnly) {
6488
6675
  raw = raw.filter((entry) => Boolean(gridEdits[`${col.uid}${KEY_SEP}${entry.documentId}`]));
6489
6676
  }
6490
- if (statusFilter === "all") return raw;
6677
+ const activeStatus = appliedSearchFilter.statusFilter || "all";
6678
+ if (activeStatus === "all") return raw;
6491
6679
  return raw.filter((entry) => {
6492
6680
  const lifecycle = getEntryLifecycleStatus(entry, col, pendingBatches);
6493
- return lifecycle.status === statusFilter;
6681
+ return lifecycle.status === activeStatus;
6494
6682
  });
6495
6683
  };
6496
6684
  const matchingEntriesCount = React__default.useMemo(() => {
@@ -6500,7 +6688,7 @@ const BulkUpdater = () => {
6500
6688
  count += getVisibleEntries(col).length;
6501
6689
  });
6502
6690
  return count;
6503
- }, [filteredCollections, collectionPages, isFilterActive, statusFilter, pendingBatches, gridEditMode, gridFilterModifiedOnly, gridEdits]);
6691
+ }, [filteredCollections, collectionPages, isFilterActive, appliedSearchFilter, pendingBatches, gridEditMode, gridFilterModifiedOnly, gridEdits]);
6504
6692
  const selectAllMatching = () => {
6505
6693
  const updated = { ...selectedEntries };
6506
6694
  filteredCollections.forEach((col) => {
@@ -6528,6 +6716,8 @@ const BulkUpdater = () => {
6528
6716
  setEntrySearch("");
6529
6717
  setStatusFilter("all");
6530
6718
  setRegexPattern("");
6719
+ appliedSearchFilterRef.current = EMPTY_SEARCH_FILTER;
6720
+ setAppliedSearchFilter(EMPTY_SEARCH_FILTER);
6531
6721
  if (gridEditMode) {
6532
6722
  setSelectedEntries((prev) => {
6533
6723
  const retained = {};
@@ -6927,17 +7117,18 @@ const BulkUpdater = () => {
6927
7117
  await fetchModels();
6928
7118
  await fetchAuditHistory();
6929
7119
  if (selectedCollectionUid) {
7120
+ const appliedNow = appliedSearchFilterRef.current;
6930
7121
  loadCollectionPage(
6931
7122
  selectedCollectionUid,
6932
7123
  collectionPages[selectedCollectionUid]?.page || 1,
6933
7124
  void 0,
6934
7125
  void 0,
6935
7126
  void 0,
6936
- filterOperator,
6937
- filterQuery,
6938
- entrySearch,
7127
+ appliedNow.filterOperator,
7128
+ appliedNow.filterQuery,
7129
+ appliedNow.entrySearch,
6939
7130
  false,
6940
- searchAttribute
7131
+ appliedNow.searchAttribute
6941
7132
  );
6942
7133
  }
6943
7134
  }
@@ -7637,14 +7828,15 @@ const BulkUpdater = () => {
7637
7828
  matchingEntriesCount === 1 ? "entry" : "entries",
7638
7829
  " found in database"
7639
7830
  ] }),
7640
- searchAttribute && searchAttribute !== selectedAttribute && /* @__PURE__ */ jsxs(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: [
7831
+ appliedSearchFilter.searchAttribute && appliedSearchFilter.searchAttribute !== selectedAttribute && /* @__PURE__ */ jsxs(Badge, { backgroundColor: "secondary100", textColor: "secondary700", children: [
7641
7832
  "Searching by: ",
7642
- searchAttribute,
7833
+ appliedSearchFilter.searchAttribute,
7643
7834
  " → Target to update: ",
7644
7835
  selectedAttribute
7645
- ] })
7836
+ ] }),
7837
+ hasPendingFilterChanges && /* @__PURE__ */ jsx(Badge, { backgroundColor: "warning100", textColor: "warning700", children: "Filters modified — click Search to apply" })
7646
7838
  ] }),
7647
- isFilterActive && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "S", onClick: clearFilter, children: "Clear Search & Filter" })
7839
+ (isFilterActive || hasPendingFilterChanges || Boolean(searchAttribute) || filterOperator !== "none" || Boolean(entrySearch.trim()) || statusFilter !== "all" || Boolean(useRegex && regexPattern.trim())) && /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "S", onClick: clearFilter, children: "Clear Search & Filter" })
7648
7840
  ] }),
7649
7841
  /* @__PURE__ */ jsxs(Flex, { gap: 3, alignItems: "flex-end", wrap: "wrap", children: [
7650
7842
  /* @__PURE__ */ jsx(Box, { style: { width: 280, minWidth: 230 }, children: /* @__PURE__ */ jsxs(Field.Root, { children: [
@@ -7713,7 +7905,13 @@ const BulkUpdater = () => {
7713
7905
  label: effectiveSearchAttribute ? `Value for "${effectiveSearchAttribute}"` : "Value to match",
7714
7906
  placeholder: "Type value to match...",
7715
7907
  value: filterQuery,
7716
- onChange: (e) => setFilterQuery(e.target.value)
7908
+ onChange: (e) => setFilterQuery(e.target.value),
7909
+ onKeyDown: (e) => {
7910
+ if (e.key === "Enter") {
7911
+ e.preventDefault();
7912
+ handleApplySearch();
7913
+ }
7914
+ }
7717
7915
  }
7718
7916
  ) }),
7719
7917
  /* @__PURE__ */ jsx(Box, { style: { flex: 1, minWidth: 180 }, children: /* @__PURE__ */ jsx(
@@ -7722,7 +7920,13 @@ const BulkUpdater = () => {
7722
7920
  label: "Full-text Entry Search",
7723
7921
  placeholder: "Search title, name, or text across records...",
7724
7922
  value: entrySearch,
7725
- onChange: (e) => setEntrySearch(e.target.value)
7923
+ onChange: (e) => setEntrySearch(e.target.value),
7924
+ onKeyDown: (e) => {
7925
+ if (e.key === "Enter") {
7926
+ e.preventDefault();
7927
+ handleApplySearch();
7928
+ }
7929
+ }
7726
7930
  }
7727
7931
  ) }),
7728
7932
  /* @__PURE__ */ jsx(Box, { style: { width: 190, minWidth: 160 }, children: /* @__PURE__ */ jsxs(
@@ -7741,6 +7945,17 @@ const BulkUpdater = () => {
7741
7945
  ]
7742
7946
  }
7743
7947
  ) }),
7948
+ /* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
7949
+ Button,
7950
+ {
7951
+ variant: hasPendingFilterChanges ? "default" : "secondary",
7952
+ startIcon: /* @__PURE__ */ jsx(Search, {}),
7953
+ onClick: handleApplySearch,
7954
+ loading: Boolean(selectedCollectionUid && collectionPages[selectedCollectionUid]?.loading),
7955
+ disabled: !selectedCollectionUid || Boolean(selectedCollectionUid && collectionPages[selectedCollectionUid]?.loading),
7956
+ children: "Search"
7957
+ }
7958
+ ) }),
7744
7959
  isFilterActive && /* @__PURE__ */ jsxs(Flex, { gap: 2, alignItems: "center", children: [
7745
7960
  /* @__PURE__ */ jsx(
7746
7961
  Button,
@@ -9951,4 +10166,4 @@ export {
9951
10166
  getSortOptionsForCollection,
9952
10167
  parseDynamicZonePath
9953
10168
  };
9954
- //# sourceMappingURL=BulkUpdater-CTKfvKhE.mjs.map
10169
+ //# sourceMappingURL=BulkUpdater-e7N4vMse.mjs.map