11"use client" ;
22import { useState } from "react" ;
33import { styles } from "./Header.style" ;
4- import { Box , Typography , Button } from "@mui/material" ;
4+ import { Box , Typography } from "@mui/material" ;
55import Table from "@/app/components/Table" ;
66import Dialog from "@/app/components/Dialog" ;
7+ import CustomButton from "@/app/components/CustomButton" ;
78import {
89 HeaderProps ,
910 NameAndDescription ,
@@ -14,81 +15,80 @@ import {
1415 SAMPLE_SIZE ,
1516 ATTRIBUTES_BUTTON_TEXT ,
1617 SAMPLE_BUTTON_TEXT ,
18+ NO_HELP_DESCRIPTION ,
1719} from "@/app/general/constants" ;
20+ import { getTableInfo } from "@/app/general/utils" ;
1821
1922export default function Header ( { bot } : HeaderProps ) {
2023 const [ openAttribute , setOpenAttribute ] = useState < boolean > ( false ) ;
2124 const [ openData , setOpenData ] = useState < boolean > ( false ) ;
25+ const [ openHelp , setOpenHelp ] = useState < boolean > ( false ) ;
2226
23- const botHeaders = bot ?. _data . headers ;
24- const botColumns = bot ?. _data . columns ;
25-
26- const rows : generalObject < strOrNum > [ ] = botHeaders . map ( ( _ , index ) => {
27- const row : generalObject < strOrNum > = { } ;
28- botColumns . forEach ( ( col ) => {
29- row [ col . displayName ] = col . rows [ index ] ;
30- } ) ;
31- return row ;
32- } ) ;
33-
27+ const helpDescription = bot ?. _details . helpDescription ;
28+ const { botHeaders, botColumns, rows } = getTableInfo ( bot ) ;
3429 const sampleRows = rows . slice ( 0 , SAMPLE_SIZE ) ;
3530
3631 const attributesRows = botColumns ?. map ( ( column ) => ( {
3732 name : column . displayName ,
3833 description : column . _description ,
3934 } ) ) ;
4035
36+ const buttons = [
37+ { onClick : ( ) => setOpenAttribute ( true ) , text : ATTRIBUTES_BUTTON_TEXT } ,
38+ { onClick : ( ) => setOpenData ( true ) , text : SAMPLE_BUTTON_TEXT } ,
39+ { onClick : ( ) => setOpenHelp ( true ) , text : "Help!" } ,
40+ ] ;
41+
42+ const dialogs = [
43+ {
44+ open : openAttribute ,
45+ setOpen : setOpenAttribute ,
46+ title : "Details of Attributes" ,
47+ children : (
48+ < Table < NameAndDescription >
49+ headers = { [ "name" , "description" ] }
50+ rows = { attributesRows }
51+ />
52+ ) ,
53+ } ,
54+ {
55+ open : openData ,
56+ setOpen : setOpenData ,
57+ title : "Sample of Data" ,
58+ children : (
59+ < Table < generalObject < strOrNum > >
60+ headers = { botHeaders }
61+ rows = { sampleRows }
62+ />
63+ ) ,
64+ } ,
65+ {
66+ open : openHelp ,
67+ setOpen : setOpenHelp ,
68+ title : "Help!" ,
69+ content : helpDescription ?? NO_HELP_DESCRIPTION ,
70+ } ,
71+ ] ;
72+
4173 return (
4274 < Box component = "header" sx = { styles . box } >
43- < Box component = "div" sx = { styles . buttonContainer } >
44- < Button
45- variant = "contained"
46- color = "primary"
47- sx = { styles . attributeButton }
48- onClick = { ( ) => setOpenAttribute ( true ) }
49- >
50- { ATTRIBUTES_BUTTON_TEXT }
51- </ Button >
75+ < Box component = "div" sx = { styles . buttonsContainer } >
76+ { buttons . map ( ( button , index ) => (
77+ < CustomButton key = { index } sx = { styles . button } { ...button } />
78+ ) ) }
5279 </ Box >
5380 < Box component = "div" sx = { styles . typContainer } >
5481 < Typography variant = "h4" component = "h1" >
5582 { bot ?. _details . name as string }
5683 </ Typography >
5784 </ Box >
58- < Box component = "div" sx = { styles . dataContainer } >
59- < Button
60- variant = "contained"
61- color = "primary"
62- sx = { styles . dataButton }
63- onClick = { ( ) => setOpenData ( true ) }
64- >
65- { SAMPLE_BUTTON_TEXT }
66- </ Button >
67- </ Box >
68- < Dialog
69- title = "Details of Attributes"
70- content = ""
71- open = { openAttribute }
72- setOpen = { setOpenAttribute }
73- children = {
74- < Table < NameAndDescription >
75- headers = { [ "name" , "description" ] }
76- rows = { attributesRows }
77- />
78- }
79- > </ Dialog >
80- < Dialog
81- title = "Sample of Data"
82- content = ""
83- open = { openData }
84- setOpen = { setOpenData }
85- children = {
86- < Table < generalObject < strOrNum > >
87- headers = { botHeaders }
88- rows = { sampleRows }
89- />
90- }
91- > </ Dialog >
85+ { dialogs . map ( ( dialog , index ) => (
86+ < Dialog
87+ key = { index }
88+ content = { dialog ?. content ?? "" }
89+ { ...dialog }
90+ />
91+ ) ) }
9292 </ Box >
9393 ) ;
9494}
0 commit comments