11import React , { useState } from "react" ;
2+ import { Table , Paper , ScrollArea , Text , Group , Badge } from "@mantine/core" ;
23import TableFooter from "./TableFooter" ;
34import useTable from "../../hooks/useTable" ;
45import MoleculeStructure from "../tools/toolComp/MoleculeStructure" ;
56import { round } from "mathjs" ;
67
7- const Table = ( { data, rowsPerPage, act_column = [ ] } ) => {
8- const [ page , setPage ] = useState ( 1 ) ;
9- const { slice, range } = useTable ( data , page , rowsPerPage ) ;
10-
11- return (
12- < >
13- < table className = "table" >
14- < thead className = "tableRowHeader" >
15- < tr >
16- < th className = "tableHeader" > ID</ th >
17- < th className = "tableHeader" > SMILES</ th >
18- < th className = "tableHeader" > Representation</ th >
19- { act_column . map ( ( el , i ) => (
20- < th className = "tableHeader" key = { i } > { el } </ th >
21- ) ) }
22- </ tr >
23- </ thead >
24- < tbody >
25- { slice . map ( ( el , i ) => (
26- < tr className = "tableRow" key = { i } >
27- < td className = "tableCell" > { el . id } </ td >
28- < td className = "tableCell" > { el . canonical_smiles } </ td >
29- < td className = "tableCell" > < MoleculeStructure structure = { el . canonical_smiles } id = { i . toString ( ) } /> </ td >
30- { act_column . map ( ( pl , j ) => (
31- < td className = "tableCell" key = { i + j } > { round ( el [ pl ] , 2 ) } </ td >
32- ) ) }
33- </ tr >
34- ) ) }
35- </ tbody >
36- </ table >
37- < TableFooter range = { range } slice = { slice } setPage = { setPage } page = { page } />
38- </ >
39- ) ;
8+ const DataTable = ( { data, rowsPerPage, act_column = [ ] } ) => {
9+ const [ page , setPage ] = useState ( 1 ) ;
10+ const { slice, range } = useTable ( data , page , rowsPerPage ) ;
11+
12+ return (
13+ < Paper
14+ shadow = "md"
15+ radius = "lg"
16+ p = "md"
17+ >
18+ < ScrollArea >
19+ < Table
20+ highlightOnHover
21+ striped
22+ withColumnBorders
23+ horizontalSpacing = "md"
24+ verticalSpacing = "sm"
25+ style = { {
26+ fontSize : "0.9rem" ,
27+ } }
28+ >
29+ < Table . Thead >
30+ < Table . Tr >
31+ < Table . Th >
32+ < Text fw = { 600 } > ID</ Text >
33+ </ Table . Th >
34+ < Table . Th >
35+ < Text fw = { 600 } > SMILES</ Text >
36+ </ Table . Th >
37+ < Table . Th >
38+ < Text fw = { 600 } > Structure</ Text >
39+ </ Table . Th >
40+ { act_column . map ( ( el , i ) => (
41+ < Table . Th key = { i } >
42+ < Text fw = { 600 } > { el } </ Text >
43+ </ Table . Th >
44+ ) ) }
45+ </ Table . Tr >
46+ </ Table . Thead >
47+
48+ < tbody >
49+ { slice . map ( ( el , i ) => (
50+ < Table . Tr key = { i } >
51+ < Table . Td >
52+ < Badge variant = "light" color = "blue" >
53+ { el . id }
54+ </ Badge >
55+ </ Table . Td >
56+
57+ < Table . Td style = { { maxWidth : 260 } } >
58+ < Text size = "sm" truncate >
59+ { el . canonical_smiles }
60+ </ Text >
61+ </ Table . Td >
62+
63+ < Table . Td >
64+ < Group justify = "center" >
65+ < MoleculeStructure
66+ structure = { el . canonical_smiles }
67+ id = { i . toString ( ) }
68+ />
69+ </ Group >
70+ </ Table . Td >
71+
72+ { act_column . map ( ( pl , j ) => (
73+ < Table . Td key = { `${ i } -${ j } ` } >
74+ < Text ta = "right" >
75+ { Number . isFinite ( el [ pl ] ) ? round ( el [ pl ] , 2 ) : "—" }
76+ </ Text >
77+ </ Table . Td >
78+ ) ) }
79+ </ Table . Tr >
80+ ) ) }
81+ </ tbody >
82+ </ Table >
83+ </ ScrollArea >
84+
85+ < Group justify = "center" mt = "md" >
86+ < TableFooter
87+ range = { range }
88+ slice = { slice }
89+ setPage = { setPage }
90+ page = { page }
91+ />
92+ </ Group >
93+ </ Paper >
94+ ) ;
4095} ;
4196
42- export default Table ;
97+ export default DataTable ;
0 commit comments