-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtermTable.tsx
More file actions
139 lines (130 loc) · 5.03 KB
/
termTable.tsx
File metadata and controls
139 lines (130 loc) · 5.03 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import React from 'react'
import { useViewGeneSetQuery } from '@/graphql';
import GeneSetModal from '@/components/geneSetModal';
import useQsState from '@/utils/useQsState';
import Pagination from '@/components/pagination';
import TermDownloadButton from '@/components/termDownloadButton';
const pageSize = 10
export default function TermTable({ terms }: { terms: { __typename?: "GeneSet" | undefined; term?: string | null | undefined; id?: any; nGeneIds?: number | null | undefined; }[] }) {
const [queryString, setQueryString] = useQsState({ page: '1', f: '' })
const { page, searchTerm, tableSearch } = React.useMemo(() => ({ page: queryString.page ? +queryString.page : 1, searchTerm: queryString.q ?? '', tableSearch: queryString.f || '' }), [queryString])
const dataFiltered = React.useMemo(() =>
terms.filter(el => {
return (el?.term?.toLowerCase().includes(tableSearch.toLowerCase()))
}),
[terms, tableSearch])
const [geneSetId, setGeneSetId] = React.useState(terms[0].id)
const [currTerm, setCurrTerm] = React.useState(terms[0].term)
const [showModal, setShowModal] = React.useState(false)
const genesQuery = useViewGeneSetQuery({
variables: { id: geneSetId }
})
return (
<>
<GeneSetModal geneset={genesQuery?.data?.geneSet?.genes.nodes} term={currTerm} showModal={showModal} setShowModal={setShowModal}></GeneSetModal>
<div className='border m-5 mt-1'>
<div className='join flex flex-row place-content-end items-center pt-3 pr-3'>
<span className="label-text text-base">Search: </span>
<input
type="text"
className="input input-bordered"
value={tableSearch}
onChange={evt => {
setQueryString({ page: '1', f: evt.currentTarget.value, q: queryString.q })
}}
/>
<div className="tooltip" data-tip="Search results">
<button
type="submit"
className="btn join-item"
>🔍</button>
</div>
<div className="tooltip" data-tip="Clear search">
<button
type="reset"
className="btn join-item"
onClick={evt => {
setQueryString({ page: '1', f: '' })
}}
>⌫</button>
</div>
<div className="tooltip" data-tip="Download results">
<TermDownloadButton dataFiltered={dataFiltered} filterTerm={searchTerm || ""} />
</div>
</div>
<table className="table table-xs">
<thead>
<tr>
<th>Term</th>
<th>Perturbation</th>
<th>Cell Line</th>
<th>Timepoint</th>
<th>Concentration</th>
<th>Direction</th>
<th>Gene Set Size</th>
</tr>
</thead>
<tbody>
{dataFiltered?.slice((page-1) * pageSize, page * pageSize).map(el => {
if (!el) return null
const term = el.term
const batch = el?.term?.split('_')[0]
const cellLine = el?.term?.split('_')[1]
const timepoint = el?.term?.split('_')[2]
const batch2 = el?.term?.split('_')[3]
var perturbation = el?.term?.split('_')[4]
if (perturbation?.split(' ').length == 2) perturbation = perturbation?.split(' ')[0] + ' KO'
const concentration = el?.term?.split('_')[5]?.split(' ')[0] ?? 'N/A'
const direction = el?.term?.split(' ')[1]
return (
<tr key={el?.term}>
<td>
{term}
</td>
<td>
{perturbation}
</td>
<td>
{cellLine}
</td>
<td>
{timepoint}
</td>
<td>
{concentration}
</td>
<td>
{direction}
</td>
<td className='w-3/12'>
<button
className='btn btn-xs btn-outline p-2 h-auto'
data-te-toggle="modal"
data-te-target="#geneSetModal"
data-te-ripple-init
data-te-ripple-color="light"
onClick={evt => {
setCurrTerm(el?.term || '')
setGeneSetId(el?.id || '')
setShowModal(true)
}}
><p>View Gene Set ({el?.nGeneIds})</p>
</button>
</td>
</tr>
)
})}
</tbody>
</table>
</div>
<div className="flex flex-col items-center">
<Pagination
page={page}
pageSize={pageSize}
totalCount={dataFiltered?.length}
onChange={newPage => {setQueryString({ page: `${newPage}` })}}
/>
</div>
</>
)
}