diff --git a/app/front-end/src/features/editor/components/editorView/editorView.tsx b/app/front-end/src/features/editor/components/editorView/editorView.tsx index edcd860..368ad4e 100644 --- a/app/front-end/src/features/editor/components/editorView/editorView.tsx +++ b/app/front-end/src/features/editor/components/editorView/editorView.tsx @@ -165,7 +165,7 @@ export const EditorView: React.FC = () => { const { totalRows, header, rows } = fileContentResponse; if (!header) { - fileStateUpdate(undefined, { columns: [], rows: [], aggregations: {} }, undefined); + fileStateUpdate(undefined, { columns: [], rows: [], aggregations: fileContent.aggregations }, undefined); return; } diff --git a/app/front-end/src/features/editor/components/toolbarView/toolbarGroup.tsx b/app/front-end/src/features/editor/components/toolbarView/toolbarGroup.tsx index 031a267..a5d0d37 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroup.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroup.tsx @@ -1,7 +1,8 @@ -import { List, useTheme } from '@mui/material'; +import { Box, List, useTheme } from '@mui/material'; export interface ToolbarGroupProps { - children: React.ReactNode; + params: React.ReactNode; + buttons: React.ReactNode; } /** @@ -25,24 +26,34 @@ export interface ToolbarGroupProps { * @param {React.ReactNode} children - The child elements to be displayed inside the list. * @returns {JSX.Element} The rendered List component. */ -export const ToolbarGroup: React.FC = ({ children }) => { +export const ToolbarGroup: React.FC = ({ params, buttons }) => { const Theme = useTheme(); return ( - - {children} - + {params} + + {buttons} + + ); }; diff --git a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx index 3044051..c099c10 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx @@ -1,26 +1,90 @@ +import { ToolbarGroupItem, ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; +import { useToolbarContext } from '@/features/editor/hooks'; +import { useStatusContext } from '@/hooks'; import { Deblur as DeblurIcon } from '@mui/icons-material'; +import { useCallback, useMemo } from 'react'; -import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; +export interface ApplyGroupButtonsProps {} -const applySpliceAiClick = () => { - console.log('Clicked Apply SpliceAI Button!'); -}; +export const ApplyGroupButtons: React.FC = () => { + const { blockedStateUpdate } = useStatusContext(); + const { saveTo, override, applyTo, applyErrorStateUpdate } = useToolbarContext(); -const applyCaddClick = () => { - console.log('Clicked Apply CADD Button!'); -}; + const applySpliceAiClick = useCallback(async () => { + if (!applyTo) { + applyErrorStateUpdate('Please select a file'); + return; + } + + blockedStateUpdate(true); + + try { + console.log( + 'Clicked Apply SpliceAI Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n applyTo:', + applyTo + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error applying SpliceAI:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, applyTo]); + + const applyCaddClick = useCallback(async () => { + if (!applyTo) { + applyErrorStateUpdate('Please select a file'); + return; + } -export const ApplyGroupButtons: ToolbarGroupItemProps[] = [ - { - group: 'apply', - icon: DeblurIcon, - label: 'Apply SpliceAI', - onClick: applySpliceAiClick, - }, - { - group: 'apply', - icon: DeblurIcon, - label: 'Apply CADD', - onClick: applyCaddClick, - }, -]; + blockedStateUpdate(true); + + try { + console.log( + 'Clicked Merge LOVD & ClinVar Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n applyTo:', + applyTo + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error applying CADD:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, applyTo]); + + const buttons: ToolbarGroupItemProps[] = useMemo( + () => [ + { + group: 'apply', + icon: DeblurIcon, + label: 'Apply SpliceAI', + onClick: applySpliceAiClick, + }, + { + group: 'apply', + icon: DeblurIcon, + label: 'Apply CADD', + onClick: applyCaddClick, + }, + ], + [applySpliceAiClick, applyCaddClick] + ); + + return ( + <> + {buttons.map((button, index) => ( + + ))} + + ); +}; diff --git a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx index febfd84..39a4133 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx @@ -1,36 +1,107 @@ -import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; - +import { ToolbarGroupItem, ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; +import { useToolbarContext } from '@/features/editor/hooks'; +import { useStatusContext } from '@/hooks'; import { Download as DownloadIcon } from '@mui/icons-material'; +import { useCallback, useMemo } from 'react'; -const handleDownloadLovdClick = () => { - console.log('Clicked Download Lovd Button!'); -}; +export interface DownloadGroupButtonsProps {} -const handleDownloadClinvarClick = () => { - console.log('Clicked Download Clinvar Button!'); -}; +export const DownloadGroupButtons: React.FC = () => { + const { blockedStateUpdate } = useStatusContext(); + const { saveTo, override, gene } = useToolbarContext(); -const handleDownloadGnomadClick = () => { - console.log('Clicked Download Gnomad Button!'); -}; + const handleDownloadLovdClick = useCallback(async () => { + blockedStateUpdate(true); + + try { + console.log( + 'Clicked Download Lovd Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n gene:', + gene + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error downloading LOVD file:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, gene]); + + const handleDownloadClinvarClick = useCallback(async () => { + blockedStateUpdate(true); -export const DownloadGroupButtons: ToolbarGroupItemProps[] = [ - { - group: 'download', - icon: DownloadIcon, - label: 'LOVD', - onClick: handleDownloadLovdClick, - }, - { - group: 'download', - icon: DownloadIcon, - label: 'ClinVar', - onClick: handleDownloadClinvarClick, - }, - { - group: 'download', - icon: DownloadIcon, - label: 'gnomAD', - onClick: handleDownloadGnomadClick, - }, -]; + try { + console.log( + 'Clicked Download Clinvar Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n gene:', + gene + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error downloading ClinVar file:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, gene]); + + const handleDownloadGnomadClick = useCallback(async () => { + blockedStateUpdate(true); + + try { + console.log( + 'Clicked Download Gnomad Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n gene:', + gene + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error downloading gnomAD file:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, gene]); + + const buttons: ToolbarGroupItemProps[] = useMemo( + () => [ + { + group: 'download', + icon: DownloadIcon, + label: 'LOVD', + onClick: handleDownloadLovdClick, + }, + { + group: 'download', + icon: DownloadIcon, + label: 'ClinVar', + onClick: handleDownloadClinvarClick, + }, + { + group: 'download', + icon: DownloadIcon, + label: 'gnomAD', + onClick: handleDownloadGnomadClick, + }, + ], + [handleDownloadLovdClick, handleDownloadClinvarClick, handleDownloadGnomadClick] + ); + + return ( + <> + {buttons.map((button, index) => ( + + ))} + + ); +}; diff --git a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts index 243e3af..5e8bc3b 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts @@ -1,3 +1,6 @@ export { ApplyGroupButtons } from './applyGroupButtons'; +export type { ApplyGroupButtonsProps } from './applyGroupButtons'; export { DownloadGroupButtons } from './downloadGroupButtons'; +export type { DownloadGroupButtonsProps } from './downloadGroupButtons'; export { MergeGroupButtons } from './mergeGroupButtons'; +export type { MergeGroupButtonsProps } from './mergeGroupButtons'; diff --git a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx index 73d2271..f7f585f 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx @@ -1,26 +1,105 @@ +import { ToolbarGroupItem, ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; +import { useToolbarContext } from '@/features/editor/hooks'; +import { useStatusContext } from '@/hooks'; import { MergeType as MergeTypeIcon } from '@mui/icons-material'; +import { useCallback, useMemo } from 'react'; -import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; +export interface MergeGroupButtonsProps {} -const mergeLovdAndGnomadClick = () => { - console.log('Clicked Merge LOVD & gnomAD Button!'); -}; +export const MergeGroupButtons: React.FC = () => { + const { blockedStateUpdate } = useStatusContext(); + const { + saveTo, + override, + lovdFile, + clinvarFile, + gnomadFile, + lovdErrorStateUpdate, + clinvarErrorStateUpdate, + gnomadErrorStateUpdate, + } = useToolbarContext(); -const mergeLovdAndClinvarClick = () => { - console.log('Clicked Merge LOVD & ClinVar Button!'); -}; + const mergeLovdAndGnomadClick = useCallback(async () => { + clinvarErrorStateUpdate(''); + + if (!lovdFile) lovdErrorStateUpdate('Please select a LOVD file'); + if (!gnomadFile) gnomadErrorStateUpdate('Please select a gnomAD file'); + if (!lovdFile || !gnomadFile) return; + + blockedStateUpdate(true); + + try { + console.log( + 'Clicked Merge LOVD & gnomAD Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n lovd:', + lovdFile, + '\n gnomad:', + gnomadFile + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error merging LOVD & gnomAD files:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, lovdFile, gnomadFile]); + + const mergeLovdAndClinvarClick = useCallback(async () => { + gnomadErrorStateUpdate(''); -export const MergeGroupButtons: ToolbarGroupItemProps[] = [ - { - group: 'merge', - icon: MergeTypeIcon, - label: 'Merge LOVD & gnomAD', - onClick: mergeLovdAndGnomadClick, - }, - { - group: 'merge', - icon: MergeTypeIcon, - label: 'Merge LOVD & ClinVar', - onClick: mergeLovdAndClinvarClick, - }, -]; + if (!lovdFile) lovdErrorStateUpdate('Please select a LOVD file'); + if (!clinvarFile) clinvarErrorStateUpdate('Please select a ClinVar file'); + if (!lovdFile || !clinvarFile) return; + + blockedStateUpdate(true); + + try { + console.log( + 'Clicked Merge LOVD & ClinVar Button! Params:\n saveTo:', + saveTo, + '\n override:', + override, + '\n lovd:', + lovdFile, + '\n clinvar:', + clinvarFile + ); + + await new Promise((resolve) => setTimeout(resolve, 1000)); // TODO: remove this line + } catch (error) { + console.error('Error merging LOVD & ClinVar files:', error); + } finally { + blockedStateUpdate(false); + } + }, [saveTo, override, lovdFile, clinvarFile]); + + const buttons: ToolbarGroupItemProps[] = useMemo( + () => [ + { + group: 'merge', + icon: MergeTypeIcon, + label: 'Merge LOVD & gnomAD', + onClick: mergeLovdAndGnomadClick, + }, + { + group: 'merge', + icon: MergeTypeIcon, + label: 'Merge LOVD & ClinVar', + onClick: mergeLovdAndClinvarClick, + }, + ], + [mergeLovdAndGnomadClick, mergeLovdAndClinvarClick] + ); + + return ( + <> + {buttons.map((button, index) => ( + + ))} + + ); +}; diff --git a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx index 8a43dd8..1a24c20 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx @@ -42,7 +42,7 @@ export const ToolbarGroupItem: React.FC = ({ icon: Icon, return (