import React, { useState, useEffect, useRef } from "react"; import { FwTabs, FwTab,…
- User
import React, { useState, useEffect, useRef } from "react"; import { FwTabs, FwTab, FwTabPanel, FwSpinner, ToastController, FwToast, FwPagination, FwButton, FwIcon, FwListOptions, FwPopover, FwModal, } from "@freshworks/crayons/react"; import AutomationCard from "./AutomationCard"; import SummaryContent from "./SummaryContent"; import { getTicketCreationRules, getTicketUpdationRules, getHourlyRules, getAgents, pagination, } from "../common";
const groupDuplicates = (rules) => { const grouped = {}; rules.forEach((rule) => { const signature = getRuleSignature(rule); if (!grouped[signature]) grouped[signature] = []; grouped[signature].push(rule); }); return Object.values(grouped); };
const getRuleSignature = (rule) => { const conditions = rule.summary?.conditions || rule.conditions; const actions = rule.summary?.actions || rule.actions; return JSON.stringify({ conditions, actions, }); };
const Filterrecords = async (automationTypeId, newRulePloadDB3) => { let allRecords = []; let nextMarker = null;
try { do { const queryObj = { query: { automation_type_id: automationTypeId } }; if (nextMarker) queryObj.next = { marker: nextMarker };
const response = await newRulePloadDB3.getAll(queryObj); if (!response.records || !Array.isArray(response.records)) break; const filtered = response.records .map((record) => ({ ...record.data, display_id: record.display_id, rule_id: record.data.rule_id, automation_type_id: record.data.automation_type_id, id: record.data.rule_id || record.data.id, })) .filter((record) => record.active === "true"); allRecords = allRecords.concat(filtered); nextMarker = response.links?.next?.marker || null; } while (nextMarker); console.log(`✅ Filtered Records for Type ${automationTypeId}:`, allRecords); return allRecords;} catch (error) { console.error("❌ Error fetching filtered records:", error); return []; } };
const AutomationTabs = ({ client }) => { const [isRulesDBReady, setIsRulesDBReady] = useState(false); const [loadingBannerVisible, setLoadingBannerVisible] = useState(true); const intervalIdRef = useRef(null); const [showSearchHint, setShowSearchHint] = useState(false);
const [searchTerm, setSearchTerm] = useState(""); const [searchQuery, setSearchQuery] = useState(""); const [searchTriggered, setSearchTriggered] = useState(false);
const [activeTab, setActiveTab] = useState("ticketcreate"); const [tabsInitialized, setTabsInitialized] = useState(false); const modalRef = useRef(null);
const [ticketCreationRules, setTicketCreationRules] = useState([]); const [ticketUpdateRules, setTicketUpdateRules] = useState([]); const [hourlyTriggerRules, setHourlyTriggerRules] = useState([]);
const [loading, setLoading] = useState(false); const [agent, setAgent] = useState([]); // const [ruleViewFilter, setRuleViewFilter] = useState(ruleViewOptions[0]);
const rulesPerPage = 30;
- Assistant
- User
{loadingBannerVisible && !isRulesDBReady && ( <div style={{ display: "flex", alignItems: "center"}}> <span style={{ marginLeft: "8px" }}>Waiting for rules to be ready... )}
center to the whole page
- Assistant
To center that loading banner both vertically and horizontally over the whole page viewport, you can wrap it in a full-page container with flexbox styles like this:
{loadingBannerVisible && !isRulesDBReady && ( <div style={{ position: "fixed", top: 0, left: 0, width: "100vw", height: "100vh", display: "flex", justifyContent: "center", alignItems: "center", backgroundColor: "rgba(255, 255, 255, 0.8)", // optional: translucent white bg overlay zIndex: 9999, // to appear above other content }} > <div style={{ display: "flex", alignItems: "center" }}> <FwSpinner size="medium" color="green" /> <span style={{ marginLeft: "8px", fontWeight: "bold", fontSize: 16 }}> Waiting for rules to be ready... </span> </div> </div> )}
Explanation:
position: fixedfixes the container to viewport regardless of scroll.
- User
no the error to center that's it (same height but center)
- Assistant
If you want to keep your current container height (like 40-50px or similar) but center the spinner and text horizontally and vertically within that container, you can do this:
{loadingBannerVisible && !isRulesDBReady && ( <div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "40px", // keep current height or adjust as needed }} > <FwSpinner size="medium" color="green" /> <span style={{ marginLeft: "8px" }}>Waiting for rules to be ready...</span> </div> )}
Explanation:
display: flexenables flexbox.justify-content: centercenters horizontally.align-items: centercenters vertically within the container height.- Set a fixed or min height on the container to have vertical space.
This will keep your loading banner container height the same as before but perfectly center the spinner and text within that height.
If you want the container to fill the available space around it (e.g., the width of its parent), make sure the parent allows full width or set on this div too. For just centering horizontally and vertically in a fixed height bar, this is sufficient.
- User
- Assistant
Got it — you want to center the entire container (
divwith width 60%) horizontally on the page, i.e., center that block instead of havingmarginLeft: 30andmarginRight: auto.
Change this:
<div style={{ width: "60%", marginLeft: 30, marginRight: "auto" }}>
To this:
<div style={{ width: "60%", margin: "0 auto" }}>
Explanation:
margin: 0 autohorizontally centers the block (div) with fixed width (60%).- Removes the fixed
marginLeft: 30which offsets it to the right. - Adds symmetrical left and right auto margin to center horizontally.
Full updated snippet:
- User
{loadingBannerVisible && !isRulesDBReady && (
this should be that's width
- Assistant
If you want the loading banner's container (
div) to have the same width and horizontal position as your main content container (which you said iswidth: 60%and centered), just set the same width and margin styles on thatdiv. For example:{loadingBannerVisible && !isRulesDBReady && ( <div style={{ display: "flex", justifyContent: "center", alignItems: "center", height: "40px", width: "60%", margin: "0 auto", }} > <FwSpinner size="medium" color="green" /> <span style={{ marginLeft: "8px" }}>Waiting for rules to be ready...</span> </div> )}
Explanation:
width: "60%"makes it same width as your main content container.margin: "0 auto"centers it horizontally on the page.- The spinner and text remain centered inside the container thanks to flexbox.
This will keep your loading banner aligned and sized exactly like your tabs/buttons container — consistent UI alignment.
- User
- Assistant
- User
<FwTabPanel name="ticketcreate"> {searchInputs} {renderRulesOrGroups()} {showPagination && getPaginatedItemCount() > 0 && ( <div style={{ marginTop: 10 }}> <div style={{ display: "flex", justifyContent: "center" }}> <FwPagination per-page={rulesPerPage} total={getCurrentTotalCount()} page={currentPage.ticketcreate} onFwChange={handlePageChange("ticketcreate")} /> </div> </div> )} </FwTabPanel> <FwTabPanel name="ticketupdate"> {searchInputs} {renderRulesOrGroups()} {showPagination && getPaginatedItemCount() > 0 && ( <div style={{ marginTop: 10 }}> <div style={{ display: "flex", justifyContent: "center" }}> <FwPagination per-page={rulesPerPage} total={getCurrentTotalCount()} page={currentPage.ticketupdate} onFwChange={handlePageChange("ticketupdate")} /> </div> </div> )} </FwTabPanel> <FwTabPanel name="hourly"> {searchInputs} {renderRulesOrGroups()} {showPagination && getPaginatedItemCount() > 0 && ( <div style={{ marginTop: 10 }}> <div style={{ display: "flex", justifyContent: "center" }}> <FwPagination per-page={rulesPerPage} total={getCurrentTotalCount()} page={currentPage.hourly} onFwChange={handlePageChange("hourly")} /> </div> </div> )} </FwTabPanel> </FwTabs> - Assistant
- User
give me the complete jsx
- Assistant
- User
const searchInputs = ( <div style={{ display: "flex", alignItems: "center", marginBottom: 10, marginLeft: 20, marginTop: 15, maxWidth: "100%", gap: "20px", }} > {/* Search input centered */} <div style={{ flex: 1, display: "flex", justifyContent: "center" }}>
{/* "All Rules" button aligned right */} <div style={{ marginLeft: "auto" }}> <FwPopover sameWidth="false" placement="bottom-start"> <FwButton slot="popover-trigger" color="secondary" showCaretIcon> <FwIcon slot="before-label" name={ruleViewFilter.graphicsProps.name} /> <span>{ruleViewFilter.text}</span> </FwButton> <div slot="popover-content" style={{ width: 220 }}> <span style={{ fontStyle: "italic" }} className="row fw-flex fw-type-xs fw-p-4 fw-type-semibold" > Select Rule View </span> <hr style={{ margin: 0 }} /> <FwListOptions onFwChange={(event) => { const selected = event.detail?.meta?.selectedOptions[0]; if (selected) { setRuleViewFilter(selected); setCurrentPage((prev) => ({ ...prev, [activeTab]: 1 })); if (selected.value === "all_rules") { setTicketCreationRuleGroups([]); setTicketUpdateRuleGroups([]); setHourlyRuleGroups([]); } else if (selected.value === "duplicate_rules") { handleFilterApiClick(); } } }} selectedOptions={[ruleViewFilter]} options={ruleViewOptions} variant="icon" /> </div> </FwPopover> </div> </div> - Assistant
- User
at right add a button fw primary Add New Rule
- Assistant
- User
- Assistant
- User
give me the compleed snippet
- Assistant
- User
i cant type anything now give me the fixed part alone
- Assistant
- User
when user type and enter then only you have to search. also when search is empty you have to show everything
- Assistant
- User
- Assistant
- User
<fw-input label="Name" icon-left="add-contact" hint-text="Do not enter your user ID" warning-text="Please use numbers for user ID" error-text="Invalid user ID" state="warning" placeholder="Enter your official name"
clear-inputincrease input size
- Assistant
To increase the size (width and/or height) of your
<fw-input>component, you can apply CSS styles either inline or via a CSS class.Since
<fw-input>is a web component, it respects standard CSS properties for sizing likewidth,height,font-size,padding, etc.
Example: Increasing width and height using inline styles
- User
ok now add the existing animatedsearch search logic to this code
{/* Search input centered */} <div style={{ flex: 1, display: "flex", justifyContent: "center", marginTop: 20 }}> <fw-inputicon-left="search" hint-text="Do not enter your user ID" warning-text="Please use numbers for user ID" placeholder = "Enter a Keyword to Search..." error-text="Invalid user ID"
clear-input style={{ width: "400px",
height: "-60px",
fontSize: "18px",}}
</div> - Assistant
- User
not as component
- Assistant
Got it! To integrate the animated search logic directly inline with your existing JSX (not as separate component), modify your
<fw-input>like this:import React, { useState, useEffect, useRef } from "react"; // inside your component's render or return: const inputRef = useRef(null); useEffect(() => { if (inputRef.current) { inputRef.current.value = searchTerm; } }, [searchTerm]); // In JSX: <div style={{ flex: 1, display: "flex", justifyContent: "center", marginTop: 20 }}> <fw-input ref={inputRef} icon-left="search" hint-text="Do not enter your user ID" warning-text="Please use numbers for user ID" placeholder="Enter a Keyword to Search..." error-text="Invalid user ID" clear-input style={{ width: "400px", height: "60px", // fixed positive height fontSize: "18px", }} onInput={(e) => { setSearchTerm(e.target.value); if (showSearchHint) setShowSearchHint(false); }} onKeyDown={(e) => { if (e.key === "Enter") { const trimmed = e.target.value.trim(); if (!trimmed) { setSearchQuery(""); setShowSearchHint(false); } else { setSearchQuery(trimmed); setShowSearchHint(false); } } }} /> </div> - User
give me the modified part alone
- Assistant
Certainly! Here's the modified part alone for your search input with the animated search logic inline (no separate component), using
refand event handlers:const inputRef = useRef(null); useEffect(() => { if (inputRef.current) { inputRef.current.value = searchTerm; } }, [searchTerm]); // In your JSX, replace the existing fw-input with this: <div style={{ flex: 1, display: "flex", justifyContent: "center", marginTop: 20 }}> <fw-input ref={inputRef} icon-left="search" hint-text="Do not enter your user ID" warning-text="Please use numbers for user ID" placeholder="Enter a Keyword to Search..." error-text="Invalid user ID" clear-input style={{ width: "400px", height: "60px", // Positive height value fontSize: "18px", }} onInput={(e) => { setSearchTerm(e.target.value); if (showSearchHint) setShowSearchHint(false); }} onKeyDown={(e) => { if (e.key === "Enter") { const trimmed = e.target.value.trim(); if (!trimmed) { setSearchQuery(""); setShowSearchHint(false); } else { setSearchQuery(trimmed); setShowSearchHint(false); } } }} /> </div> - User
when the search is back to empty it should show all rules as it is
- Assistant
The snippet I gave already handles that logic inside the
onKeyDownhandler, specifically this part:if (e.key === "Enter") { const trimmed = e.target.value.trim(); if (!trimmed) { setSearchQuery(""); // Clear search query when empty setShowSearchHint(false); } else { setSearchQuery(trimmed); // Set new search query when user presses Enter setShowSearchHint(false); } }
To clarify:
- User
- Assistant
- User
not that filtering filtering based on duplicates
- Assistant
- User
on filtering duplicates add this logic : after finding duplicates per page show 5 group of duplicates rules. like that i need
- Assistant
- User
willl that work in both state like flatrules, duplcates rules (per page group of 5 set of rules) like that?
- Assistant
- User
give me the full completee component without removing existing functionality dont remove anything anything
- Assistant
- User
dont remove anything give me full code full no removing anything from my code. give me the full code
- Assistant