Skip to content

Commit

Permalink
add presigned URLs, monthly
Browse files Browse the repository at this point in the history
  • Loading branch information
craigrbarnes committed Feb 13, 2025
1 parent 39d1c71 commit 94f4033
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 24 deletions.
135 changes: 115 additions & 20 deletions src/lib/AnalysisApps/Results/Utils/workflowApi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { gen3Api, GEN3_API } from '@gen3/core';

import { gen3Api, GEN3_API, GEN3_FENCE_API } from '@gen3/core';
import type { FetchBaseQueryError } from '@reduxjs/toolkit/query';
const TAGS = 'GWASWorkflow';
export const GEN3_WORKFLOW_API = process.env.NEXT_PUBLIC_GEN3_WORLFLOW_API || `${GEN3_API}/ga4gh/wes/v2/`;
export const GEN3_WORKFLOW_API =
process.env.NEXT_PUBLIC_GEN3_WORLFLOW_API || `${GEN3_API}/ga4gh/wes/v2/`;

export const ResultsApiTags = gen3Api.enhanceEndpoints({
addTagTypes: [TAGS],
Expand All @@ -21,38 +22,132 @@ export interface WorkflowResponse {
uid: string;
}

interface WorkflowArguments {
parameters: WorkflowParameter[];
}

interface WorkflowOutputs {
parameters: WorkflowParameter[];
}

interface WorkflowParameter {
name: string;
value: string;
default?: string;
enum?: string[];
}

interface WorkflowDetails {
name: string;
phase: string;
gen3username: string;
submittedAt: string;
startedAt: string;
finishedAt: string;
wf_name: string;
arguments: WorkflowArguments;
progress: string;
outputs: WorkflowOutputs;
gen3teamproject: string;
}

export interface PresignedUrl {
url: string;
}

export interface WorkflowMonthly {
workflow_run:number;
workflow_limit:number
}

// Requests Types

interface WorkflowDetailsRequest {
workflowName: string;
workflowUid: string;
}

interface PresignedUrlWorkflowArtifactRequest extends WorkflowDetailsRequest {
artifactName: string;
}

export const getPresignedUrl = async (
uid: string,
fetchWithBQ: any,
method: string = 'download',
) => {
const response = await fetchWithBQ({
url: `${GEN3_FENCE_API}/data/${method}/${uid}`,
});
if (response.error) {
return { error: response.error as FetchBaseQueryError };
}
const data = { data: { url: response.data.url } };
return data;
};

const workflowApi = ResultsApiTags.injectEndpoints({
endpoints: (builder) => ({
getWorkflowDetails: builder.query<
Record<string, unknown>,
WorkflowDetailsRequest
>({
query: ({
workflowName,
workflowUid
}) =>
getWorkflowDetails: builder.query<WorkflowDetails, WorkflowDetailsRequest>({
query: ({ workflowName, workflowUid }) =>
`${GEN3_WORKFLOW_API}status/${workflowName}?uid=${workflowUid}`,
}),
getWorkflows: builder.query<
WorkflowResponse,
string
>({
query: (
currentTeamProject,
) =>
getWorkflows: builder.query<WorkflowResponse, string>({
query: (currentTeamProject) =>
`${GEN3_WORKFLOW_API}workflows?team_projects=${currentTeamProject}`,
}),
getWorkflowsMonthly: builder.query<WorkflowMonthly, void>({
query: () => `${GEN3_WORKFLOW_API}workflows/user-monthly`
}),
getPresignedUrlForWorkflowArtifact: builder.query<
PresignedUrl,
PresignedUrlWorkflowArtifactRequest
>({
async queryFn(args, _queryApi, _extraOptions, fetchWithBQ) {
const { artifactName, workflowName, workflowUid } = args;

const workflowDetailsResponse = await fetchWithBQ({
url: `${GEN3_WORKFLOW_API}status/${workflowName}?uid=${workflowUid}`,
credentials: 'include',
});

if (workflowDetailsResponse.error) {
return {
error: workflowDetailsResponse.error as FetchBaseQueryError,
};
}

const results = (
workflowDetailsResponse.data as WorkflowDetails
)?.outputs?.parameters.filter((entry) => entry.name === artifactName);
if (!results || results.length !== 1) {
return {
error: {
error: `Expected 1 artifact with name ${artifactName}, found: ${
results?.length ?? 'undefined'
}`,
status: 'CUSTOM_ERROR',
} as FetchBaseQueryError,
};
}

const data = await getPresignedUrl(
JSON.parse(results[0].value).did,
fetchWithBQ,
'download',
);

return data;
},
}),
}),
});

export const {
useGetWorkflowDetailsQuery,
useGetWorkflowsQuery
} = workflowApi;
useGetWorkflowsQuery,
useLazyGetWorkflowsQuery,
useGetPresignedUrlForWorkflowArtifactQuery,
useLazyGetPresignedUrlForWorkflowArtifactQuery,
useGetWorkflowsMonthlyQuery
} = workflowApi;
18 changes: 14 additions & 4 deletions src/pages/GWASResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,29 @@ import { Center, Text, Paper } from '@mantine/core';
import {
NavPageLayout,
NavPageLayoutProps,
getNavPageLayoutPropsFromConfig,
getNavPageLayoutPropsFromConfig, ProtectedContent,
} from '@gen3/frontend';
import { GetServerSideProps } from 'next';
import { useGetWorkflowsMonthlyQuery } from '@/lib/AnalysisApps/Results/Utils/workflowApi';

const GWASResults = ({ headerProps, footerProps }: NavPageLayoutProps) => {

const {data, isFetching: isFetchingMonthlyData } = useGetWorkflowsMonthlyQuery();

console.log(data, isFetchingMonthlyData);
return (
<NavPageLayout
{...{ headerProps, footerProps }}
headerData={{
title: 'Gen3 Sample Page',
content: 'Sample Data',
key: 'gen3-sample-page',
title: 'GWAS Results',
content: 'Results of GWAS Workflows',
key: 'gen3-gwas-results',
}}
>



<ProtectedContent>
<div className="w-full m-10">
<Center>
<Paper shadow="md" p="xl" withBorder>
Expand All @@ -26,6 +35,7 @@ const GWASResults = ({ headerProps, footerProps }: NavPageLayoutProps) => {
</Paper>
</Center>
</div>
</ProtectedContent>
</NavPageLayout>
);
};
Expand Down
10 changes: 10 additions & 0 deletions src/pages/api/ga4gh/wes/v2/workflows/user-monthly/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NextApiRequest, NextApiResponse } from 'next';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {

// Get the sourceId from the slug in the path
// const { sourceId } = query;
return res.status(200).json({"workflow_run":0,"workflow_limit":50});
};

export default handler;

0 comments on commit 94f4033

Please sign in to comment.