11import { CardContent , CardHeader , Card , CardTitle } from './ui/card'
2- import { useState } from 'react'
2+ import { useEffect , useState } from 'react'
33import { Button } from './ui/button'
44import Excel from 'exceljs'
55import FileSaver from 'file-saver'
66import { Bounce , ToastContainer , toast } from 'react-toastify'
77import 'react-toastify/dist/ReactToastify.css'
88import { Database , Download , MoveRight } from 'lucide-react'
99
10+ async function fetchTables (
11+ setTables : React . Dispatch < React . SetStateAction < string [ ] > >
12+ ) : Promise < void > {
13+ console . log ( 'Fetching table names from database...' )
14+ const [ tableNames , error_message ] = await window . api . queryDatabase (
15+ "SELECT name FROM sqlite_master WHERE type='table'"
16+ )
17+ console . log ( 'Received table names:' , tableNames , 'Error message:' , error_message )
18+ if ( ! error_message && Array . isArray ( tableNames ) ) {
19+ setTables ( ( tableNames as { name : string } [ ] ) . map ( ( table ) => table . name ) )
20+ }
21+ }
22+
1023async function exportReports ( sqlQuery : string ) : Promise < void > {
1124 if ( ! sqlQuery || sqlQuery . trim ( ) === '' ) {
1225 toast . error ( 'Please enter a valid SQL query.' )
@@ -46,9 +59,13 @@ async function exportReports(sqlQuery: string): Promise<void> {
4659 }
4760 }
4861}
49-
5062function ExportReports ( { darkMode } : { darkMode : boolean } ) : React . JSX . Element {
5163 const [ inputValue , setInputValue ] = useState ( '' )
64+ const [ tables , setTables ] = useState ( Array < string > ( ) )
65+
66+ useEffect ( ( ) => {
67+ fetchTables ( setTables )
68+ } , [ ] )
5269
5370 return (
5471 < Card className = "flex flex-col" >
@@ -63,12 +80,10 @@ function ExportReports({ darkMode }: { darkMode: boolean }): React.JSX.Element {
6380 < CardContent className = "flex-1 overflow-auto no-scrollbar pr-2" >
6481 < div className = "w-full mb-4 border border-default-medium rounded-base bg-neutral-secondary-medium shadow-xs" >
6582 < div className = "px-4 py-2 bg-neutral-secondary-medium rounded-t-base" >
66- < label htmlFor = "comment" className = "sr-only" >
67- SELECT * FROM application_snapshots
68- </ label >
6983 < textarea
84+ title = { tables . join ( '\n' ) }
7085 id = "comment"
71- className = "block w-full px-0 text-sm text-heading bg-neutral-secondary-medium border-0 focus:ring-0 placeholder:text-body "
86+ className = "block w-full px-0 text-sm text-heading bg-neutral-secondary-medium border-0 focus:ring-0"
7287 placeholder = "Enter your query here..."
7388 required
7489 onChange = { ( e ) => setInputValue ( e . target . value ) }
0 commit comments