diff --git a/frontend/src/Components/DataForm.js b/frontend/src/Components/DataForm.js index c74230c..ef4afe9 100644 --- a/frontend/src/Components/DataForm.js +++ b/frontend/src/Components/DataForm.js @@ -113,7 +113,7 @@ const DataForm = ({ integrationId, schema }) => {

Submit New Data

{renderFormFields()}
-
diff --git a/frontend/src/Components/DataTable.js b/frontend/src/Components/DataTable.js index 1a37e5a..54c04ec 100644 --- a/frontend/src/Components/DataTable.js +++ b/frontend/src/Components/DataTable.js @@ -2,11 +2,32 @@ import React, { useState,useEffect } from 'react'; const DataTable = ({ data }) => { const [usernames, setUsernames] = useState([]); + const [loading, setLoading] = useState(true); + + useEffect(() => { + const fetchData = async () => { + if (!Array.isArray(data) || data.length === 0) { + // Handle the case where data is not valid + setLoading(false); + return; + } + + const usernamesArray = []; + for (const row of data) { + const username = await getusernames(row.userId); + usernamesArray.push(username); + } + setUsernames(usernamesArray); + setLoading(false); + }; + + fetchData(); + }, [data]); if (!data) { return
No data available
; - }else if (!Array.isArray(data) || data.length === 0) { + } else if (!Array.isArray(data) || data.length === 0) { return
No data available or data is not in the expected format.
; } @@ -20,7 +41,7 @@ const DataTable = ({ data }) => { const getusernames = async (userID) => { try { const token = 'Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImF1dGgiOiJST0xFX0FETUlOIiwiZXhwIjoxNzAyOTI0ODE0LCJpYXQiOjE3MDI4Mzg0MTR9.PgwOZyE-2cvUaoYpvvLvZAPRX1eKQA_5M7SYO1a0v8BLEvZj-VY9b0FPnAzAwB8K6_5s0YIcjS-SUezjKcKvXg'; - const response = await fetch('http://localhost/api/v1/user/'+userID, { + const response = await fetch('http://localhost/api/v1/user/'+"657e1ff042cdee02f39569b4", { method: 'GET', headers: { 'Accept': 'application/json', @@ -54,12 +75,9 @@ const DataTable = ({ data }) => { return `${day}/${month}/${year}`; }; - console.log(data) - - return ( -
+

Integration Data

@@ -67,7 +85,7 @@ const DataTable = ({ data }) => { - + {dataKeys.map(key => ( - - + + {dataKeys.map(key => ( + @@ -129,6 +118,7 @@ function GetIntegration() { + ))} diff --git a/frontend/src/Components/IntegrationForm.js b/frontend/src/Components/IntegrationForm.js index d8e4faf..3c016e1 100644 --- a/frontend/src/Components/IntegrationForm.js +++ b/frontend/src/Components/IntegrationForm.js @@ -59,7 +59,7 @@ export default function IntegrationForm() { }; return ( - +
{formFields.map((field, index) => ( -
+
-
ID IntegrationID AgentTimestampTimestamp {key} @@ -80,8 +98,8 @@ const DataTable = ({ data }) => {
{row._id} {row.integrationId}{row.userId}{formatDate(row.timestamp)}{loading ? 'Loading...' : usernames[index]}{formatDate(row.timestamp)} {row.data ? row.data[key] : 'N/A'} diff --git a/frontend/src/Components/GetIntegration.js b/frontend/src/Components/GetIntegration.js index 0a19d4b..13ed5e7 100644 --- a/frontend/src/Components/GetIntegration.js +++ b/frontend/src/Components/GetIntegration.js @@ -4,11 +4,8 @@ import { useNavigate } from "react-router-dom"; function GetIntegration() { const [data, setData] = useState([]); - const [integrationdata, setIntegrationData] = useState([]); - const [parentID, setparentID] = useState(); const [maxPage, setMaxPage] = useState(1); const [page, setPage] = useState(0); - const [usernames, setUsernames] = useState([]); const { showSnackbar } = useSnackbar(); // Use the Snackbar hook const getData = async () => { @@ -29,21 +26,6 @@ function GetIntegration() { } }; - const getIntegrationData = async() =>{ - try { - const response = await fetch('http://localhost/api/v1/integration/'+parentID+'/data/pageable?page=0&size=50'); - if (!response.ok) { - // Handle non-OK responses - throw new Error(`HTTP error! Status: ${response.status}`); - } - const responseData = await response.json(); - setIntegrationData(responseData.content); - console.log('Success: 11', responseData); - } catch (error) { - const errorMessage = integrationdata.messages.join(', '); - } - }; - const getusernames = async (userID) => { try { @@ -89,11 +71,6 @@ function GetIntegration() { handleLoad(); }, [page]); - useEffect(() => { - if(parentID){ - getIntegrationData(); - } - }, [parentID]); useEffect(() => { if (integrationdata.length > 0) { @@ -111,6 +88,17 @@ function GetIntegration() { await getData(); }; + const formatDate = (timestamp) => { + const date = new Date(timestamp); + const day = String(date.getDate()).padStart(2, '0'); + const month = String(date.getMonth() + 1).padStart(2, '0'); // Month is 0-indexed + const year = date.getFullYear(); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + + return `${hours}:${minutes} - ${day}/${month}/${year}`; + }; + return (
@@ -121,6 +109,7 @@ function GetIntegration() {
Id Name TypeLast updated
{integration.id} {integration.name} {integration.type}{formatDate(integration.lastUpdated)}