-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathindex.tsx
99 lines (83 loc) · 2.79 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
93
94
95
96
97
98
99
import React from 'react'
import { MetaNode } from '@/spec/metanode'
import { z } from 'zod'
import { additional_info_icon, reaction_icon } from '@/icons';
// object: {}
const MetGeneRxnObjC = z.object({
Gene: z.string(),
KEGG_REACTION_ID: z.string(),
KEGG_REACTION_NAME: z.string(),
KEGG_REACTION_EQN: z.string()
});
export type MetGeneRxnObj = z.infer<typeof MetGeneRxnObjC>
// important ref: https://rsinohara.github.io/json-to-zod-react/
// array of objects: [{}]
export const MetGeneRxnObjArrayC = z.array(
MetGeneRxnObjC
)
export type MetGeneRxnObjArray = z.infer<typeof MetGeneRxnObjArrayC>
// array of array of objects: [[{}]]
export const MetGeneRxnObjArray2C = z.array(
MetGeneRxnObjArrayC
)
export type MetGeneRxnObjArray2 = z.infer<typeof MetGeneRxnObjArray2C>
// A unique name for your data type is used here
export const MetGeneRxnTable = MetaNode('MetGeneRxnTable')
// Human readble descriptors about this node should go here
.meta({
label: 'MetGENE Reaction Table',
description: 'MetGENE Reaction Table',
icon: [reaction_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(MetGeneRxnObjArray2C)
// react component rendering your data goes here
.view(data => {
const heading1 = "Gene"
const heading2 = "KEGG Rxn Id"
const heading3 = "KEGG Rxn Name"
const heading4 = "KEGG Rxn Equation"
const contents = data.filter(arrval => arrval.length > 0)
if (contents.length === 0) {
return (
<div className="prose max-w-none">
<h2 className="m-0">MetGENE Reactions</h2>
<span className="text-red-500">No reactions found.</span>
</div>
)
}
return (
<div className="prose max-w-none">
<h2 className="m-0">MetGENE Reactions</h2>
{contents.map((arrayVal:MetGeneRxnObjArray, index:number) => (
<div key={index}>
<table>
<thead>
<tr>
<th>{heading1}</th>
<th>{heading2}</th>
<th>{heading3}</th>
<th>{heading4}</th>
</tr>
</thead>
<tbody>
{arrayVal.map((val:MetGeneRxnObj, i:number) => {
return (
<tr key={i}>
<td>{val.Gene}</td>
<td><a href = {`https://www.kegg.jp/entry/rn:${val.KEGG_REACTION_ID}`} target = "__blank">{val.KEGG_REACTION_ID}</a></td>
<td>{val.KEGG_REACTION_NAME}</td>
<td>{val.KEGG_REACTION_EQN}</td>
</tr>
)
})}
</tbody>
</table>
</div>
))}
</div>
)
})
.build()