From 2ed4bb3df0674b94e38bd159c93ff3567285bf02 Mon Sep 17 00:00:00 2001 From: Alex Shorsher Date: Thu, 15 Sep 2022 13:28:22 -0400 Subject: [PATCH 1/2] use selected namespace when downloading blobs Signed-off-by: Alex Shorsher --- src/components/Accordions/DataViewerAccordion.tsx | 11 +++++++++-- src/components/Accordions/MessageDataAccordion.tsx | 1 + src/components/Buttons/DownloadButton.tsx | 10 ++++++++-- src/components/Lists/ApiList.tsx | 1 + src/pages/Blockchain/views/Apis.tsx | 1 + src/pages/Blockchain/views/Dashboard.tsx | 1 + src/pages/Off-Chain/views/Dashboard.tsx | 7 ++++++- src/pages/Off-Chain/views/Data.tsx | 7 ++++++- src/utils/files.ts | 8 ++++++-- 9 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/components/Accordions/DataViewerAccordion.tsx b/src/components/Accordions/DataViewerAccordion.tsx index 8b576f20..9eee93f2 100644 --- a/src/components/Accordions/DataViewerAccordion.tsx +++ b/src/components/Accordions/DataViewerAccordion.tsx @@ -5,7 +5,8 @@ import { AccordionSummary, Grid, } from '@mui/material'; -import { useState } from 'react'; +import { useContext, useState } from 'react'; +import { ApplicationContext } from '../../contexts/ApplicationContext'; import { IData } from '../../interfaces'; import { DownloadButton } from '../Buttons/DownloadButton'; import { DownloadJsonButton } from '../Buttons/DownloadJsonButton'; @@ -25,6 +26,7 @@ export const DataViewAccordion: React.FC = ({ data, }) => { const [expanded, setExpanded] = useState(isOpen); + const { selectedNamespace } = useContext(ApplicationContext); return ( = ({ } rightContent={ data.blob ? ( - + ) : ( = ({ isBlob url={data.id} filename={data.blob.name} + namespace={selectedNamespace} /> ) : ( = ({ filename, isBlob, url }) => { +export const DownloadButton: React.FC = ({ + filename, + isBlob, + url, + namespace, +}) => { return ( { e.stopPropagation(); isBlob - ? downloadBlobFile(url, filename) + ? downloadBlobFile(url, namespace, filename) : downloadExternalFile(url, filename); }} > diff --git a/src/components/Lists/ApiList.tsx b/src/components/Lists/ApiList.tsx index 47b0e675..74804bbf 100644 --- a/src/components/Lists/ApiList.tsx +++ b/src/components/Lists/ApiList.tsx @@ -65,6 +65,7 @@ export const ApiList: React.FC = ({ api }) => { filename={api.name} url={api.urls.openapi} isBlob={false} + namespace={selectedNamespace} /> diff --git a/src/pages/Blockchain/views/Apis.tsx b/src/pages/Blockchain/views/Apis.tsx index d9f41974..a79eff70 100644 --- a/src/pages/Blockchain/views/Apis.tsx +++ b/src/pages/Blockchain/views/Apis.tsx @@ -155,6 +155,7 @@ export const BlockchainApis: () => JSX.Element = () => { filename={api.name} url={api.urls.openapi} isBlob={false} + namespace={selectedNamespace} /> ), }, diff --git a/src/pages/Blockchain/views/Dashboard.tsx b/src/pages/Blockchain/views/Dashboard.tsx index 49548136..d44d7a58 100644 --- a/src/pages/Blockchain/views/Dashboard.tsx +++ b/src/pages/Blockchain/views/Dashboard.tsx @@ -247,6 +247,7 @@ export const BlockchainDashboard: () => JSX.Element = () => { filename={api.name} url={api.urls.openapi} isBlob={false} + namespace={selectedNamespace} /> ), }, diff --git a/src/pages/Off-Chain/views/Dashboard.tsx b/src/pages/Off-Chain/views/Dashboard.tsx index 56b01d7b..76b6b93d 100644 --- a/src/pages/Off-Chain/views/Dashboard.tsx +++ b/src/pages/Off-Chain/views/Dashboard.tsx @@ -231,7 +231,12 @@ export const OffChainDashboard: () => JSX.Element = () => { }, { value: data.blob ? ( - + ) : ( ), diff --git a/src/pages/Off-Chain/views/Data.tsx b/src/pages/Off-Chain/views/Data.tsx index 42f9e2c1..73bea886 100644 --- a/src/pages/Off-Chain/views/Data.tsx +++ b/src/pages/Off-Chain/views/Data.tsx @@ -159,7 +159,12 @@ export const OffChainData: () => JSX.Element = () => { }, { value: d.blob && ( - + ), }, ], diff --git a/src/utils/files.ts b/src/utils/files.ts index f350ef5b..adbb12ca 100644 --- a/src/utils/files.ts +++ b/src/utils/files.ts @@ -1,8 +1,12 @@ import { fetchWithCredentials } from './fetches'; -export const downloadBlobFile = async (id: string, filename?: string) => { +export const downloadBlobFile = async ( + id: string, + namespace: string, + filename?: string +) => { const file = await fetchWithCredentials( - `/api/v1/namespaces/default/data/${id}/blob` + `/api/v1/namespaces/${namespace}/data/${id}/blob` ); const blob = await file.blob(); const href = await URL.createObjectURL(blob); From 406253c9064be935341114cb038abf0c4e7f332b Mon Sep 17 00:00:00 2001 From: Alex Shorsher Date: Thu, 15 Sep 2022 13:37:33 -0400 Subject: [PATCH 2/2] use selected namespace in identity query Signed-off-by: Alex Shorsher --- src/components/Slides/IdentitySlide.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/Slides/IdentitySlide.tsx b/src/components/Slides/IdentitySlide.tsx index 0e4a5d99..d7239c84 100644 --- a/src/components/Slides/IdentitySlide.tsx +++ b/src/components/Slides/IdentitySlide.tsx @@ -17,6 +17,7 @@ import { Grid } from '@mui/material'; import React, { useContext, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; +import { ApplicationContext } from '../../contexts/ApplicationContext'; import { SnackbarContext } from '../../contexts/SnackbarContext'; import { FF_Paths, IIdentity } from '../../interfaces'; import { DEFAULT_PADDING } from '../../theme'; @@ -37,6 +38,7 @@ export const IdentitySlide: React.FC = ({ did, open, onClose }) => { const { reportFetchError } = useContext(SnackbarContext); const { t } = useTranslation(); const [identity, setIdentity] = useState(); + const { selectedNamespace } = useContext(ApplicationContext); const [isMounted, setIsMounted] = useState(false); useEffect(() => { @@ -49,7 +51,9 @@ export const IdentitySlide: React.FC = ({ did, open, onClose }) => { useEffect(() => { isMounted && fetchCatcher( - `${FF_Paths.apiPrefix}${FF_Paths.networkIdentitiesByDID( + `${ + FF_Paths.nsPrefix + }/${selectedNamespace}/${FF_Paths.networkIdentitiesByDID( did )}?fetchverifiers` )