for (let part of parts) {
const cleaned = cleanText(part);
if (cleaned === "condition set 1") {
currentSet = set1;
continue;
}
if (cleaned === "condition set 2") {
currentSet = set2;
continue;
}
if (!currentSet) currentSet = set1;
function extractText(htmlString) {
if (!htmlString || typeof htmlString !== "string") return "";
let text = htmlString.replace(/<[^>]+>/g, "").trim();
if (text.toLowerCase().startsWith("if ")) {
text = text.substring(3).trim();
}
// console.log("Actual Text :", text);
return text; // do not convert to lowercase here
}
function generateSummary(summary) {
if (!summary) return "";
if (typeof summary === "string") {
return summary;
}
let conditionTexts = [];
if (summary.conditions) {
for (const setKey in summary.conditions) {
if (Object.prototype.hasOwnProperty.call(summary.conditions, setKey)) {
const conditionsVal = summary.conditions[setKey];
const conditionsArray = Array.isArray(conditionsVal) ? conditionsVal : [conditionsVal];
const cleanConditions = conditionsArray.map(extractText);
conditionTexts.push(cleanConditions.join(", "));
}
}
}
const conditionsStr = conditionTexts.join(", ");
let actionsStr = "";
if (summary.actions && Array.isArray(summary.actions)) {
const cleanActions = summary.actions.map(extractText);
actionsStr = cleanActions.join(", ");
}
if (conditionsStr && actionsStr) {
return if ${conditionsStr}, then ${actionsStr};
} else if (conditionsStr) {
return if ${conditionsStr};
} else if (actionsStr) {
return actionsStr;
}
return "";
}
const duplicateGroupsMap = useMemo(() => {
// groups: array of arrays of duplicate rules with length > 1
let allRules = [];
if (activeTab === "ticketcreate") allRules = ticketCreationRules;
else if (activeTab === "ticketupdate") allRules = ticketUpdateRules;
else if (activeTab === "hourly") allRules = hourlyTriggerRules;
// group duplicates, filtered active only
const groups = groupDuplicates(allRules).filter((g) => g.length > 1);
// Map rule_id -> isFirstInGroup flag (true only for first rule of each duplicate group)
const firstRuleIds = new Set();
groups.forEach((group) => {
if (group.length > 0) {
firstRuleIds.add(group[0].id);
}
});
// Return structure for lookup: firstRuleIds set + flattened set of all duplicate IDs
const duplicateRuleIds = new Set(groups.flat().map((r) => r.id));
return { firstRuleIds, duplicateRuleIds };
// if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
// else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
// else if (activeTab === "hourly") groups = hourlyRuleGroups;
// // exact count of items on current page
// const count = flattenGroups(groupsToShow).length;
// console.log([Pagination] Duplicate mode per-page on tab '${activeTab}' page ${pageIndex + 1}: ${count});
// return count;
// };
// const getPaginationTotalCount = () => {
// if (ruleViewFilter.value === "duplicate_rules") {
// let groups = [];
// if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
// else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
// else if (activeTab === "hourly") groups = hourlyRuleGroups;
// if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
// else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
// else if (activeTab === "hourly") groups = hourlyRuleGroups;
let groups = [];
if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
else if (activeTab === "hourly") groups = hourlyRuleGroups;
const paginatedGroups = paginateDuplicateGroups(groups, rulesPerPage, searchQuery);
const pageIndex = currentPage[activeTab] - 1;
let startItem = 1;
for (let i = 0; i < pageIndex; i++) {
const groupsToShow = paginatedGroups[i];
if (groupsToShow && groupsToShow.length > 0) {
startItem += flattenGroups(groupsToShow).length;
}
}
return startItem;
};
const getCurrentPageItemCount = (totalItems) => {
if (ruleViewFilter.value !== "duplicate_rules") {
const calculatedEnd = currentPage[activeTab] * rulesPerPage;
return Math.min(calculatedEnd, totalItems);
}
let groups = [];
if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
else if (activeTab === "hourly") groups = hourlyRuleGroups;
const paginatedGroups = paginateDuplicateGroups(groups, rulesPerPage, searchQuery);
const pageIndex = currentPage[activeTab] - 1;
let cumulativeCount = 0;
for (let i = 0; i <= pageIndex; i++) {
const groupsToShow = paginatedGroups[i];
if (groupsToShow && groupsToShow.length > 0) {
cumulativeCount += flattenGroups(groupsToShow).length;
}
}
return cumulativeCount;
};
// const getCurrentPageItemCount = () => {
// if (ruleViewFilter.value !== "duplicate_rules") {
// return rulesPerPage;
// }
// let groups = [];
// if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
// else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
// else if (activeTab === "hourly") groups = hourlyRuleGroups;
// // Correct usage: Paginate the flattened list of items instead of the groups
// const currentPageIndex = currentPage[activeTab];
// const paginatedItems = paginateGroups(groups, rulesPerPage, currentPageIndex);
// // console.log("paginatedItems on groups :",JSON.stringify(paginatedItems,null,2))
// return paginatedItems.length; // Return the count of the items on the current page
// };
const getPaginationTotalCount = () => {
if (ruleViewFilter.value === "duplicate_rules") {
let groups = [];
if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
else if (activeTab === "hourly") groups = hourlyRuleGroups;
let totalItemCount = 0;
for (const group of groups) {
const filteredGroup = group.filter(
(rule) =>
!searchQuery.trim() ||
rule.name?.toLowerCase().includes(searchQuery.toLowerCase()) ||
rule.description?.toLowerCase().includes(searchQuery.toLowerCase())
);
totalItemCount += filteredGroup.length;
}
return totalItemCount;
} else {
return getCurrentTotalCount();
}
};
// Helper function to paginate a single group of items
const paginateGroup = (group, itemsPerPage, currentPage) => {
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = Math.min(startIndex + itemsPerPage, group.length);
return group.slice(startIndex, endIndex);
};
// Helper function to paginate groups (assuming groups are an array of arrays)
const paginateGroups = (groups, itemsPerPage, currentPage) => {
// Flatten the groups to paginate them as a single list
let allItems = [];
for (const group of groups) {
allItems = allItems.concat(group);
}
const startIndex = (currentPage - 1) * itemsPerPage;
const endIndex = Math.min(startIndex + itemsPerPage, allItems.length);
const pageItems = allItems.slice(startIndex, endIndex);
// Reconstruct the page based on the original group structure
const pageGroups = [];
let currentIndex = 0;
for (const group of groups) {
let groupIndex = 0;
while (groupIndex < group.length && pageItems.includes(group[groupIndex])) {
if (!pageGroups[pageGroups.length - 1] || pageGroups[pageGroups.length - 1].length >= itemsPerPage) {
pageGroups.push([]);
}
pageGroups[pageGroups.length - 1].push(group[groupIndex]);
groupIndex++;
}
currentIndex += group.length;
}
return pageItems;
};
in this code, for on when switching to duplicate rules, if duplicate rules does not move to next pagination dont show pagination
To ensure that pagination only appears when there's enough content (rules) in the duplicate rules view and hides when there's nothing to paginate (e.g., on a page with no duplicate rules or only one page), you need to adjust the logic that controls pagination visibility.
Problem Recap
In the duplicate rules view, you want to:
Show pagination only if there are multiple pages of duplicates to paginate through.
When switching tabs or changing filters, if the current page has no data (because duplicates don't fill that page), the pagination should not show or should adapt properly.
Specifically, if there are no duplicate rules on the current page or just a single page in total, pagination component should be hidden.
How to Fix
You already have some conditions and functions to get:
The total number of duplicate rules matching the current search.
Current page items count.
Current page number.
Total pages.
Use these to conditionally render the pagination component only if the total pages are more than 1 and the current page contains any items.
Steps to Implement
Add a function to get total pages count for duplicates:
Because your rulesPerPage is fixed, total pages = Math.ceil(totalDuplicateRules / rulesPerPage)
You already have a function getPaginationTotalCount() which returns total items count.
You can encapsulate this logic into a helper and use it everywhere you render <CustomPagination /> so that pagination doesn’t show if duplicates are fewer / fit in one page.
Bonus: Update currentPage when no data (already done?)
You already partly handle page rollback on delete, but also consider resetting page if search or filtering results in no rules on the current page — otherwise pagination might show page 3 but with zero entries.
You can also handle this in an effect, for example:
Add helper shouldShowPagination() based on duplicate rules count and total pages.
Use that helper to conditionally render <CustomPagination>.
Optionally, sync current page number to valid range after filter/search.
This will ensure pagination only shows when duplicate rules require it (multiple pages), and won't show pagination unnecessarily when there aren't enough items to paginate in duplicate rules view.
Thanks for the update! Let's address this step-by-step and ensure pagination shows/hides correctly on the duplicate rules view.
What might be going wrong?
You may be calling shouldShowPagination() or equivalent conditions before your filtered groups/rules have been fully updated or calculated, causing it to misjudge counts.
Your existing page data may stay at a page number where no items exist; so the paginated groups or rules for that page are empty — causing getPaginatedItemCount() to be 0 but getPaginationTotalCount() to be higher, which confuses logic.
The filtering happens after pagination calculation, so if the filtering reduces the data, the pagination logic will misbehave unless that filtering is considered.
Recommended approach for debugging & fixing
1. Make sure your pagination total count reflects filtered and paginated data.
Your getPaginationTotalCount correctly returns the total filtered items count — which is good.
But your getPaginatedItemCount should give the count of items on current page (after filtering + pagination).
If that is out of sync, the pagination visibility logic will fail.
2. Adjust getPaginatedItemCount (get count of rules visible on current page):
Check your existing implementation. It currently returns
Replace .ticketcreate with current tab accordingly in other tabs.
6. Synchronize current page whenever filters/search/group changes
If the current page number points to a page with no items, navigate back to a page with items.
You can add this effect triggered when dependencies change:
useEffect(() => {
const totalItems = getPaginationTotalCount();
const totalPages = Math.ceil(totalItems / rulesPerPage) || 1;
let current = currentPage[activeTab] || 1;
if (current > totalPages) current = totalPages;
if (current < 1) current = 1;
const paginatedCount = getPaginatedItemCount();
if (paginatedCount === 0 && current > 1) {
current -= 1; // go back one page if current page empty and not first
}
if (current !== currentPage[activeTab]) {
setCurrentPage(prev => ({ ...prev, [activeTab]: current }));
}
// You might add dependencies depending on how your state works:
}, [searchQuery, ruleViewFilter, activeTab, ticketCreationRuleGroups, ticketUpdateRuleGroups, hourlyRuleGroups, ticketCreationRules, ticketUpdateRules, hourlyTriggerRules]);
Debugging suggestions
Add console logs inside shouldShowPagination to print counts:
Use filtered total items & filtered page items to decide pagination visibility.
Hide pagination if only 1 or 0 pages or current page empty.
Adjust current page if no items on that page.
Debug with logs to ensure counts are consistent.
If you want, I can help you patch your existing code with these changes exactly — just say so! But these steps should fix your issue where duplicate rules set pagination hides/shows correctly based on available data.
Let me know if you want me to provide the concrete updated snippet for your shouldShowPagination, the pagination rendering, and the effect to sync current page.
Certainly! I'll provide a focused, verified code snippet integrating the fixes to correctly show/hide pagination when switching to duplicate rules, ensuring pagination only appears when needed.
What will be changed or added?
Add shouldShowPagination() helper to control pagination visibility.
Update the three places where <CustomPagination /> renders, wrapping render in that condition.
Add useEffect to ensure current page never points to empty pages.
Add debug logging to help verify counts (can remove in production).
3. Sync current page with totalPages & avoid empty pages
Add this effect inside your component to trigger on relevant dependencies:
useEffect(() => {
const totalItems = getPaginationTotalCount();
const totalPages = Math.ceil(totalItems / rulesPerPage) || 1;
let current = currentPage[activeTab] || 1;
if (current > totalPages) current = totalPages;
if (current < 1) current = 1;
const paginatedCount = getPaginatedItemCount();
// If current page is empty and not first page, go 1 page back
if (paginatedCount === 0 && current > 1) {
current -= 1;
}
if (current !== currentPage[activeTab]) {
setCurrentPage(prev => ({ ...prev, [activeTab]: current }));
}
}, [
searchQuery,
ruleViewFilter,
activeTab,
ticketCreationRuleGroups,
ticketUpdateRuleGroups,
hourlyRuleGroups,
ticketCreationRules,
ticketUpdateRules,
hourlyTriggerRules,
currentPage // include so effect re-checks after page set
]);
Verification notes:
getPaginationTotalCount() and getPaginatedItemCount() are called internally and must operate on filtered + grouped data, which your code already ensures.
shouldShowPagination prevents pagination from showing when total pages <= 1 OR current page is empty.
The effect makes sure current page number is always valid w.r.t current filtered sets, preventing empty pagination states.
Added debug logging in shouldShowPagination will print counts so you can verify behavior live.
Summary for integration:
Add shouldShowPagination as above
Replace pagination render conditions with showPagination && shouldShowPagination()
Add current page sync effect with dependencies as above
Test switching tabs / toggling search with duplicate filter on/off: pagination should only show if multiple pages, disappear otherwise.
If you want, I can generate a full updated AutomationTabs component with these integrated. But the above fixes directly apply to your existing component's event flow and logic.
Let me know if you want me to prepare the full updated full component with these changes applied!
Thanks for clarifying. If pagination is still showing unexpectedly, let’s carefully troubleshoot and provide a complete minimal example of the core logic controlling pagination visibility, tailored for your duplicate rules scenario.
Given your existing code, here are the main issues that often cause this problem:
getPaginationTotalCount() and getPaginatedItemCount() are not aligned — e.g., total count based on all groups, but paginated count is based on filtered or paginated data, or vice versa.
The filtering logic inside these functions doesn't match your UI filtering/search, so totals and counts differ from visual data.
Pagination logic or rendering is triggered before the state updates propagate, causing false positives on counts.
Let's take a practical approach:
Verify counts appearing on page and total counts with console logs.
Simplify logic to isolate the problem.
Provide a working example snippet of pagination visibility control.
Step 1: Add detailed console logging
Inside your component add a debugging helper function:
Step 4: Add an immediate fix for page number correction
To ensure your pagination isn’t stuck on empty pages:
useEffect(() => {
const totalItems = getPaginationTotalCount();
const totalPages = Math.ceil(totalItems / rulesPerPage) || 1;
let page = currentPage[activeTab] || 1;
if (page > totalPages) {
page = totalPages;
}
if (page < 1) {
page = 1;
}
const currentPageItemsCount = getPaginatedItemCount();
// If current page empty but not first, move back one page
if (currentPageItemsCount === 0 && page > 1) {
page = page - 1;
}
if (currentPage[activeTab] !== page) {
setCurrentPage((prev) => ({ ...prev, [activeTab]: page }));
}
}, [
activeTab,
currentPage,
searchQuery,
ruleViewFilter,
ticketCreationRuleGroups,
ticketUpdateRuleGroups,
hourlyRuleGroups,
ticketCreationRules,
ticketUpdateRules,
hourlyTriggerRules,
]);
Step 5: Verify getPaginationTotalCount and getPaginatedItemCount logic itself
Make sure:
getPaginationTotalCount() sums correctly items after applying your search query filter to duplicate groups (for duplicate_rules view) or flat list (for all_rules).
Example simplified for duplicate rules:
const getPaginationTotalCount = () => {
if (ruleViewFilter.value === "duplicate_rules") {
let groups = [];
if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
else if (activeTab === "hourly") groups = hourlyRuleGroups;
let count = 0;
for (const group of groups) {
// Apply your search filter on each group
const filteredGroup = group.filter(
(rule) =>
!searchQuery.trim() ||
rule.name?.toLowerCase().includes(searchQuery.toLowerCase()) ||
rule.description?.toLowerCase().includes(searchQuery.toLowerCase())
);
count += filteredGroup.length;
}
return count;
} else {
// all_rules flat list filtering
let rules = [];
if (activeTab === "ticketcreate") rules = ticketCreationRules;
else if (activeTab === "ticketupdate") rules = ticketUpdateRules;
else if (activeTab === "hourly") rules = hourlyTriggerRules;
return getFilteredRules(rules).length;
}
};
Step 6: getPaginatedItemCount must paginate filtered lists correctly
const getPaginatedItemCount = () => {
if (ruleViewFilter.value === "duplicate_rules") {
let groups = [];
if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
else if (activeTab === "hourly") groups = hourlyRuleGroups;
// Flatten all groups before filtering and paginating
const flatList = flattenGroups(groups);
// Filter flat list
const filtered = getFilteredRules(flatList);
// Paginate filtered flat list
const paginated = pagination(filtered, currentPage[activeTab]);
return paginated.length;
} else {
let rules = [];
if (activeTab === "ticketcreate") rules = ticketCreationRules;
else if (activeTab === "ticketupdate") rules = ticketUpdateRules;
else if (activeTab === "hourly") rules = hourlyTriggerRules;
const filtered = getFilteredRules(rules);
const paginated = pagination(filtered, currentPage[activeTab]);
return paginated.length;
}
};
Summary checklist before testing:
Use logging inside shouldShowPagination and render to confirm numbers.
On switching tabs or search query changes, run effect that corrects current page number.
Confirm filtering is consistent between total count and paginated count.
Wrap the pagination render with showPagination && shouldShowPagination() condition.
If after all this, pagination still shows unexpectedly, possibly the way groups are paginated vs flattened might be confusing the counts. In that case you could:
Try rendering only flat filtered lists (temporarily ignore groups) to test.
Reconfirm your pagination helper returns consistent pages.
Confirm your external pagination helper does what you expect: slices array as per page index.
Please try the above exact code snippets & debug lines together. They’re the standard, robust approach to sync pagination to filtered & grouped data.
If you want, I can prepare a minimal runnable CodeSandbox/React example simulating your data structures to prove the technique.
Let me know if you want me to prepare that full minimal demo — it can pinpoint the problem exactly.
This React warning:
Warning: Each child in a list should have a unique "key" prop.
happens because when you render a list of React elements (e.g., in .map()), React requires every child element to have a unique key prop to help it identify and reconcile elements efficiently.
Where this happens in your code
The warning specifically mentions:
Check the render method of `CustomPagination`.
So the problem is likely inside your CustomPagination component, when it renders a list of elements (probably the page number buttons or ellipsis spans) without unique keys.
How to fix it:
Look inside your CustomPagination's renderPageNumbers method:
const renderPageNumbers = () => {
const pageNumbers = [];
const maxVisiblePages = 5;
const ellipsis = <span style={{ margin: '0 5px', color: '#888' }}>…</span>;
const addPageNumber = (page) => {
pageNumbers.push(
<button
key={page} // good here, page number is unique
onClick={() => handlePaginationClick(page)}
// ...
>
{page}
</button>
);
};
// ...
if (totalPages <= maxVisiblePages) {
for (let i = 1; i <= totalPages; i++) {
addPageNumber(i);
}
} else {
// ...
pageNumbers.push(ellipsis); // THIS is missing a key!
// ...
pageNumbers.push(ellipsis); // Another ellipsis missing a key!
// ...
}
return pageNumbers;
};
The problem:
You are inserting the same React element ellipsis twice without unique keys: (pageNumbers.push(ellipsis);).
React treats this as two identical elements without keys in the list, causing the warning.
Add a unique key prop to every React element inside lists.
For ellipsis <span>…</span>, create a new element with a unique key each time.
For page buttons, key can usually be the page number (unless you have duplicates, which is unlikely).
If you make this change inside your CustomPagination component, that warning will disappear.
If you want, I can provide the full corrected CustomPagination component code snippet. Just ask!
To not show pagination when the total duplicate rules on the current tab (after filtering) are less than rulesPerPage (30), you can modify your getPaginatedItemCount helper slightly, but it's better to handle this check outside in a helper that controls pagination visibility.
However, if you want to embed this logic directly in your pagination visibility condition, you should:
Compute the total count of filtered duplicate rules (not just the current page count).
Show pagination only if total filtered items exceed rulesPerPage (30).
How to update your code:
Step 1: Add a helper to get the total filtered items count (for duplicates).
You likely already have a function like getPaginationTotalCount() that does this. Make sure it returns the total number (not just current page).
const getTotalFilteredCount = () => {
if (ruleViewFilter.value === "duplicate_rules") {
let groups = [];
if (activeTab === "ticketcreate") groups = ticketCreationRuleGroups;
else if (activeTab === "ticketupdate") groups = ticketUpdateRuleGroups;
else if (activeTab === "hourly") groups = hourlyRuleGroups;
const flatList = flattenGroups(groups);
const filtered = getFilteredRules(flatList);
return filtered.length; // total filtered duplicate rules count
} else {
let rules = [];
if (activeTab === "ticketcreate") rules = ticketCreationRules;
else if (activeTab === "ticketupdate") rules = ticketUpdateRules;
else if (activeTab === "hourly") rules = hourlyTriggerRules;
const filtered = getFilteredRules(rules);
return filtered.length;
}
};
Step 2: Update the function (or your condition) that decides whether to show pagination
For example:
const shouldShowPagination = () => {
const totalItems = getTotalFilteredCount();
if (totalItems === 0) return false; // no items no pagination
if (totalItems <= rulesPerPage) return false; // less than page size, no pagination
return true; // else pagination needed
};
Step 3: Use shouldShowPagination to condition rendering pagination