-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.tsx
92 lines (81 loc) · 3.16 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react'
import { MetaNode } from '@/spec/metanode'
import { z } from 'zod'
import { additional_info_icon, study_icon } from '@/icons';
const MetGeneStudyObjC = z.object({
KEGG_COMPOUND_ID: z.string().url(),
REFMET_NAME: z.string(),
STUDY_ID: z.string(),
});
export type MetGeneStudyObj = z.infer<typeof MetGeneStudyObjC>
// important ref: https://rsinohara.github.io/json-to-zod-react/
// array of objects: [{}]
export const MetGeneStudyObjArrayC = z.array(
MetGeneStudyObjC
)
export type MetGeneStudyObjArray = z.infer<typeof MetGeneStudyObjArrayC>
// A unique name for your data type is used here
export const MetGeneStudyTable = MetaNode('MetGeneStudyTable')
// Human readble descriptors about this node should go here
.meta({
label: 'MetGENE Studies Table',
description: 'Studies table corresponding to gene',
icon: [study_icon, additional_info_icon],
external: true,
})
// this should have a codec which can encode or decode the data type represented by this node
// using zod, a compile-time and runtime type-safe codec can be constructed
.codec(MetGeneStudyObjArrayC)
// react component rendering your data goes here
.view(data => {
const heading1 = "Kegg Compound Id"
const heading2 = "Refmet Name"
const heading3 = "Study Ids"
const studyID_url = "https://www.metabolomicsworkbench.org/data/DRCCMetadata.php?Mode=Study&StudyID="
const contents = data.filter(arrval => arrval.STUDY_ID.split(', ').length > 0)
if (contents.length === 0) {
return (
<div className="prose max-w-none">
<h2 className="m-0">MetGENE Studies</h2>
<span className="text-red-500">No studies found.</span>
</div>
)
}
return (
<div className="prose max-w-none">
<h2>MetGENE Studies</h2>
<table>
<tr>
<th>{heading1}</th>
<th>{heading2}</th>
<th>{heading3}</th>
</tr>
{data.map((val : MetGeneStudyObj, key : number) => {
var all_study_ids = val.STUDY_ID
var study_id_arr = all_study_ids.split(", ")
const m = /href\s*=\s*["'](.+)["'].*?>?([^><]+)/g.exec(val.KEGG_COMPOUND_ID)
const { url, compound } = m === null ?
{ url: `https://www.kegg.jp/entry/${val.KEGG_COMPOUND_ID}`, compound: val.KEGG_COMPOUND_ID }
: { url: m[1], compound: m[2] }
return (
<tr key={key}>
<>
<td><a href = {url} target = "_blank">{compound}</a></td>
<td><a href = {`https://www.metabolomicsworkbench.org/databases/refmet/refmet_details.php?REFMET_NAME=${val.REFMET_NAME}`} target = "_blank">{val.REFMET_NAME}</a></td>
<td>
{study_id_arr.map((study_id: string, i: number) =>
<>
{i > 0 ? <span>, </span> : null}
<a key={i} href = {`https://www.metabolomicsworkbench.org/data/DRCCMetadata.php?Mode=Study&StudyID=${study_id}`} target = "_blank">{study_id}</a>
</>
)}
</td>
</>
</tr>
)
})}
</table>
</div>
)
})
.build()