Commit 37dd1624 authored by ReemyHasan's avatar ReemyHasan

fixing dashboard

parent 4ff55782
// export const AUTH_TOKEN: string = "token"; // export const AUTH_TOKEN: string = "token";
export const Default_Language: string = "app-language"; export const Default_Language: string = "app-language";
export const ApiGatewayURL: string = `http://localhost:6644`; export const ApiGatewayURL: string = `http://localhost:6644`;
export const TrapURL: string = `http://localhost:6644/api/rethink/data`; export const TrapURL: string = `http://localhost:6644/api/rethink`;
export const SettingURL: string = `http://localhost:6644/api/about`; export const SettingURL: string = `http://localhost:6644/api/about`;
export const AuthURL: string = "http://localhost:6644/auth/"; export const AuthURL: string = "http://localhost:6644/auth/";
export const UserURL: string = `http://localhost:6644/users/`; export const UserURL: string = `http://localhost:6644/users/`;
......
import React, { Component } from "react"; import React, { Component, useEffect, useState } from "react";
import Chart from "chart.js/auto"; import Chart from "chart.js/auto";
import { useCookies } from "react-cookie";
import { getSeverityStatistics } from "../../services/traps-service";
export default function CardLineChart() { export default function CardLineChart() {
React.useEffect(() => { const [data, setData] = useState([]);
const [cookies] = useCookies([]);
useEffect(() => {
const fetchData = async () => {
try {
const response = await getSeverityStatistics(cookies["token"]);
console.log(response);
setData(response);
} catch (error) {
console.error("Error fetching data:", error);
}
};
fetchData();
}, []);
useEffect(() => {
const severityColors:any = {
WARNING: "#fadb14",
INFO: "#10B981",
ERROR: "#EF4444",
};
if (window.myLine) {
window.myLine.destroy();
}
// Check if data has been fetched and is not an empty object
if (Object.keys(data).length > 0) {
const labels = Object.keys(data).sort(); // Use the sorted timestamps as labels
const datasets = Object.keys(severityColors).map((severity) => ({
label: severity,
backgroundColor: severityColors[severity],
borderColor: severityColors[severity],
data: labels.map((timestamp) => data[timestamp][severity] || 0),
fill: false,
}));
var config = { var config = {
type: "line", type: "line",
data: { data: {
labels: [ labels: labels.map((timestamp) =>
"January", new Date(timestamp).toLocaleTimeString()
"February", ),
"March", datasets: datasets,
"April",
"May",
"June",
"July",
],
datasets: [
{
label: "WARNING",
backgroundColor: "#fadb14",
borderColor: "#fadb14",
data: [65, 78, 66, 44, 56, 67, 75],
fill: false,
},
{
label: "INFO",
backgroundColor: "#10B981",
borderColor: "#10B981",
data: [65, 78, 76, 34, 46, 67, 85],
fill: false,
},
{
label: "ERROR",
fill: false,
backgroundColor: "#EF4444",
borderColor: "#EF4444",
data: [40, 68, 86, 74, 56, 60, 87],
},
],
}, },
options: { options: {
maintainAspectRatio: false, maintainAspectRatio: false,
...@@ -111,9 +119,10 @@ export default function CardLineChart() { ...@@ -111,9 +119,10 @@ export default function CardLineChart() {
}, },
}, },
}; };
}
var ctx = document.getElementById("line-chart").getContext("2d"); var ctx = document.getElementById("line-chart").getContext("2d");
window.myLine = new Chart(ctx, config); window.myLine = new Chart(ctx, config);
}, []); }, [data]);
return ( return (
<> <>
<div className="relative flex flex-col min-w-0 break-words w-full mb-6 shadow-lg rounded primary-blue-600"> <div className="relative flex flex-col min-w-0 break-words w-full mb-6 shadow-lg rounded primary-blue-600">
...@@ -123,12 +132,13 @@ export default function CardLineChart() { ...@@ -123,12 +132,13 @@ export default function CardLineChart() {
<h6 className="uppercase text-blueGray-100 mb-1 text-xs font-semibold"> <h6 className="uppercase text-blueGray-100 mb-1 text-xs font-semibold">
Overview Overview
</h6> </h6>
<h2 className="text-white text-xl font-semibold">Severity traps Charts</h2> <h2 className="text-white text-xl font-semibold">
Severity traps Charts
</h2>
</div> </div>
</div> </div>
</div> </div>
<div className="p-4 flex-auto"> <div className="p-4 flex-auto">
{/* Chart */}
<div className="relative h-350-px"> <div className="relative h-350-px">
<canvas id="line-chart"></canvas> <canvas id="line-chart"></canvas>
</div> </div>
......
import React from "react"; import React, {useState, useEffect} from "react";
import FmsTable from "../../../../shared-library/src/tables/fms-table"; import FmsTable from "../../../../shared-library/src/tables/fms-table";
// import { DataSource } from "../show-users/data-source";
import useTranslation from "next-translate/useTranslation"; import useTranslation from "next-translate/useTranslation";
import { TranslationFiles } from "@/src/data/core"; import { TranslationFiles } from "@/src/data/core";
import FmsButton from "../../../../shared-library/src/buttons/fms-button"; import FmsButton from "../../../../shared-library/src/buttons/fms-button";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
// components import { getAllUsers, deleteUser } from "@/src/services/user-service";
import { useCookies } from "react-cookie";
export default function CardUsers() { export default function CardUsers() {
const Columns = [ const Columns = [
{ title: 'Name', dataIndex: 'name', key: 'name' }, { title: 'username', dataIndex: 'username', key: 'username' },
{ title: 'Age', dataIndex: 'age', key: 'age' }, { title: 'role', dataIndex: 'role', key: 'role' },
]; ];
const { t } = useTranslation(TranslationFiles.COMMON); const { t } = useTranslation(TranslationFiles.COMMON);
const router = useRouter(); const router = useRouter();
const [data, setData] = useState([]);
const [cookies] = useCookies([]);
useEffect(() => {
const fetchData = async () => {
try {
const response = await getAllUsers(cookies["token"], cookies["role"]);
setData(response);
} catch (error) {
console.error("Error fetching data:", error);
}
};
fetchData();
}, []);
return ( return (
<> <>
<div className="relative flex flex-col min-w-0 break-words bg-white w-full mb-6 shadow-lg rounded"> <div className="relative flex flex-col min-w-0 break-words bg-white w-full mb-6 shadow-lg rounded">
{/* <div className="rounded-t mb-0 px-4 py-3 border-0"> */}
{/* <div className="flex flex-wrap items-center"> */}
{/* <div className="relative w-full px-4 max-w-full flex-grow flex-1">
<h3 className="font-semibold text-base text-blueGray-700">
Page visits
</h3>
</div> */}
{/* </div> */}
{/* </div> */}
<div className="block w-full overflow-x-auto"> <div className="block w-full overflow-x-auto">
<div className=" w-full px-4 max-w-full flex-grow flex-1 text-right"> <div className=" w-full px-4 max-w-full flex-grow flex-1 text-right">
<FmsButton <FmsButton
...@@ -40,16 +43,15 @@ export default function CardUsers() { ...@@ -40,16 +43,15 @@ export default function CardUsers() {
{"See all".toUpperCase()} {"See all".toUpperCase()}
</FmsButton> </FmsButton>
</div> </div>
{/* <FmsTable <FmsTable
title={"users"} title={"users"}
columns={Columns} columns={Columns}
data={DataSource} data={data}
pageSizeOptions={["3", "5", "7"]} pageSizeOptions={["3", "5", "7"]}
defaultPageSize={3} defaultPageSize={3}
// t={t} className={"dash-table"}
// setData={setData} scroll={{ x: false }}
// setColumns={setColumns} />
/> */}
</div> </div>
</div> </div>
</> </>
......
...@@ -18,7 +18,6 @@ const [modalProps, setModalProps] = useState({ ...@@ -18,7 +18,6 @@ const [modalProps, setModalProps] = useState({
const [data, setData] = useState([]); const [data, setData] = useState([]);
const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]); const [selectedRowKeys, setSelectedRowKeys] = useState<string[]>([]);
const [cookies] = useCookies([]); const [cookies] = useCookies([]);
// Fetch data when the component mounts using useEffect
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
try { try {
......
...@@ -2,7 +2,7 @@ import axios from "axios"; ...@@ -2,7 +2,7 @@ import axios from "axios";
import {TrapURL} from "../data/constant/app-constant"; import {TrapURL} from "../data/constant/app-constant";
export const fetchData = async (token:any) => { export const fetchData = async (token:any) => {
try { try {
const response = await axios.get(TrapURL,{ const response = await axios.get(TrapURL+"/data",{
headers: { headers: {
Authorization: `Bearer ${token}`, Authorization: `Bearer ${token}`,
}, },
...@@ -25,3 +25,16 @@ export const fetchData = async (token:any) => { ...@@ -25,3 +25,16 @@ export const fetchData = async (token:any) => {
console.log(error); console.log(error);
} }
}; };
export const getSeverityStatistics = async (token:any) => {
try {
const response = await axios.get(TrapURL+ "/severity-statistics",{
headers: {
Authorization: `Bearer ${token}`,
},
});
// console.log("response: "+response);
return response.data;
} catch (error) {
console.log(error);
}
};
\ No newline at end of file
...@@ -134,3 +134,6 @@ ...@@ -134,3 +134,6 @@
line-height: 20px !important; line-height: 20px !important;
color: var(--primary-gray-600) !important; color: var(--primary-gray-600) !important;
} }
.dash-table{
width: fit-content;
}
\ No newline at end of file
...@@ -15,6 +15,8 @@ interface fmsTableProps { ...@@ -15,6 +15,8 @@ interface fmsTableProps {
rowSelection:any; rowSelection:any;
pageSizeOptions:Array<string>; pageSizeOptions:Array<string>;
defaultPageSize:any; defaultPageSize:any;
className?: string;
scroll?: any;
} }
const FmsTable: FunctionComponent<fmsTableProps> = ({ const FmsTable: FunctionComponent<fmsTableProps> = ({
title, title,
...@@ -26,8 +28,10 @@ const FmsTable: FunctionComponent<fmsTableProps> = ({ ...@@ -26,8 +28,10 @@ const FmsTable: FunctionComponent<fmsTableProps> = ({
rowSelection, rowSelection,
pageSizeOptions, pageSizeOptions,
defaultPageSize, defaultPageSize,
className,
scroll
}) => { }) => {
const combinedClassName = `fms-table ${className || ""}`;
return ( return (
<div data-testid="fms-table"> <div data-testid="fms-table">
<div className={classes.tableTitleContainer}> <div className={classes.tableTitleContainer}>
...@@ -46,7 +50,7 @@ const FmsTable: FunctionComponent<fmsTableProps> = ({ ...@@ -46,7 +50,7 @@ const FmsTable: FunctionComponent<fmsTableProps> = ({
dataSource={data} dataSource={data}
rowSelection = {rowSelection} rowSelection = {rowSelection}
bordered bordered
scroll={{ x: 1000 }} scroll={{ x: scroll }}
pagination={{ position: ['bottomLeft'], pagination={{ position: ['bottomLeft'],
pageSizeOptions: pageSizeOptions, pageSizeOptions: pageSizeOptions,
showSizeChanger: true, locale: { items_per_page: "" }, showSizeChanger: true, locale: { items_per_page: "" },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment