Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@fortawesome/fontawesome-free": "^6.4.0",
"@mui/icons-material": "^5.14.0",
"@mui/material": "^5.14.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand All @@ -16,23 +14,28 @@
"@types/node": "^20.2.5",
"@types/react": "^18.2.7",
"@types/react-dom": "^18.2.4",
"ansi-to-react": "^6.1.6",
"apexcharts": "^3.41.0",
"axios": "^1.4.0",
"chart.js": "^4.3.0",
"chartjs-plugin-datalabels": "^2.2.0",
"formik": "^2.4.1",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"match-sorter": "^6.3.1",
"mdb-react-ui-kit": "^6.1.0",
"moment": "^2.29.4",
"react": "^18.2.0",
"react-datepicker": "^4.12.0",
"react-apexcharts": "^1.4.1",
"react-datepicker": "^4.16.0",
"react-dom": "^18.2.0",
"react-form-stepper": "^2.0.3",
"react-fullscreen-loading": "^0.0.4",
"react-hot-toast": "^2.4.1",
"react-pro-sidebar": "^1.1.0-alpha.1",
"react-router-dom": "^6.11.2",
"react-scripts": "5.0.1",
"react-select": "^5.7.4",
"sort-by": "^1.2.0",
"typescript": "^5.0.4",
"web-vitals": "^2.1.4",
Expand Down
4 changes: 2 additions & 2 deletions src/components/icons/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react'
//@ts-ignore
import dashboard from '../../assets/images/dashboard.png';
const DashobardIcon = () => {
const DashboardIcon = () => {
return (
<img src={dashboard} alt="dashboard" height="25" />
)
}

export default DashobardIcon
export default DashboardIcon
16 changes: 0 additions & 16 deletions src/components/sidebar/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ export const monitoringItemsConfig = [
label: "Overview",
link: "/monitoring/overview",
},
{
label: "Kafka Topics",
link: "/monitoring/kafka-topics",
},
{
label: "UCI-API",
link: "/monitoring/uci-api",
Expand All @@ -30,18 +26,10 @@ export const monitoringItemsConfig = [
{
label: "Outbound",
link: "/monitoring/outbound",
},
{
label: "Transport-Socket",
link: "/monitoring/transport-socket",
}
];

export const logsItemsConfig = [
{
label: "Kafka Topics",
link: "/monitoring/logs/kafka-topics",
},
{
label: "UCI-API",
link: "/monitoring/logs/uci-api",
Expand All @@ -65,9 +53,5 @@ export const logsItemsConfig = [
{
label: "Outbound",
link: "/monitoring/logs/outbound",
},
{
label: "Transport-Socket",
link: "/monitoring/logs/transport-socket",
}
];
2 changes: 1 addition & 1 deletion src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Switch } from "./Switch";
// import { Typography } from './Typography';
import { SidebarFooter } from "./SidebarFooter";
import { SidebarHeader } from "./SidebarHeader";
import DashobardIcon from "../icons/Dashobard";
import DashobardIcon from "../icons/Dashboard";
import AddIcon from "../icons/AddIcon";
import LogoutIcon from "../icons/LogoutIcon";
import ThemeIcon from "../icons/ThemeIcon";
Expand Down
8 changes: 7 additions & 1 deletion src/components/visualisation/bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, { useEffect, useRef } from "react";
// import Chart from "chart.js";
import Chart from 'chart.js/auto';

export const BarChart = ({ data }) => {
const BarChart = ({ data }) => {
const chartRef = useRef(null);

useEffect(() => {
// Create a new bar chart instance
const ctx = chartRef.current.getContext("2d");
const chart = new Chart(ctx, {
type: "bar",
Expand All @@ -20,11 +21,15 @@ export const BarChart = ({ data }) => {
},
y: {
beginAtZero: true,
// grid: {
// borderDash: [2],
// },
},
},
},
});

// Clean up the chart instance on component unmount
return () => {
chart.destroy();
};
Expand All @@ -33,3 +38,4 @@ export const BarChart = ({ data }) => {
return <canvas ref={chartRef} />;
};

export default BarChart;
4 changes: 3 additions & 1 deletion src/components/visualisation/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export * from './bar'
export * from './bar'
export * from './line'
export * from './pie'
40 changes: 40 additions & 0 deletions src/components/visualisation/line.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { useEffect, useRef } from "react";
import Chart from 'chart.js/auto';

const LineChart = ({ data }) => {
const chartRef = useRef(null);

useEffect(() => {
// Create a new line chart instance
const ctx = chartRef.current.getContext("2d");
const chart = new Chart(ctx, {
type: "line",
data: data,
options: {
responsive: true,
scales: {
x: {
grid: {
display: false,
},
},
y: {
beginAtZero: true,
// grid: {
// borderDash: [2],
// },
},
},
},
});

// Clean up the chart instance on component unmount
return () => {
chart.destroy();
};
}, [data]);

return <canvas ref={chartRef} />;
};

export default LineChart;
73 changes: 73 additions & 0 deletions src/components/visualisation/pie.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React, { useEffect, useRef } from "react";
import Chart from "chart.js/auto";
import useWindowSize from "../../hooks/useWindow";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you move this function to some util function

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a hook so I have kept it in the hooks folder. Should I change?

const generateRandomColor = () => {
const letters = "0123456789ABCDEF";
let color = "#";
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
};

const PieChart = ({ data }) => {
const chartRef = useRef(null);
const { height } = useWindowSize();

useEffect(() => {
// Generate dynamic background colors for each segment based on labels
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since it's reading data from props,so there are chances that when you reload or during initiation time data may be undefined which will break the condition data.labels.map and return error.So I suggest you to use optional chaining like data?.labels?.map

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated it in the recent push.

const dynamicColors = data.labels.map(() => generateRandomColor());

// Create a new pie chart instance
const ctx = chartRef.current.getContext("2d");
const chart = new Chart(ctx, {
type: "pie",
data: {
labels: data.labels,
datasets: [
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here also add optional chaining

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated it in the recent push.

data: data.datasets[0].data,
backgroundColor: dynamicColors,
},
],
},
options: {
responsive: true,
plugins: {
tooltip: {
callbacks: {
label: (context) => {
const label = data.labels[context.dataIndex];
const value = data.datasets[0].data[context.dataIndex];
const total = data.datasets[0].data.reduce((acc, curr) => acc + curr);
const percentage = ((value / total) * 100).toFixed(2);
return `${label}: ${value} (${percentage}%)`;
},
},
},
},
},
});

// Clean up the chart instance on component unmount
return () => {
chart.destroy();
};
}, [data]);

return (
<div
style={{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move inline styles to a style class

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated it in the recent push.

display: "flex",
justifyContent: "center",
alignItems: "center",
maxHeight: `${height - 100}px`,
}}
>
<canvas ref={chartRef} />
</div>
);
};

export default PieChart;