From bac39dee3da58f6067377bcb3508c9555d147639 Mon Sep 17 00:00:00 2001 From: Daniel Kurtz Date: Tue, 16 Jul 2024 15:00:23 +0200 Subject: [PATCH 1/2] Added information about contract agreements --- src/frontend/actions/api.ts | 21 ++++++++- src/frontend/app/dashboard/upload/page.tsx | 52 +++++++++++++++++++++- 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/frontend/actions/api.ts b/src/frontend/actions/api.ts index f10b189..24fd17e 100644 --- a/src/frontend/actions/api.ts +++ b/src/frontend/actions/api.ts @@ -347,7 +347,7 @@ export async function negotiateContract(item: CatalogItem) { } } -interface ContractAgreement { +export interface ContractAgreement { providerId: string; [key: string]: any; } @@ -371,6 +371,25 @@ export async function getNegotiatedContracts(counterpartyname: string) { } } +export async function getNegotiatedContractsAsProvider() { + try { + const response = await fetch("/api/getNegotiatedContracts", { + method: "GET" + }); + if (!response.ok) { + throw new Error(`API call failed with status ${response.status}`); + } + + const data: ContractAgreement[] = await response.json(); + + return data.filter(item => item.providerId === process.env.NEXT_PUBLIC_CONNECTOR_NAME); + + } catch (err) { + console.error('Error getting contract agreement info: ', err); + throw new Error('Failed to get contract agreement info'); + } +} + export async function getContractAgreementInfo(agreementId: string) { try { const response = await fetch("/api/getContractAgreementInfo", { diff --git a/src/frontend/app/dashboard/upload/page.tsx b/src/frontend/app/dashboard/upload/page.tsx index 679f954..75f205a 100644 --- a/src/frontend/app/dashboard/upload/page.tsx +++ b/src/frontend/app/dashboard/upload/page.tsx @@ -2,7 +2,7 @@ import React, { useState, useEffect } from 'react'; import { ArrowPathIcon, TrashIcon, CloudArrowDownIcon, XCircleIcon, CheckCircleIcon } from '@heroicons/react/24/outline'; -import { createAsset, createContractDefinition, getAssets, uploadFile, getPolicies, fetchCatalogItems, deleteAsset, deleteContractDefinition, deleteFile, getContractDefinitions } from '@/actions/api'; +import { createAsset, createContractDefinition, getAssets, uploadFile, getPolicies, fetchCatalogItems, deleteAsset, deleteContractDefinition, deleteFile, getContractDefinitions, getNegotiatedContractsAsProvider, ContractAgreement } from '@/actions/api'; import { FileInfo, Policy, Asset, CatalogItem } from "@/data/interface/file"; import PolicyDropdown from './PolicyDropdown'; import PolicyModal from './policyModal'; @@ -22,6 +22,8 @@ const UploadPage: React.FC = () => { const [policies, setPolicies] = useState([]); const [isSubmitted, setIsSubmitted] = useState(false); const [hoveredItem, setHoveredItem] = useState(null); + const [hoveredAgreementCount, setHoveredAgreementCount] = useState(null); + const [contractAgreements, setContractAgreements] = useState([]); const [loadingAssets, setLoadingAssets] = useState(false); @@ -37,6 +39,13 @@ const UploadPage: React.FC = () => { setHoveredItem(null); } + const handleMouseEnterAgreement = (fileId: string) => { + setHoveredAgreementCount(fileId); + } + const handleMouseLeaveAgreement = () => { + setHoveredAgreementCount(null); + } + const getPolicyInfo = (policyId: string) => { const policy = policies.find(policy => policy.id === policyId); return policy || null; @@ -55,6 +64,7 @@ const UploadPage: React.FC = () => { setFiles(assets); const ownContractDefinitions = await getContractDefinitions(); setContractDefinitions(ownContractDefinitions); + await fetchContractAgreements(); } catch (error) { console.error('Error fetching assets:', error); toast.error("There was an error fetching the assets"); @@ -63,6 +73,32 @@ const UploadPage: React.FC = () => { } }; + const fetchContractAgreements = async () => { + try { + setContractAgreements(await getNegotiatedContractsAsProvider()); + } catch (error) { + console.error("Error fetching negotiated contracts: ", error); + toast.error("There was an error fetching the contract agreements"); + } + + } + + const countContracts = (assetId: string) => { + let count = 0 + for (const agreement of contractAgreements) { + if (agreement.assetId === assetId) count++; + } + return count; + } + + const getAgreementConsumerIds = (assetId: string) => { + const consumerIdSet = new Set(); + for (const agreement of contractAgreements) { + if (agreement.assetId === assetId) consumerIdSet.add(agreement.consumerId); + } + return Array.from(consumerIdSet); + } + const deleteCallback = async (asset: Asset) => { try { await deleteContractDefinition("contract-" + asset.id) @@ -209,7 +245,7 @@ const UploadPage: React.FC = () => { - {['Title', 'Name', 'Size', 'Date', 'Author', 'Content Type', 'Offered', 'Actions'].map((label) => ( + {['Title', 'Name', 'Size', 'Date', 'Author', 'Content Type', 'Negotiated', 'Offered', 'Actions'].map((label) => ( @@ -227,6 +263,18 @@ const UploadPage: React.FC = () => { + {catalogItems.map((item) => ( - + @@ -188,7 +188,7 @@ const DownloadPage: React.FC = () => { {negotiatedContracts.map((item) => ( - + diff --git a/src/frontend/app/dashboard/upload/page.tsx b/src/frontend/app/dashboard/upload/page.tsx index 75f205a..e9190ac 100644 --- a/src/frontend/app/dashboard/upload/page.tsx +++ b/src/frontend/app/dashboard/upload/page.tsx @@ -257,7 +257,7 @@ const UploadPage: React.FC = () => { const policy = getPolicyFromContract("contract-" + file.id); return ( - +
{label} {file.date} {file.author} {file.contenttype} handleMouseEnterAgreement(file.id)} onMouseLeave={() => handleMouseLeaveAgreement()}> + {countContracts(file.id)} + + { (hoveredAgreementCount === file.id && countContracts(file.id) !== 0) && ( +
+
+
AGREED WITH
+
{getAgreementConsumerIds(file.id).join(", ")}
+
+
+ )} +
{isOffered(file.id) ? ( From 3ed91b7149dc148415019495bba2d2a2c67b5592 Mon Sep 17 00:00:00 2001 From: Daniel Kurtz Date: Tue, 16 Jul 2024 15:06:46 +0200 Subject: [PATCH 2/2] Minor style changes --- src/frontend/app/dashboard/download/page.tsx | 4 ++-- src/frontend/app/dashboard/upload/page.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/frontend/app/dashboard/download/page.tsx b/src/frontend/app/dashboard/download/page.tsx index a69bde9..543d7cc 100644 --- a/src/frontend/app/dashboard/download/page.tsx +++ b/src/frontend/app/dashboard/download/page.tsx @@ -152,7 +152,7 @@ const DownloadPage: React.FC = () => {
{item.title}{item.title} {item.name} {item.size} {item.date}
{item.title}{item.title} {item.fileName} {item.fileSize} {item.date}
{file.title}{file.title} {file.name} {file.size} {file.date}