From 760b4add33171341c523a5bdbbdfe8c5d5cde857 Mon Sep 17 00:00:00 2001 From: sara-pervana Date: Tue, 12 Dec 2023 21:48:11 +0100 Subject: [PATCH] final final fixes? --- pkgs/clan-cli/tests/test_db_api.py | 4 +- pkgs/ui/src/app/access-point/page.tsx | 9 +++ pkgs/ui/src/app/client-1/page.tsx | 60 +++++++++++++------ pkgs/ui/src/app/client-2/page.tsx | 50 +++++++++++----- .../app/distributed-ledger-gateway/page.tsx | 9 +++ pkgs/ui/src/app/home/page.tsx | 20 ++++++- pkgs/ui/src/config/access_point/index.tsx | 4 +- pkgs/ui/src/config/client_1/index.tsx | 16 ++--- pkgs/ui/src/config/client_2/index.tsx | 16 ++--- 9 files changed, 136 insertions(+), 52 deletions(-) diff --git a/pkgs/clan-cli/tests/test_db_api.py b/pkgs/clan-cli/tests/test_db_api.py index 2595a86..cf393bf 100644 --- a/pkgs/clan-cli/tests/test_db_api.py +++ b/pkgs/clan-cli/tests/test_db_api.py @@ -266,7 +266,7 @@ def test_entity(api: TestClient) -> None: request_body = { "did": default_entity_did, "name": "C1", - "ip": "127.0.0.1", + "ip": "127.0.0.1:5555", "attached": False, "visible": True, "other": { @@ -283,7 +283,7 @@ def test_entity2(api: TestClient) -> None: request_body = { "did": default_entity_did2, "name": "C2", - "ip": "127.0.0.2", + "ip": "127.0.0.1:5555", "attached": False, "visible": True, "other": { diff --git a/pkgs/ui/src/app/access-point/page.tsx b/pkgs/ui/src/app/access-point/page.tsx index 3cb3115..5ef21b9 100644 --- a/pkgs/ui/src/app/access-point/page.tsx +++ b/pkgs/ui/src/app/access-point/page.tsx @@ -10,6 +10,7 @@ import { APAttachmentsTableConfig, APServiceRepositoryTableConfig, } from "@/config/access_point"; +import { useEffect } from 'react'; export default function AccessPoint() { @@ -28,6 +29,14 @@ export default function AccessPoint() { } } + useEffect(() => { + const interval = setInterval(() => { + onRefresh(); + }, 1000); + + return () => clearInterval(interval); + }, []); + return (
{ + setSnackbarMessage(''); + setSnackbarOpen(false); + } const onAttachEntity = async () => { try { const response = await axios.post(`${BASE_URL}/attach`, { entity_did: entity?.did }); - alert(response.data.message); + setSnackbarMessage(response.data.message); + setSnackbarOpen(true); } catch (error) { console.error(error); } finally { + setIsAttached(true) } } const onDetachEntity = async () => { try { const response = await axios.post(`${BASE_URL}/detach`, { entity_did: entity?.did }); - console.log('detach', response) - alert('Entity Detached Successfully.'); + console.log(response); + setSnackbarMessage('Entity detached successfully.'); + setSnackbarOpen(true); } catch (error) { console.error(error); } finally { + setIsAttached(false) } } const onRefresh = () => { const entityKey = typeof entityKeyFunc === 'function' ? entityKeyFunc() : entityKeyFunc; - const consumerKey = typeof consumerKeyFunc === 'function' ? consumerKeyFunc() : consumerKeyFunc; if (entityKey) mutate(entityKey); - if (consumerKey) mutate(consumerKey) } + useEffect(() => { + const interval = setInterval(() => { + onRefresh(); + }, 1000); + + return () => clearInterval(interval); + }, []); + if (isLoading) return @@ -63,12 +79,17 @@ export default function Client1() { >

Client 1

- - + + {isAttached === false ? + + : + + } +
@@ -93,8 +114,8 @@ export default function Client1() {

Consumer View

@@ -106,6 +127,11 @@ export default function Client1() { configuration={Client1ProducerTableConfig} /> + + + {snackbarMessage} + + ); } diff --git a/pkgs/ui/src/app/client-2/page.tsx b/pkgs/ui/src/app/client-2/page.tsx index 747f59a..c48eaab 100644 --- a/pkgs/ui/src/app/client-2/page.tsx +++ b/pkgs/ui/src/app/client-2/page.tsx @@ -1,15 +1,14 @@ "use client"; -import { useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import { Client2ConsumerTableConfig, Client2ProducerTableConfig, } from "@/config/client_2"; import CustomTable from "@/components/table"; import useGetEntityByName from "@/components/hooks/useGetEntityById"; -import { Button, Card, CardContent, CardHeader, Skeleton, Typography } from "@mui/material"; +import { Button, Card, CardContent, CardHeader, Skeleton, Typography, Snackbar, Alert } from "@mui/material"; import CopyToClipboard from "@/components/copy_to_clipboard"; import { useGetEntity } from "@/api/entities/entities"; -import { useGetConsumer } from "@/api/consumers/consumers"; import { mutate } from "swr"; import axios from "axios"; import { BASE_URL } from "@/constants"; @@ -18,8 +17,15 @@ export default function Client2() { const { entity } = useGetEntityByName('C2'); const { data: client2, isLoading, swrKey: entityKeyFunc } = useGetEntity({ entity_did: entity?.did }) - const { data: consumerData, isLoading: loadingConsumerData, swrKey: consumerKeyFunc } = useGetConsumer({ entity_did: entity?.did }) const cardContentRef = useRef(null); + const [isAttached, setIsAttached] = useState(entity?.attached); + const [snackbarOpen, setSnackbarOpen] = useState(false); + const [snackbarMessage, setSnackbarMessage] = useState(''); + + const closeSnackBar = () => { + setSnackbarMessage(''); + setSnackbarOpen(false); + } const onAttachEntity = async () => { try { @@ -28,6 +34,7 @@ export default function Client2() { } catch (error) { console.error(error); } finally { + setIsAttached(true) } } @@ -39,16 +46,23 @@ export default function Client2() { } catch (error) { console.error(error); } finally { + setIsAttached(false) } } const onRefresh = () => { const entityKey = typeof entityKeyFunc === 'function' ? entityKeyFunc() : entityKeyFunc; - const consumerKey = typeof consumerKeyFunc === 'function' ? consumerKeyFunc() : consumerKeyFunc; if (entityKey) mutate(entityKey); - if (consumerKey) mutate(consumerKey) } + useEffect(() => { + const interval = setInterval(() => { + onRefresh(); + }, 1000); + + return () => clearInterval(interval); + }, []); + if (isLoading) return @@ -63,12 +77,15 @@ export default function Client2() { >

Client 2

- - + {isAttached === false ? + + : + + }
@@ -93,8 +110,8 @@ export default function Client2() {

Consumer View

@@ -106,6 +123,11 @@ export default function Client2() { configuration={Client2ProducerTableConfig} /> + + + {snackbarMessage} + + ); } diff --git a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx index 96ee33f..a611b9c 100644 --- a/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx +++ b/pkgs/ui/src/app/distributed-ledger-gateway/page.tsx @@ -4,6 +4,7 @@ import { DLGResolutionTableConfig, DLGSummaryDetails } from "@/config/dlg"; import CustomTable from "@/components/table"; import SummaryDetails from "@/components/summary_card"; import useFetch from "@/components/hooks/useFetch"; +import { useEffect } from "react"; export default function DLG() { @@ -13,6 +14,14 @@ export default function DLG() { fetch(); } + useEffect(() => { + const interval = setInterval(() => { + onRefresh(); + }, 5000); + + return () => clearInterval(interval); + }, []); + return (
{ + const entityKey = typeof entitiesKeyFunc === 'function' ? entitiesKeyFunc() : entitiesKeyFunc; + if (entitiesKeyFunc) mutate(entityKey); + } + + useEffect(() => { + const interval = setInterval(() => { + onRefresh(); + }, 500); + + return () => clearInterval(interval); + }, []); + return (
diff --git a/pkgs/ui/src/config/access_point/index.tsx b/pkgs/ui/src/config/access_point/index.tsx index f43ba4c..335505a 100644 --- a/pkgs/ui/src/config/access_point/index.tsx +++ b/pkgs/ui/src/config/access_point/index.tsx @@ -17,11 +17,11 @@ export const APSummaryDetails = [ export const APAttachmentsTableConfig = [ { - key: "entity_name", + key: "name", label: "Entity name", }, { - key: "entity_did", + key: "did", label: "Entity DID", }, { diff --git a/pkgs/ui/src/config/client_1/index.tsx b/pkgs/ui/src/config/client_1/index.tsx index 7d9b18f..e2b8ecf 100644 --- a/pkgs/ui/src/config/client_1/index.tsx +++ b/pkgs/ui/src/config/client_1/index.tsx @@ -16,18 +16,18 @@ export const Client1ConsumerTableConfig = [ return } }, - { - key: "entity", - label: "Entity", - }, + // { + // key: "entity", + // label: "Entity", + // }, { key: "entity_did", label: "Entity DID", }, - { - key: "network", - label: "Network", - }, + // { + // key: "network", + // label: "Network", + // }, ]; export const Client1ProducerTableConfig = [ diff --git a/pkgs/ui/src/config/client_2/index.tsx b/pkgs/ui/src/config/client_2/index.tsx index c9528d8..a971098 100644 --- a/pkgs/ui/src/config/client_2/index.tsx +++ b/pkgs/ui/src/config/client_2/index.tsx @@ -16,18 +16,18 @@ export const Client2ConsumerTableConfig = [ return } }, - { - key: "entity", - label: "Entity", - }, + // { + // key: "entity", + // label: "Entity", + // }, { key: "entity_did", label: "Entity DID", }, - { - key: "network", - label: "Network", - }, + // { + // key: "network", + // label: "Network", + // }, ]; export const Client2ProducerTableConfig = [