Before Milestone Meeting Final Changes #40

Merged
Luis merged 11 commits from final-fixes into main 2023-12-12 22:00:38 +00:00
9 changed files with 136 additions and 52 deletions
Showing only changes of commit 760b4add33 - Show all commits

View File

@@ -266,7 +266,7 @@ def test_entity(api: TestClient) -> None:
request_body = { request_body = {
"did": default_entity_did, "did": default_entity_did,
"name": "C1", "name": "C1",
"ip": "127.0.0.1", "ip": "127.0.0.1:5555",
"attached": False, "attached": False,
"visible": True, "visible": True,
"other": { "other": {
@@ -283,7 +283,7 @@ def test_entity2(api: TestClient) -> None:
request_body = { request_body = {
"did": default_entity_did2, "did": default_entity_did2,
"name": "C2", "name": "C2",
"ip": "127.0.0.2", "ip": "127.0.0.1:5555",
"attached": False, "attached": False,
"visible": True, "visible": True,
"other": { "other": {

View File

@@ -10,6 +10,7 @@ import {
APAttachmentsTableConfig, APAttachmentsTableConfig,
APServiceRepositoryTableConfig, APServiceRepositoryTableConfig,
} from "@/config/access_point"; } from "@/config/access_point";
import { useEffect } from 'react';
export default function AccessPoint() { export default function AccessPoint() {
@@ -28,6 +29,14 @@ export default function AccessPoint() {
} }
} }
useEffect(() => {
const interval = setInterval(() => {
onRefresh();
}, 1000);
return () => clearInterval(interval);
}, []);
return ( return (
<div className="m-10"> <div className="m-10">
<SummaryDetails <SummaryDetails

View File

@@ -1,16 +1,15 @@
"use client"; "use client";
import { useRef } from "react"; import { useEffect, useRef, useState } from "react";
import { import {
Client1ConsumerTableConfig, Client1ConsumerTableConfig,
Client1ProducerTableConfig, Client1ProducerTableConfig,
} from "@/config/client_1"; } from "@/config/client_1";
import CustomTable from "@/components/table"; import CustomTable from "@/components/table";
import useGetEntityByName from "@/components/hooks/useGetEntityById"; import useGetEntityByName from "@/components/hooks/useGetEntityById";
import { Button, Card, CardContent, CardHeader, Skeleton, Typography } from "@mui/material"; import { Alert, Button, Card, CardContent, CardHeader, Skeleton, Snackbar, Typography } from "@mui/material";
import CopyToClipboard from "@/components/copy_to_clipboard"; import CopyToClipboard from "@/components/copy_to_clipboard";
import { mutate } from "swr"; import { mutate } from "swr";
import { useGetEntity } from "@/api/entities/entities"; import { useGetEntity } from "@/api/entities/entities";
import { useGetConsumer } from "@/api/consumers/consumers";
import { BASE_URL } from "@/constants"; import { BASE_URL } from "@/constants";
import axios from "axios"; import axios from "axios";
@@ -18,37 +17,54 @@ export default function Client1() {
const { entity } = useGetEntityByName('C1'); const { entity } = useGetEntityByName('C1');
const { data: client1, isLoading, swrKey: entityKeyFunc } = useGetEntity({ entity_did: entity?.did }) const { data: client1, 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 cardContentRef = useRef(null);
const [isAttached, setIsAttached] = useState(entity?.attached || false);
const [snackbarOpen, setSnackbarOpen] = useState(false);
const [snackbarMessage, setSnackbarMessage] = useState('');
const closeSnackBar = () => {
setSnackbarMessage('');
setSnackbarOpen(false);
}
const onAttachEntity = async () => { const onAttachEntity = async () => {
try { try {
const response = await axios.post(`${BASE_URL}/attach`, { entity_did: entity?.did }); const response = await axios.post(`${BASE_URL}/attach`, { entity_did: entity?.did });
alert(response.data.message); setSnackbarMessage(response.data.message);
setSnackbarOpen(true);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {
setIsAttached(true)
} }
} }
const onDetachEntity = async () => { const onDetachEntity = async () => {
try { try {
const response = await axios.post(`${BASE_URL}/detach`, { entity_did: entity?.did }); const response = await axios.post(`${BASE_URL}/detach`, { entity_did: entity?.did });
console.log('detach', response) console.log(response);
alert('Entity Detached Successfully.'); setSnackbarMessage('Entity detached successfully.');
setSnackbarOpen(true);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {
setIsAttached(false)
} }
} }
const onRefresh = () => { const onRefresh = () => {
const entityKey = typeof entityKeyFunc === 'function' ? entityKeyFunc() : entityKeyFunc; const entityKey = typeof entityKeyFunc === 'function' ? entityKeyFunc() : entityKeyFunc;
const consumerKey = typeof consumerKeyFunc === 'function' ? consumerKeyFunc() : consumerKeyFunc;
if (entityKey) mutate(entityKey); if (entityKey) mutate(entityKey);
if (consumerKey) mutate(consumerKey)
} }
useEffect(() => {
const interval = setInterval(() => {
onRefresh();
}, 1000);
return () => clearInterval(interval);
}, []);
if (isLoading) if (isLoading)
return <Skeleton height={500} /> return <Skeleton height={500} />
@@ -63,12 +79,17 @@ export default function Client1() {
> >
<h2>Client 1</h2> <h2>Client 1</h2>
<div> <div>
<Button onClick={onAttachEntity} className="mr-6" variant="contained">
Attach {isAttached === false ?
</Button> <Button onClick={onAttachEntity} className="mr-6" variant="contained">
<Button onClick={onDetachEntity} className="mr-6" variant="contained"> Attach
Detach </Button>
</Button> :
<Button onClick={onDetachEntity} className="mr-6" variant="contained">
Detach
</Button>
}
<Button onClick={onRefresh} variant="contained">Refresh</Button> <Button onClick={onRefresh} variant="contained">Refresh</Button>
</div> </div>
</div> </div>
@@ -93,8 +114,8 @@ export default function Client1() {
<div> <div>
<h4>Consumer View</h4> <h4>Consumer View</h4>
<CustomTable <CustomTable
loading={loadingConsumerData} loading={isLoading}
data={consumerData?.data} data={client1?.data?.producers}
configuration={Client1ConsumerTableConfig} configuration={Client1ConsumerTableConfig}
/> />
</div> </div>
@@ -106,6 +127,11 @@ export default function Client1() {
configuration={Client1ProducerTableConfig} configuration={Client1ProducerTableConfig}
/> />
</div> </div>
<Snackbar onClose={closeSnackBar} anchorOrigin={{ vertical: 'top', horizontal: 'center' }} open={snackbarOpen} autoHideDuration={1000}>
<Alert severity="success" sx={{ width: '100%' }}>
{snackbarMessage}
</Alert>
</Snackbar>
</div> </div>
); );
} }

View File

@@ -1,15 +1,14 @@
"use client"; "use client";
import { useRef } from "react"; import { useEffect, useRef, useState } from "react";
import { import {
Client2ConsumerTableConfig, Client2ConsumerTableConfig,
Client2ProducerTableConfig, Client2ProducerTableConfig,
} from "@/config/client_2"; } from "@/config/client_2";
import CustomTable from "@/components/table"; import CustomTable from "@/components/table";
import useGetEntityByName from "@/components/hooks/useGetEntityById"; 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 CopyToClipboard from "@/components/copy_to_clipboard";
import { useGetEntity } from "@/api/entities/entities"; import { useGetEntity } from "@/api/entities/entities";
import { useGetConsumer } from "@/api/consumers/consumers";
import { mutate } from "swr"; import { mutate } from "swr";
import axios from "axios"; import axios from "axios";
import { BASE_URL } from "@/constants"; import { BASE_URL } from "@/constants";
@@ -18,8 +17,15 @@ export default function Client2() {
const { entity } = useGetEntityByName('C2'); const { entity } = useGetEntityByName('C2');
const { data: client2, isLoading, swrKey: entityKeyFunc } = useGetEntity({ entity_did: entity?.did }) 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 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 () => { const onAttachEntity = async () => {
try { try {
@@ -28,6 +34,7 @@ export default function Client2() {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {
setIsAttached(true)
} }
} }
@@ -39,16 +46,23 @@ export default function Client2() {
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {
setIsAttached(false)
} }
} }
const onRefresh = () => { const onRefresh = () => {
const entityKey = typeof entityKeyFunc === 'function' ? entityKeyFunc() : entityKeyFunc; const entityKey = typeof entityKeyFunc === 'function' ? entityKeyFunc() : entityKeyFunc;
const consumerKey = typeof consumerKeyFunc === 'function' ? consumerKeyFunc() : consumerKeyFunc;
if (entityKey) mutate(entityKey); if (entityKey) mutate(entityKey);
if (consumerKey) mutate(consumerKey)
} }
useEffect(() => {
const interval = setInterval(() => {
onRefresh();
}, 1000);
return () => clearInterval(interval);
}, []);
if (isLoading) if (isLoading)
return <Skeleton height={500} /> return <Skeleton height={500} />
@@ -63,12 +77,15 @@ export default function Client2() {
> >
<h2>Client 2</h2> <h2>Client 2</h2>
<div> <div>
<Button onClick={onAttachEntity} className="mr-6" variant="contained"> {isAttached === false ?
Attach <Button onClick={onAttachEntity} className="mr-6" variant="contained">
</Button> Attach
<Button onClick={onDetachEntity} className="mr-6" variant="contained"> </Button>
Detach :
</Button> <Button onClick={onDetachEntity} className="mr-6" variant="contained">
Detach
</Button>
}
<Button onClick={onRefresh} variant="contained">Refresh</Button> <Button onClick={onRefresh} variant="contained">Refresh</Button>
</div> </div>
</div> </div>
@@ -93,8 +110,8 @@ export default function Client2() {
<div> <div>
<h4>Consumer View</h4> <h4>Consumer View</h4>
<CustomTable <CustomTable
loading={loadingConsumerData} loading={isLoading}
data={consumerData?.data} data={client2?.data?.producers}
configuration={Client2ConsumerTableConfig} configuration={Client2ConsumerTableConfig}
/> />
</div> </div>
@@ -106,6 +123,11 @@ export default function Client2() {
configuration={Client2ProducerTableConfig} configuration={Client2ProducerTableConfig}
/> />
</div> </div>
<Snackbar onClose={closeSnackBar} anchorOrigin={{ vertical: 'top', horizontal: 'center' }} open={snackbarOpen} autoHideDuration={1000}>
<Alert severity="success" sx={{ width: '100%' }}>
{snackbarMessage}
</Alert>
</Snackbar>
</div> </div>
); );
} }

View File

@@ -4,6 +4,7 @@ import { DLGResolutionTableConfig, DLGSummaryDetails } from "@/config/dlg";
import CustomTable from "@/components/table"; import CustomTable from "@/components/table";
import SummaryDetails from "@/components/summary_card"; import SummaryDetails from "@/components/summary_card";
import useFetch from "@/components/hooks/useFetch"; import useFetch from "@/components/hooks/useFetch";
import { useEffect } from "react";
export default function DLG() { export default function DLG() {
@@ -13,6 +14,14 @@ export default function DLG() {
fetch(); fetch();
} }
useEffect(() => {
const interval = setInterval(() => {
onRefresh();
}, 5000);
return () => clearInterval(interval);
}, []);
return ( return (
<div className="m-10"> <div className="m-10">
<SummaryDetails <SummaryDetails

View File

@@ -5,16 +5,34 @@ import { NoDataOverlay } from "@/components/noDataOverlay";
import SummaryDetails from "@/components/summary_card"; import SummaryDetails from "@/components/summary_card";
import CustomTable from "@/components/table"; import CustomTable from "@/components/table";
import { HomeTableConfig } from "@/config/home"; import { HomeTableConfig } from "@/config/home";
import { useEffect } from "react";
import { mutate } from "swr";
export default function Home() { export default function Home() {
const { data } = useAppState(); const { data } = useAppState();
const entitiesKeyFunc = data.entitiesKeyFunc;
const onRefresh = () => {
const entityKey = typeof entitiesKeyFunc === 'function' ? entitiesKeyFunc() : entitiesKeyFunc;
if (entitiesKeyFunc) mutate(entityKey);
}
useEffect(() => {
const interval = setInterval(() => {
onRefresh();
}, 500);
return () => clearInterval(interval);
}, []);
return ( return (
<div className="m-10"> <div className="m-10">
<SummaryDetails <SummaryDetails
entity={{ name: "Home", details: [] }} entity={{ name: "Home", details: [] }}
hasRefreshButton={false} hasRefreshButton={true}
onRefresh={onRefresh}
hasAttachDetach={false} hasAttachDetach={false}
/> />

View File

@@ -17,11 +17,11 @@ export const APSummaryDetails = [
export const APAttachmentsTableConfig = [ export const APAttachmentsTableConfig = [
{ {
key: "entity_name", key: "name",
label: "Entity name", label: "Entity name",
}, },
{ {
key: "entity_did", key: "did",
label: "Entity DID", label: "Entity DID",
}, },
{ {

View File

@@ -16,18 +16,18 @@ export const Client1ConsumerTableConfig = [
return <Button disabled variant="outlined">Consume</Button> return <Button disabled variant="outlined">Consume</Button>
} }
}, },
{ // {
key: "entity", // key: "entity",
label: "Entity", // label: "Entity",
}, // },
{ {
key: "entity_did", key: "entity_did",
label: "Entity DID", label: "Entity DID",
}, },
{ // {
key: "network", // key: "network",
label: "Network", // label: "Network",
}, // },
]; ];
export const Client1ProducerTableConfig = [ export const Client1ProducerTableConfig = [

View File

@@ -16,18 +16,18 @@ export const Client2ConsumerTableConfig = [
return <Button disabled variant="outlined">Consume</Button> return <Button disabled variant="outlined">Consume</Button>
} }
}, },
{ // {
key: "entity", // key: "entity",
label: "Entity", // label: "Entity",
}, // },
{ {
key: "entity_did", key: "entity_did",
label: "Entity DID", label: "Entity DID",
}, },
{ // {
key: "network", // key: "network",
label: "Network", // label: "Network",
}, // },
]; ];
export const Client2ProducerTableConfig = [ export const Client2ProducerTableConfig = [