Skip to content

Commit c27b552

Browse files
MDE/PKFE-31 implemented toolbar context provider
1 parent fc8d067 commit c27b552

File tree

6 files changed

+208
-0
lines changed

6 files changed

+208
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
export { useToolbarContext } from './useToolbarContext';
12
export { useWorkspaceContext } from './useWorkspaceContext';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ToolbarContext } from '@/features/editor/stores';
2+
import { useContext } from 'react';
3+
4+
export const useToolbarContext = () => useContext(ToolbarContext);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
export { ToolbarContext, ToolbarContextProvider } from './toolbarContextProvider';
2+
export type { ToolbarContextProps } from './toolbarContextProvider';
13
export { WorkspaceContext, WorkspaceContextProvider } from './workspaceContextProvider';
24
export type { WorkspaceContextProps } from './workspaceContextProvider';
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
import { GenesEnum } from '@/features/editor/types';
2+
import React, { createContext, useState } from 'react';
3+
4+
export interface ToolbarContextProps {
5+
//
6+
// Universal state properties
7+
//
8+
saveTo: string;
9+
override: boolean;
10+
saveToStateUpdate: (saveTo: string, override?: boolean) => void;
11+
12+
//
13+
// Download state properties
14+
//
15+
gene: GenesEnum;
16+
geneStateUpdate: (gene: GenesEnum) => void;
17+
18+
//
19+
// Merge state properties
20+
//
21+
lovdFile: string;
22+
clinvarFile: string;
23+
gnomadFile: string;
24+
mergeStateUpdate: (lovdFile: string, clinvarFile: string, gnomadFile: string) => void;
25+
26+
lovdError: string;
27+
lovdErrorStateUpdate: (lovdFileError: string) => void;
28+
clinvarError: string;
29+
clinvarErrorStateUpdate: (clinvarFileError: string) => void;
30+
gnomadError: string;
31+
gnomadErrorStateUpdate: (gnomadFileError: string) => void;
32+
33+
//
34+
// Apply state properties
35+
//
36+
applyTo: string;
37+
applyToStateUpdate: (applyTo: string) => void;
38+
39+
applyError: string;
40+
applyErrorStateUpdate: (applyError: string) => void;
41+
}
42+
43+
export const ToolbarContext = createContext<ToolbarContextProps>({
44+
//
45+
// Universal state defaults
46+
//
47+
saveTo: '/', // Root directory (new file)
48+
override: false,
49+
saveToStateUpdate: () => {},
50+
51+
//
52+
// Download state defaults
53+
//
54+
gene: GenesEnum.EYS,
55+
geneStateUpdate: () => {},
56+
57+
//
58+
// Merge state defaults
59+
//
60+
lovdFile: '',
61+
clinvarFile: '',
62+
gnomadFile: '',
63+
mergeStateUpdate: () => {},
64+
65+
lovdError: '',
66+
lovdErrorStateUpdate: () => {},
67+
clinvarError: '',
68+
clinvarErrorStateUpdate: () => {},
69+
gnomadError: '',
70+
gnomadErrorStateUpdate: () => {},
71+
72+
//
73+
// Apply state defaults
74+
//
75+
applyTo: '',
76+
applyToStateUpdate: () => {},
77+
78+
applyError: '',
79+
applyErrorStateUpdate: () => {},
80+
});
81+
82+
interface Props {
83+
children?: React.ReactNode;
84+
}
85+
86+
export const ToolbarContextProvider: React.FC<Props> = ({ children }) => {
87+
/***************
88+
State management
89+
***************/
90+
91+
//
92+
// Universal state
93+
//
94+
const [saveTo, setSaveTo] = useState<string>('/');
95+
const [override, setOverride] = useState<boolean>(false);
96+
97+
const saveToStateUpdate = (saveTo: string, override?: boolean) => {
98+
setSaveTo(saveTo);
99+
if (override !== undefined) setOverride(override);
100+
};
101+
102+
//
103+
// Download state
104+
//
105+
const [gene, setGene] = useState<GenesEnum>(GenesEnum.EYS);
106+
107+
const geneStateUpdate = (gene: GenesEnum) => {
108+
setGene(gene);
109+
};
110+
111+
//
112+
// Merge state
113+
//
114+
const [lovdFile, setLovdFile] = useState<string>('');
115+
const [clinvarFile, setClinvarFile] = useState<string>('');
116+
const [gnomadFile, setGnomadFile] = useState<string>('');
117+
118+
const mergeStateUpdate = (lovdFile: string, clinvarFile: string, gnomadFile: string) => {
119+
setLovdFile(lovdFile);
120+
setClinvarFile(clinvarFile);
121+
setGnomadFile(gnomadFile);
122+
};
123+
124+
const [lovdError, setLovdError] = useState<string>('');
125+
126+
const lovdErrorStateUpdate = (lovdFileError: string) => {
127+
setLovdError(lovdFileError);
128+
};
129+
130+
const [clinvarError, setClinvarError] = useState<string>('');
131+
132+
const clinvarErrorStateUpdate = (clinvarFileError: string) => {
133+
setClinvarError(clinvarFileError);
134+
};
135+
136+
const [gnomadError, setGnomadError] = useState<string>('');
137+
138+
const gnomadErrorStateUpdate = (gnomadFileError: string) => {
139+
setGnomadError(gnomadFileError);
140+
};
141+
142+
//
143+
// Apply state
144+
//
145+
const [applyTo, setApplyTo] = useState<string>('');
146+
147+
const applyToStateUpdate = (applyTo: string) => {
148+
setApplyTo(applyTo);
149+
};
150+
151+
const [applyError, setApplyError] = useState<string>('');
152+
153+
const applyErrorStateUpdate = (applyError: string) => {
154+
setApplyError(applyError);
155+
};
156+
157+
const ToolbarContextValue: ToolbarContextProps = {
158+
//
159+
// Universal state
160+
//
161+
saveTo,
162+
override,
163+
saveToStateUpdate,
164+
165+
//
166+
// Download state
167+
//
168+
gene,
169+
geneStateUpdate,
170+
171+
//
172+
// Merge state
173+
//
174+
lovdFile,
175+
clinvarFile,
176+
gnomadFile,
177+
mergeStateUpdate,
178+
179+
lovdError,
180+
lovdErrorStateUpdate,
181+
clinvarError,
182+
clinvarErrorStateUpdate,
183+
gnomadError,
184+
gnomadErrorStateUpdate,
185+
186+
//
187+
// Apply state
188+
//
189+
applyTo,
190+
applyToStateUpdate,
191+
192+
applyError,
193+
applyErrorStateUpdate,
194+
};
195+
196+
return <ToolbarContext.Provider value={ToolbarContextValue}>{children}</ToolbarContext.Provider>;
197+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export enum GenesEnum {
2+
EYS = 'eys',
3+
}

app/front-end/src/features/editor/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { ConsoleFeedbackTypes } from './consoleFeedback';
22
export type { ConsoleFeedback } from './consoleFeedback';
3+
export { GenesEnum } from './enums/genesEnum';
34
export type { FileDataRequestDTO, FileDataResponseDTO } from './fileData';
45
export { FileTreeItemContextMenuActions } from './fileTreeItemContextMenuActions';
56
export type { FileTreeViewItemProps } from './fileTreeViewItemProps';

0 commit comments

Comments
 (0)