-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(runs): added UI to list s3 resources
- Loading branch information
Showing
6 changed files
with
157 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/app/runs/[id]/components/MentionedResources/MentionedResources.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
"use client" | ||
|
||
import { useMemo } from "react" | ||
|
||
type MentionedResourcesProps = { | ||
data?: any | ||
} | ||
|
||
type MatchedResourceLink = { | ||
key: string | ||
url: string | ||
urlName: string | ||
} | ||
|
||
export const MentionedResources = ({ data }: MentionedResourcesProps) => { | ||
const findS3Entries = (dict: any) => { | ||
let result: { [key: string]: string } = {} | ||
|
||
for (let key in dict) { | ||
if (typeof dict[key] === "string" && dict[key].includes("s3://")) { | ||
result[key] = dict[key] | ||
} | ||
if (typeof dict[key] === "object" && dict[key] !== null) { | ||
let nestedResults = findS3Entries(dict[key]) | ||
for (let nestedKey in nestedResults) { | ||
result[nestedKey] = nestedResults[nestedKey] | ||
} | ||
} | ||
} | ||
|
||
return result | ||
} | ||
|
||
const resolveLinks = (dict: any) => { | ||
let result: MatchedResourceLink[] = [] | ||
|
||
for (let key in dict) { | ||
if (dict[key].includes("s3://")) { | ||
const urlName = dict[key].split("s3://")[1] | ||
const url = `https://s3.console.aws.amazon.com/s3/buckets/${urlName}` | ||
result.push({ | ||
key: key, | ||
url: cleanUrl(url), | ||
urlName: dict[key], | ||
}) | ||
} | ||
} | ||
return result | ||
} | ||
|
||
const priorityKeywords = ["output"] | ||
|
||
const hasPriority = (key: string): boolean => { | ||
return priorityKeywords.some((keyword) => key.includes(keyword)) | ||
} | ||
|
||
const sortLinks = (links: MatchedResourceLink[]): MatchedResourceLink[] => { | ||
return links.sort((a, b) => { | ||
if (hasPriority(a.key) && !hasPriority(b.key)) { | ||
return -1 | ||
} else if (!hasPriority(a.key) && hasPriority(b.key)) { | ||
return 1 | ||
} | ||
return 0 | ||
}) | ||
} | ||
|
||
const cleanUrl = (url: string): string => { | ||
// Remove duplicate slashes | ||
url = url.replace(/([^:]\/)\/+/g, "$1") | ||
|
||
// for S3 directories | ||
if (url.includes("s3")) { | ||
const extensionPattern = /\.[0-9a-z]+$/i | ||
|
||
// If the URL doesn't have a file extension | ||
if (!extensionPattern.test(url)) { | ||
// Ensure there's a slash at the end | ||
if (!url.endsWith("/")) { | ||
url += "/" | ||
} | ||
} | ||
} | ||
|
||
console.log(url) | ||
return url | ||
} | ||
|
||
const matches = useMemo(() => (data ? findS3Entries(data) : {}), [data]) | ||
const resolvedLinks = useMemo(() => (matches ? resolveLinks(matches) : []), [matches]) | ||
const sortedLinks = useMemo(() => (resolvedLinks ? sortLinks(resolvedLinks) : []), [resolvedLinks]) | ||
|
||
return ( | ||
<div className="mx-auto"> | ||
<p className="mb-4 text-gray-600 font-sm"> | ||
Below are paths used in Nextflow resources and links to resources (S3) if possible. | ||
</p> | ||
<table className="min-w-full divide-y divide-gray-200"> | ||
<tbody className="bg-white divide-y divide-gray-200"> | ||
{sortedLinks.map((link) => ( | ||
<tr key={link.key}> | ||
<td className="py-2">{link.key}</td> | ||
<td className="py-2"> | ||
<a href={link.url} className="text-blue-500 underline text-sm" target="_blank"> | ||
{link.urlName} | ||
</a> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
// <div> | ||
// <p>Mentioned resources extracts paths used in Nextflow configuration and constructs URLs if possible.</p> | ||
// <ul> | ||
// {Object.entries(matches).map(([key, value]) => ( | ||
// <li key={key}> | ||
// <p> | ||
// {key}- {JSON.stringify(value)} | ||
// </p> | ||
// </li> | ||
// ))} | ||
// </ul> | ||
// </div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { MentionedResources } from "./MentionedResources" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters