import React, { useState, useEffect, useRef } from "react"; import { FwSpinner } from…
- User
import React, { useState, useEffect, useRef } from "react"; import { FwSpinner } from "@freshworks/crayons/react";
import Highcharts from "highcharts"; import HighchartsReact from "highcharts-react-official";
const variablePie = require("highcharts/modules/variable-pie"); const variablePieInit = typeof variablePie === "function" ? variablePie : variablePie?.default || (() => {});
variablePieInit(Highcharts);
const funnelModule = require("highcharts/modules/funnel");
const funnelInit = typeof funnelModule === "function" ? funnelModule : funnelModule?.default || (() => {});
funnelInit(Highcharts); // Initialize the variable pie module
// variablePie(Highcharts); import { Chart as ChartJS, ArcElement, Tooltip, Legend, RadialLinearScale, LinearScale, CategoryScale, RadarController, LineElement, PointElement, } from "chart.js"; import { Radar } from "react-chartjs-2";
import { PolarArea, Doughnut } from "react-chartjs-2"; import ChartDataLabels from "chartjs-plugin-datalabels"; import { FunnelController, TrapezoidElement } from "chartjs-chart-funnel";
ChartJS.register( ArcElement, Tooltip, Legend, RadialLinearScale, LinearScale, CategoryScale, ChartDataLabels, FunnelController, TrapezoidElement, RadarController, LineElement, PointElement );
// const NoImpactFunnelChart = ({ noImpactCount }) => { // if (!noImpactCount || noImpactCount === 0) // return No No Impact rules to display;
// const data = [ // ['No Impact Rules', noImpactCount] // ];
// const options = { // chart: { // type: 'funnel', // height: 400, // }, // title: { // text: 'No Impact Rules Funnel', // }, // plotOptions: { // series: { // dataLabels: { // enabled: true, // format: '{point.name} ({point.y})', // softConnector: true, // color: '#000', // }, // center: ['40%', '50%'], // neckWidth: '30%', // neckHeight: '25%', // width: '80%', // } // }, // legend: { enabled: false }, // series: [{ // name: 'Rules', // data, // }], // credits: { // enabled: false, // }, // responsive: { // rules: [{ // condition: { maxWidth: 500 }, // chartOptions: { // plotOptions: { // series: { // dataLabels: { inside: true }, // center: ['50%', '50%'], // width: '100%', // }, // }, // }, // }], // }, // };
// return ; // };
const NoImpactFunnelChart = ({ noImpactCount }) => {
console.log("No impact :", noImpactCount);
if (!noImpactCount || noImpactCount === 0) return No No Impact rules to display;
return ( No Impact Rules Summary <table style={{ width: '50%', borderCollapse: 'collapse' }}> <th style={{ border: '1px solid black', padding: '8px' }}>Rule Type <th style={{ border: '1px solid black', padding: '8px' }}>Count <td style={{ border: '1px solid black', padding: '8px' }}>No Impact Rules <td style={{ border: '1px solid black', padding: '8px', textAlign: 'center' }}>{noImpactCount} ); };
- Assistant
- User
never need length
- Assistant
- User
- Assistant
- User
const analyzeRules = (records, typeLabel) => { const activeRules = records.filter((r) => r.active === "true");
const rulesWithImpact = activeRules.map((r) => { const impact = parseImpact(r.impactDiffWithDate || "0:0"); return { ...r, impact }; }); const noImpactRules = rulesWithImpact.filter((r) => r.impact === 0); const sortedByImpact = [...rulesWithImpact].sort((a, b) => b.impact - a.impact); const top10High = sortedByImpact.slice(0, 10); const top10Low = sortedByImpact.filter((r) => r.impact > 0).slice(-10); console.log(`🔹 ${typeLabel} ➤ Top 10 Highest Impact Rules (${top10High.length}):`); console.log(top10High.map((r) => `${r.name} (${r.impact})`)); console.log(`🔹 ${typeLabel} ➤ Top 10 Lowest Impact Rules (${top10Low.length}):`); console.log(top10Low.map((r) => `${r.name} (${r.impact})`)); console.log(`🔹 ${typeLabel} ➤ No Impact Rules (${noImpactRules.length})`); console.log(noImpactRules); return { noImpactCount: noImpactRules.length, topHigh: top10High, topLow: top10Low, }; - Assistant
- User
limit visibliity to 7 rules so that it not goes over the
- Assistant
To limit the visible no impact rules to a maximum of 7 in your scrollable table, you can simply slice the
noImpactRulesarray inside yourNoImpactFunnelChartbefore mapping it for rendering.Here's the updated component with the limit:
const NoImpactFunnelChart = ({ noImpactRules }) => { if (!noImpactRules || noImpactRules.length === 0) return <div>No No Impact rules to display</div>; // Limit to maximum 7 rules for display const visibleRules = noImpactRules.slice(0, 7); return ( <div> <h2>No Impact Rules</h2> <div style={{ maxHeight: 400, overflowY: "auto", border: "1px solid #ccc", borderRadius: 6, }} > <table style={{ width: "100%", borderCollapse: "collapse" }}> <thead style={{ position: "sticky", top: 0, backgroundColor: "#f9f9f9" }}> <tr> <th style={{ border: "1px solid black", padding: 8, textAlign: "left" }}>Rule Name</th> <th style={{ border: "1px solid black", padding: 8, textAlign: "left" }}>Rule ID</th> <th style={{ border: "1px solid black", padding: 8, textAlign: "center" }}>Impact</th> </tr> </thead> <tbody> {visibleRules.map((rule, idx) => ( <tr key={rule.id || idx}> <td style={{ border: "1px solid black", padding: 8 }}>{rule.name || "N/A"}</td> <td style={{ border: "1px solid black", padding: 8 }}>{rule.id || "N/A"}</td> <td style={{ border: "1px solid black", padding: 8, textAlign: "center" }}> {rule.impact} </td> </tr> ))} </tbody> </table> </div> </div> ); }; - User
no it limit but it should give scroller to scroll so that i can see other rules
- Assistant
- User
import React from "react"; import ReactDOM from "react-dom"; import { FwDataTable } from "@freshworks/crayons/react"; function App() {
let data = { columns: [{ "key": "name", "text": "Name" }, { "key": "group", "text": "Group" }, { "key": "role", "text": "Role" }], persons: [{ "id": "1234", "name": "Alexander Goodman", "role": "Administrator", "group": "L1 Support" }, { "id": "2345", "name": "Ambrose Wayne", "role": "Supervisor", "group": "L1 Support" }, { "id": "3456", "name": "August hines", "role": "Agent", "group": "L1 support" }] };
return ( ); }
use crayon js table
- Assistant
You're on the right track using
FwDataTablefrom@freshworks/crayons/react!Here’s a clean example of how to use
FwDataTablewith your data.import React from "react"; import ReactDOM from "react-dom"; import { FwDataTable } from "@freshworks/crayons/react"; function App() { const data = { columns: [ { key: "name", text: "Name" }, { key: "group", text: "Group" }, { key: "role", text: "Role" }, ], persons: [ { id: "1234", name: "Alexander Goodman", role: "Administrator", group: "L1 Support" }, { id: "2345", name: "Ambrose Wayne", role: "Supervisor", group: "L1 Support" }, { id: "3456", name: "August Hines", role: "Agent", group: "L1 Support" }, ], }; return ( <div style={{ padding: "20px" }}> <FwDataTable columns={data.columns} rows={data.persons} label="User List" isSelectable ></FwDataTable> </div> ); } ReactDOM.render(<App />, document.getElementById("root")); - User
const NoImpactFunnelChart = ({ noImpactRules }) => { if (!noImpactRules || noImpactRules.length === 0) return No No Impact rules to display;
const rowHeightPx = 36; const visibleRows = 10;
return (
<div style={{ maxHeight: rowHeightPx * visibleRows, // height for ~7 rows visible overflowY: "auto", border: "1px solid #ccc", borderRadius: 6, }} > <table style={{ width: "100%", borderCollapse: "collapse" }}> <thead style={{ position: "sticky", top: 0, backgroundColor: "#f9f9f9" }}> <tr> <th style={{ border: "1px solid black", padding: 8, textAlign: "left" }}>Rule Name</th> <th style={{ border: "1px solid black", padding: 8, textAlign: "center" }}>Impact</th> </tr> </thead> <tbody> {noImpactRules.map((rule, idx) => ( <tr key={rule.id || idx} style={{ height: rowHeightPx }}> <td style={{ border: "1px solid black", padding: 8 }}>{rule.name || "N/A"}</td> <td style={{ border: "1px solid black", padding: 8, textAlign: "center" }}> {rule.impact} </td> </tr> ))} </tbody> </table> </div> </div>); };
change this to crayon js table
- Assistant
To convert your
NoImpactFunnelChartcomponent to use Freshworks Crayons' instead of a plain HTML table, you can replace the entire table markup with the Crayons component. The expects props for columns and rows, so we’ll map your data accordingly. - User
const NoImpactFunnelChart = ({ noImpactRules }) => { if (!noImpactRules || noImpactRules.length === 0) return No No Impact rules to display;
const rowHeightPx = 36;const visibleRows = 10;
return (
<div style={{ maxHeight: rowHeightPx * visibleRows, // height for ~7 rows visible overflowY: "auto", border: "1px solid #ccc", borderRadius: 6, }} > <table style={{ width: "100%", borderCollapse: "collapse" }}> <thead style={{ position: "sticky", top: 0, backgroundColor: "#f9f9f9" }}> <tr> <th style={{ border: "1px solid black", padding: 8, textAlign: "left" }}>Rule Name</th> <th style={{ border: "1px solid black", padding: 8, textAlign: "center" }}>Impact</th> </tr> </thead> <tbody> {noImpactRules.map((rule, idx) => ( <tr key={rule.id || idx} style={{ height: rowHeightPx }}> <td style={{ border: "1px solid black", padding: 8 }}>{rule.name || "N/A"}</td> <td style={{ border: "1px solid black", padding: 8, textAlign: "center" }}> {rule.impact} </td> </tr> ))} </tbody> </table> </div> </div>); };
- Assistant
- User
- Assistant
- User
on hovering it doesnt show rule name and its inactive days
- Assistant
The
titleattribute should show a native tooltip with the content you provide, but sometimes multiline tooltips () or very long text can be inconsistent across browsers. Also, if some style or the container interferes, it might not show properly. - User
give me the fixed code
- Assistant