Skip to content

Commit

Permalink
feat: use useAsync for getting workflow landing url (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterckx committed Oct 25, 2024
1 parent 93902bc commit aebedc5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions app/components/Entity/components/AnalysisMethod/analysisMethod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
ANCHOR_TARGET,
REL_ATTRIBUTE,
} from "@databiosphere/findable-ui/lib/components/Links/common/entities";
import { useAsync } from "@databiosphere/findable-ui/src/hooks/useAsync";
import { Card } from "@mui/material";
import { WORKFLOW_IDS_BY_ANALYSIS_METHOD } from "app/apis/catalog/brc-analytics-catalog/common/constants";
import { getWorkflowLandingUrl } from "app/utils/galaxy-api";
import { useState } from "react";
import { ANALYSIS_METHOD } from "../../../../apis/catalog/brc-analytics-catalog/common/entities";
import {
StyledButtonPrimary,
Expand All @@ -30,7 +30,7 @@ export const AnalysisMethod = ({
title,
}: AnalysisMethodProps): JSX.Element => {
const workflowId = WORKFLOW_IDS_BY_ANALYSIS_METHOD[analysisMethod];
const [urlIsLoading, setUrlIsLoading] = useState(false);
const { data: landingUrl, isLoading, run } = useAsync<string>();
return (
<Card component={Paper}>
<CardSection>
Expand All @@ -39,23 +39,22 @@ export const AnalysisMethod = ({
<CardText>{text}</CardText>
</StyledCardContent>
<StyledButtonPrimary
disabled={!workflowId || urlIsLoading}
disabled={!workflowId || isLoading}
onClick={async (): Promise<void> => {
if (!workflowId) return;
setUrlIsLoading(true);
const url = await getWorkflowLandingUrl(
workflowId,
genomeVersionAssemblyId
);
setUrlIsLoading(false);
const url =
landingUrl ??
(await run(
getWorkflowLandingUrl(workflowId, genomeVersionAssemblyId)
));
window.open(
url,
ANCHOR_TARGET.BLANK,
REL_ATTRIBUTE.NO_OPENER_NO_REFERRER
);
}}
>
{urlIsLoading ? "Loading..." : "Analyze"}
{isLoading ? "Loading..." : "Analyze"}
</StyledButtonPrimary>
</CardSection>
</Card>
Expand Down

0 comments on commit aebedc5

Please sign in to comment.