Skip to content

Commit

Permalink
Merge pull request #194 from kaleido-io/ns-query-update
Browse files Browse the repository at this point in the history
use selected namespace in API calls
  • Loading branch information
dechdev authored Sep 15, 2022
2 parents bfe0462 + 406253c commit 659bfb2
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/components/Accordions/DataViewerAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -25,6 +26,7 @@ export const DataViewAccordion: React.FC<Props> = ({
data,
}) => {
const [expanded, setExpanded] = useState<boolean>(isOpen);
const { selectedNamespace } = useContext(ApplicationContext);

return (
<Accordion
Expand All @@ -39,7 +41,12 @@ export const DataViewAccordion: React.FC<Props> = ({
}
rightContent={
data.blob ? (
<DownloadButton isBlob url={data.id} filename={data.blob.name} />
<DownloadButton
isBlob
url={data.id}
namespace={selectedNamespace}
filename={data.blob.name}
/>
) : (
<DownloadJsonButton
jsonString={JSON.stringify(data.value)}
Expand Down
1 change: 1 addition & 0 deletions src/components/Accordions/MessageDataAccordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const MessageDataAccordion: React.FC<Props> = ({
isBlob
url={data.id}
filename={data.blob.name}
namespace={selectedNamespace}
/>
) : (
<DownloadJsonButton
Expand Down
10 changes: 8 additions & 2 deletions src/components/Buttons/DownloadButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ interface Props {
filename?: string;
isBlob: boolean;
url: string;
namespace: string;
}

export const DownloadButton: React.FC<Props> = ({ filename, isBlob, url }) => {
export const DownloadButton: React.FC<Props> = ({
filename,
isBlob,
url,
namespace,
}) => {
return (
<IconButton
onClick={(e) => {
e.stopPropagation();
isBlob
? downloadBlobFile(url, filename)
? downloadBlobFile(url, namespace, filename)
: downloadExternalFile(url, filename);
}}
>
Expand Down
1 change: 1 addition & 0 deletions src/components/Lists/ApiList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const ApiList: React.FC<Props> = ({ api }) => {
filename={api.name}
url={api.urls.openapi}
isBlob={false}
namespace={selectedNamespace}
/>
<FFCopyButton value={api.urls.openapi} />
</>
Expand Down
6 changes: 5 additions & 1 deletion src/components/Slides/IdentitySlide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -37,6 +38,7 @@ export const IdentitySlide: React.FC<Props> = ({ did, open, onClose }) => {
const { reportFetchError } = useContext(SnackbarContext);
const { t } = useTranslation();
const [identity, setIdentity] = useState<IIdentity>();
const { selectedNamespace } = useContext(ApplicationContext);

const [isMounted, setIsMounted] = useState(false);
useEffect(() => {
Expand All @@ -49,7 +51,9 @@ export const IdentitySlide: React.FC<Props> = ({ did, open, onClose }) => {
useEffect(() => {
isMounted &&
fetchCatcher(
`${FF_Paths.apiPrefix}${FF_Paths.networkIdentitiesByDID(
`${
FF_Paths.nsPrefix
}/${selectedNamespace}/${FF_Paths.networkIdentitiesByDID(
did
)}?fetchverifiers`
)
Expand Down
1 change: 1 addition & 0 deletions src/pages/Blockchain/views/Apis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export const BlockchainApis: () => JSX.Element = () => {
filename={api.name}
url={api.urls.openapi}
isBlob={false}
namespace={selectedNamespace}
/>
),
},
Expand Down
1 change: 1 addition & 0 deletions src/pages/Blockchain/views/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ export const BlockchainDashboard: () => JSX.Element = () => {
filename={api.name}
url={api.urls.openapi}
isBlob={false}
namespace={selectedNamespace}
/>
),
},
Expand Down
7 changes: 6 additions & 1 deletion src/pages/Off-Chain/views/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,12 @@ export const OffChainDashboard: () => JSX.Element = () => {
},
{
value: data.blob ? (
<DownloadButton isBlob url={data.id} filename={data.blob?.name} />
<DownloadButton
isBlob
url={data.id}
filename={data.blob?.name}
namespace={selectedNamespace}
/>
) : (
<FFTableText color="secondary" text={t('noBlobInData')} />
),
Expand Down
7 changes: 6 additions & 1 deletion src/pages/Off-Chain/views/Data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ export const OffChainData: () => JSX.Element = () => {
},
{
value: d.blob && (
<DownloadButton isBlob url={d.id} filename={d.blob?.name} />
<DownloadButton
isBlob
url={d.id}
filename={d.blob?.name}
namespace={selectedNamespace}
/>
),
},
],
Expand Down
8 changes: 6 additions & 2 deletions src/utils/files.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 659bfb2

Please sign in to comment.