From 2dcb1e5d05fdc5c8564a1922dde10cfae71e7190 Mon Sep 17 00:00:00 2001 From: Mantvydas Deltuva Date: Thu, 5 Sep 2024 00:54:38 +0300 Subject: [PATCH 1/5] MDE/PKFE-32 implemented status context provider --- app/front-end/src/app/provider.tsx | 6 ++- app/front-end/src/hooks/index.ts | 1 + app/front-end/src/hooks/useStatusContext.ts | 4 ++ app/front-end/src/stores/index.ts | 2 + .../src/stores/statusContextProvider.tsx | 42 +++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 app/front-end/src/hooks/useStatusContext.ts create mode 100644 app/front-end/src/stores/statusContextProvider.tsx diff --git a/app/front-end/src/app/provider.tsx b/app/front-end/src/app/provider.tsx index 31c7e84..40e5c3a 100644 --- a/app/front-end/src/app/provider.tsx +++ b/app/front-end/src/app/provider.tsx @@ -1,4 +1,4 @@ -import { SessionContextProvider, ThemeContextProvider } from '@/stores'; +import { SessionContextProvider, StatusContextProvider, ThemeContextProvider } from '@/stores'; import { CircularProgress } from '@mui/material'; import React from 'react'; @@ -40,7 +40,9 @@ export const AppProvider = ({ children }: AppProviderProps) => { fallback={} > - {children} + + {children} + ); diff --git a/app/front-end/src/hooks/index.ts b/app/front-end/src/hooks/index.ts index 978411d..9bbe3c9 100644 --- a/app/front-end/src/hooks/index.ts +++ b/app/front-end/src/hooks/index.ts @@ -1,2 +1,3 @@ export { useSessionContext } from './useSessionContext'; +export { useStatusContext } from './useStatusContext'; export { useThemeContext } from './useThemeContext'; diff --git a/app/front-end/src/hooks/useStatusContext.ts b/app/front-end/src/hooks/useStatusContext.ts new file mode 100644 index 0000000..ccae9c5 --- /dev/null +++ b/app/front-end/src/hooks/useStatusContext.ts @@ -0,0 +1,4 @@ +import { StatusContext } from '@/stores'; +import { useContext } from 'react'; + +export const useStatusContext = () => useContext(StatusContext); diff --git a/app/front-end/src/stores/index.ts b/app/front-end/src/stores/index.ts index 59d0790..0d28f71 100644 --- a/app/front-end/src/stores/index.ts +++ b/app/front-end/src/stores/index.ts @@ -1,4 +1,6 @@ export { SessionContext, SessionContextProvider } from './sessionContextProvider'; export type { SessionContextProps } from './sessionContextProvider'; +export { StatusContext, StatusContextProvider } from './statusContextProvider'; +export type { StatusContextProps } from './statusContextProvider'; export { ThemeContext, ThemeContextProvider } from './themeContextProvider'; export type { ThemeContextProps } from './themeContextProvider'; diff --git a/app/front-end/src/stores/statusContextProvider.tsx b/app/front-end/src/stores/statusContextProvider.tsx new file mode 100644 index 0000000..02c4607 --- /dev/null +++ b/app/front-end/src/stores/statusContextProvider.tsx @@ -0,0 +1,42 @@ +import { useSessionContext } from '@/hooks'; +import React, { createContext, useEffect, useState } from 'react'; + +export interface StatusContextProps { + blocked: boolean; + blockedStateUpdate: (blocked: boolean) => void; +} + +export const StatusContext = createContext({ + blocked: false, + blockedStateUpdate: () => {}, +}); + +interface Props { + children?: React.ReactNode; +} + +export const StatusContextProvider: React.FC = ({ children }) => { + const [blocked, setBlocked] = useState(false); + + const blockedStateUpdate = (blocked: boolean) => { + setBlocked(blocked); + }; + + const { connected } = useSessionContext(); + + useEffect(() => { + if (!connected) { + setBlocked(true); + return; + } + + setBlocked(false); + }, [connected]); + + const StatusContextValue: StatusContextProps = { + blocked, + blockedStateUpdate, + }; + + return {children}; +}; From d3af32aa47bfbf08cf25a2022339fde0f1f7db39 Mon Sep 17 00:00:00 2001 From: Mantvydas Deltuva Date: Thu, 5 Sep 2024 00:56:38 +0300 Subject: [PATCH 2/5] MDE/PKFE-32 restructured toolbar button data --- .../toolbarGroupButtons/applyGroupButtons.tsx | 26 ---- .../downloadGroupButtons.tsx | 36 ----- .../toolbarView/toolbarGroupButtons/index.ts | 3 - .../toolbarGroupButtons/mergeGroupButtons.tsx | 26 ---- .../toolbarView/toolbarGroupItem.tsx | 4 +- .../components/toolbarView/toolbarView.tsx | 135 ++++++++++++++++-- 6 files changed, 124 insertions(+), 106 deletions(-) delete mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx delete mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx delete mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts delete mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx 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 deleted file mode 100644 index 3044051..0000000 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { Deblur as DeblurIcon } from '@mui/icons-material'; - -import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; - -const applySpliceAiClick = () => { - console.log('Clicked Apply SpliceAI Button!'); -}; - -const applyCaddClick = () => { - console.log('Clicked Apply CADD Button!'); -}; - -export const ApplyGroupButtons: ToolbarGroupItemProps[] = [ - { - group: 'apply', - icon: DeblurIcon, - label: 'Apply SpliceAI', - onClick: applySpliceAiClick, - }, - { - group: 'apply', - icon: DeblurIcon, - label: 'Apply CADD', - onClick: applyCaddClick, - }, -]; 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 deleted file mode 100644 index febfd84..0000000 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; - -import { Download as DownloadIcon } from '@mui/icons-material'; - -const handleDownloadLovdClick = () => { - console.log('Clicked Download Lovd Button!'); -}; - -const handleDownloadClinvarClick = () => { - console.log('Clicked Download Clinvar Button!'); -}; - -const handleDownloadGnomadClick = () => { - console.log('Clicked Download Gnomad Button!'); -}; - -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, - }, -]; 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 deleted file mode 100644 index 243e3af..0000000 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export { ApplyGroupButtons } from './applyGroupButtons'; -export { DownloadGroupButtons } from './downloadGroupButtons'; -export { MergeGroupButtons } 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 deleted file mode 100644 index 73d2271..0000000 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { MergeType as MergeTypeIcon } from '@mui/icons-material'; - -import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; - -const mergeLovdAndGnomadClick = () => { - console.log('Clicked Merge LOVD & gnomAD Button!'); -}; - -const mergeLovdAndClinvarClick = () => { - console.log('Clicked Merge LOVD & ClinVar Button!'); -}; - -export const MergeGroupButtons: ToolbarGroupItemProps[] = [ - { - group: 'merge', - icon: MergeTypeIcon, - label: 'Merge LOVD & gnomAD', - onClick: mergeLovdAndGnomadClick, - }, - { - group: 'merge', - icon: MergeTypeIcon, - label: 'Merge LOVD & ClinVar', - onClick: mergeLovdAndClinvarClick, - }, -]; 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 707773b..789a501 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx @@ -5,6 +5,7 @@ export interface ToolbarGroupItemProps { group: string; icon: SvgIconComponent; label: string; + disabled: boolean; onClick: () => void; } @@ -34,13 +35,14 @@ export interface ToolbarGroupItemProps { * @param {Function} onClick - The function to be called when the button is clicked. * @returns {JSX.Element} The rendered Button component with an icon and label. */ -export const ToolbarGroupItem: React.FC = ({ icon: Icon, label, onClick }) => { +export const ToolbarGroupItem: React.FC = ({ icon: Icon, label, disabled, onClick }) => { const Theme = useTheme(); return ( = (file) => { const Theme = useTheme(); const Workspace = useWorkspaceContext(); + const { blocked } = useStatusContext(); const { id, label } = file; @@ -39,9 +41,13 @@ export const FilebarGroupItem: React.FC = (file) => { borderRadius: '0rem', ':hover': { backgroundColor: - Workspace.file.id === id ? Theme.palette.background.default : alpha(Theme.palette.background.default, 0.5), + Workspace.file.id === id + ? Theme.palette.background.default + : blocked + ? Theme.palette.action.selected + : alpha(Theme.palette.background.default, 0.5), }, - cursor: 'pointer', + cursor: blocked ? 'default' : 'pointer', display: 'flex', flexDirection: 'row', alignItems: 'center', @@ -49,8 +55,10 @@ export const FilebarGroupItem: React.FC = (file) => { }} onClick={() => { // Update the workspace to the selected file - Workspace.fileStateUpdate(file); - Workspace.filesHistoryStateUpdate(file); + if (!blocked) { + Workspace.fileStateUpdate(file); + Workspace.filesHistoryStateUpdate(file); + } }} > = (file) => { { event.stopPropagation(); }} diff --git a/app/front-end/src/features/editor/stores/workspaceContextProvider.tsx b/app/front-end/src/features/editor/stores/workspaceContextProvider.tsx index 1eecacf..7a87392 100644 --- a/app/front-end/src/features/editor/stores/workspaceContextProvider.tsx +++ b/app/front-end/src/features/editor/stores/workspaceContextProvider.tsx @@ -1,5 +1,5 @@ import { FileContentModel, FileModel, FilePaginationModel, FileTypes } from '@/features/editor/types'; -import { useSessionContext } from '@/hooks'; +import { useSessionContext, useStatusContext } from '@/hooks'; import { axios, socket } from '@/lib'; import { Endpoints, Events } from '@/types'; import { TreeViewBaseItem } from '@mui/x-tree-view'; @@ -149,8 +149,11 @@ export const WorkspaceContextProvider: React.FC = ({ children }) => { const [fileTreeIsLoading, setFileTreeIsLoading] = useState(true); const [fileTree, setFileTree] = useState[]>([]); + const { blockedStateUpdate } = useStatusContext(); + const getWorkspace = useCallback(async () => { setFileTreeIsLoading(true); + blockedStateUpdate(true); try { const response = await axios.get(Endpoints.WORKSPACE); setFileTree(response.data); @@ -158,6 +161,7 @@ export const WorkspaceContextProvider: React.FC = ({ children }) => { console.error('Failed to fetch workspace data:', error); } finally { setFileTreeIsLoading(false); + blockedStateUpdate(false); } }, []); From 8d12237ac793227faa2bb84aab32f17443549e61 Mon Sep 17 00:00:00 2001 From: Mantvydas Deltuva Date: Thu, 5 Sep 2024 01:04:43 +0300 Subject: [PATCH 4/5] MDE/PKFE-32 bug-fix --- app/back-end/src/routes/workspace_aggregate_route.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/back-end/src/routes/workspace_aggregate_route.py b/app/back-end/src/routes/workspace_aggregate_route.py index 87a245d..4db5cf6 100644 --- a/app/back-end/src/routes/workspace_aggregate_route.py +++ b/app/back-end/src/routes/workspace_aggregate_route.py @@ -104,11 +104,7 @@ def get_workspace_aggregate_all(relative_path): or header_values[field] == float("-inf") or ( header_values[field] == float(0) - and ( - header_actions[field] != "min" - or header_actions[field] != "max" - or header_actions[field] != "cnt" - ) + and header_actions[field] not in ["min", "max", "cnt"] ) else ( str(int(header_values[field])) From 1fb82da040b65b3a9ea2ad0fa13ede94028113e7 Mon Sep 17 00:00:00 2001 From: Mantvydas Deltuva Date: Thu, 5 Sep 2024 16:12:42 +0300 Subject: [PATCH 5/5] MDE/PKFE-32 changes to toolbar --- .../toolbarGroupButtons/applyGroupButtons.tsx | 26 ++++ .../downloadGroupButtons.tsx | 36 ++++++ .../toolbarView/toolbarGroupButtons/index.ts | 3 + .../toolbarGroupButtons/mergeGroupButtons.tsx | 26 ++++ .../toolbarView/toolbarGroupItem.tsx | 7 +- .../components/toolbarView/toolbarView.tsx | 116 +----------------- 6 files changed, 100 insertions(+), 114 deletions(-) create mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx create mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx create mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts create mode 100644 app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx 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 new file mode 100644 index 0000000..3044051 --- /dev/null +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/applyGroupButtons.tsx @@ -0,0 +1,26 @@ +import { Deblur as DeblurIcon } from '@mui/icons-material'; + +import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; + +const applySpliceAiClick = () => { + console.log('Clicked Apply SpliceAI Button!'); +}; + +const applyCaddClick = () => { + console.log('Clicked Apply CADD Button!'); +}; + +export const ApplyGroupButtons: ToolbarGroupItemProps[] = [ + { + group: 'apply', + icon: DeblurIcon, + label: 'Apply SpliceAI', + onClick: applySpliceAiClick, + }, + { + group: 'apply', + icon: DeblurIcon, + label: 'Apply CADD', + onClick: applyCaddClick, + }, +]; 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 new file mode 100644 index 0000000..febfd84 --- /dev/null +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/downloadGroupButtons.tsx @@ -0,0 +1,36 @@ +import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; + +import { Download as DownloadIcon } from '@mui/icons-material'; + +const handleDownloadLovdClick = () => { + console.log('Clicked Download Lovd Button!'); +}; + +const handleDownloadClinvarClick = () => { + console.log('Clicked Download Clinvar Button!'); +}; + +const handleDownloadGnomadClick = () => { + console.log('Clicked Download Gnomad Button!'); +}; + +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, + }, +]; 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 new file mode 100644 index 0000000..243e3af --- /dev/null +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/index.ts @@ -0,0 +1,3 @@ +export { ApplyGroupButtons } from './applyGroupButtons'; +export { DownloadGroupButtons } from './downloadGroupButtons'; +export { MergeGroupButtons } 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 new file mode 100644 index 0000000..73d2271 --- /dev/null +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupButtons/mergeGroupButtons.tsx @@ -0,0 +1,26 @@ +import { MergeType as MergeTypeIcon } from '@mui/icons-material'; + +import { ToolbarGroupItemProps } from '@/features/editor/components/toolbarView'; + +const mergeLovdAndGnomadClick = () => { + console.log('Clicked Merge LOVD & gnomAD Button!'); +}; + +const mergeLovdAndClinvarClick = () => { + console.log('Clicked Merge LOVD & ClinVar Button!'); +}; + +export const MergeGroupButtons: ToolbarGroupItemProps[] = [ + { + group: 'merge', + icon: MergeTypeIcon, + label: 'Merge LOVD & gnomAD', + onClick: mergeLovdAndGnomadClick, + }, + { + group: 'merge', + icon: MergeTypeIcon, + label: 'Merge LOVD & ClinVar', + onClick: mergeLovdAndClinvarClick, + }, +]; 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 789a501..8a43dd8 100644 --- a/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx +++ b/app/front-end/src/features/editor/components/toolbarView/toolbarGroupItem.tsx @@ -1,3 +1,4 @@ +import { useStatusContext } from '@/hooks'; import { SvgIconComponent } from '@mui/icons-material'; import { alpha, Box, Button, useTheme } from '@mui/material'; @@ -5,7 +6,6 @@ export interface ToolbarGroupItemProps { group: string; icon: SvgIconComponent; label: string; - disabled: boolean; onClick: () => void; } @@ -35,14 +35,15 @@ export interface ToolbarGroupItemProps { * @param {Function} onClick - The function to be called when the button is clicked. * @returns {JSX.Element} The rendered Button component with an icon and label. */ -export const ToolbarGroupItem: React.FC = ({ icon: Icon, label, disabled, onClick }) => { +export const ToolbarGroupItem: React.FC = ({ icon: Icon, label, onClick }) => { const Theme = useTheme(); + const { blocked } = useStatusContext(); return (