Skip to content

Commit 18a149a

Browse files
committed
Prettier fixes
1 parent 6a5351a commit 18a149a

4 files changed

Lines changed: 123 additions & 94 deletions

File tree

Eplant/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const userViews = [
3636
ExperimentEFP,
3737
WorldEFP,
3838
ChromosomeViewer,
39-
NavigatorView
39+
NavigatorView,
4040
]
4141

4242
// List of views that are used to lookup a view by id

Eplant/tutorial.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,14 +372,18 @@ const views = [...genericViews, ...userViews]
372372

373373
#### View Switching Functionality
374374

375-
If your new view has function to swap to a different view and/or gene available on ePlant, you may benefit from the generalized view switching component file (name tbd).
375+
If your new view has function to swap to a different view and/or gene available on ePlant, you may benefit from the generalized view switching component file (name tbd).
376376

377377
To utilize the component:
378-
1. Import createViewSwitchProvider into your index file and export it:
378+
379+
1. Import createViewSwitchProvider into your index file and export it:
380+
379381
```
380382
export const ViewSwitchProvider = createViewSwitchProvider();
381383
```
384+
382385
2. Import your exported provider into your view's main component and wrap your component in the view's return statement:
386+
383387
```
384388
const App = () => {
385389
return (
@@ -389,9 +393,11 @@ const App = () => {
389393
);
390394
};
391395
```
396+
392397
3. Import and use useViewSwitch in your main component whenever you want to invoke the switching functionality. For example: `switchViewAndGene('Cell eFP', geneName);`
393398

394399
There are 3 main swithing functions you can invoke based on needs.
400+
395401
```
396402
/** Function to switch view only */
397403
switchViewOnly: (viewId: string) => Promise<void>;
@@ -401,18 +407,19 @@ There are 3 main swithing functions you can invoke based on needs.
401407
402408
/** Function to switch both view and gene */
403409
switchViewAndGene: (viewId: string, geneName: string, speciesUrl?: string) => Promise<void>;
404-
```
410+
```
405411

406412
## Documentation and Commenting Style
407413

408414
It is important to maintain a common standard for commenting code and documentation. If you want to make contributions to the project, we ask that you follow the TSdoc(typescript) commenting style. As an example this includes adding function/class headers and comments as seen below:
415+
409416
```
410417
/**
411418
* Extracts the primary gene identifier from the API URL
412-
*
419+
*
413420
* @param url - The complete API URL containing query parameters
414421
* @returns The primary gene identifier, or an empty string not found
415-
*
422+
*
416423
* Uses regex to find the primaryGene parameter in the URL
417424
*/
418425
function extractPrimaryGene(url: string): string {

Eplant/util/ErrorBoundary/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ export default class ErrorBoundary extends Component<
88
this.state = { hasError: false }
99
}
1010
componentDidCatch(error: Error, info: ErrorInfo) {
11-
console.log("Error caught by ErrorBoundary:", error.message, info.componentStack);
11+
console.log(
12+
'Error caught by ErrorBoundary:',
13+
error.message,
14+
info.componentStack
15+
)
1216
this.setState({ hasError: true })
1317
}
1418
render() {

Eplant/views/ViewGeneSwitching.tsx

Lines changed: 105 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1-
import { createContext, useContext, useEffect, useState } from 'react';
2-
import _ from 'lodash';
1+
import { createContext, useContext, useEffect, useState } from 'react'
2+
import _ from 'lodash'
3+
4+
import { useConfig } from '@eplant/config'
5+
import GeneticElement from '@eplant/GeneticElement'
6+
import {
7+
useGeneticElements,
8+
useSetActiveGeneId,
9+
useSetActiveViewId,
10+
useSpecies,
11+
} from '@eplant/state'
12+
import { View } from '@eplant/View'
313

4-
import { useConfig } from '@eplant/config';
5-
import GeneticElement from '@eplant/GeneticElement';
6-
import { useGeneticElements, useSetActiveGeneId, useSetActiveViewId, useSpecies } from '@eplant/state';
7-
import { View } from '@eplant/View';
8-
9-
/**
14+
/**
1015
* Interface defining the shape of the ViewSwitch context
1116
*/
1217
interface ViewSwitchContextType {
1318
/** Currently active view */
14-
activeView: View | null;
19+
activeView: View | null
1520
/** Currently active genetic element */
16-
activeGene: GeneticElement | null;
21+
activeGene: GeneticElement | null
1722
/** Function to switch view only */
18-
switchViewOnly: (viewId: string) => Promise<void>;
23+
switchViewOnly: (viewId: string) => Promise<void>
1924
/** Function to switch gene only */
20-
switchGeneOnly: (geneName: string) => Promise<void>;
25+
switchGeneOnly: (geneName: string) => Promise<void>
2126
/** Function to switch both view and gene */
22-
switchViewAndGene: (viewId: string, geneName: string, species?: string) => Promise<void>;
27+
switchViewAndGene: (
28+
viewId: string,
29+
geneName: string,
30+
species?: string
31+
) => Promise<void>
2332
}
2433

2534
/** Default context value */
@@ -29,10 +38,10 @@ const ViewSwitchContext = createContext<ViewSwitchContextType>({
2938
switchViewOnly: async () => {},
3039
switchGeneOnly: async () => {},
3140
switchViewAndGene: async () => {},
32-
});
41+
})
3342

3443
/** Hook to access the ViewSwitch context */
35-
export const useViewSwitch = () => useContext(ViewSwitchContext);
44+
export const useViewSwitch = () => useContext(ViewSwitchContext)
3645

3746
/**
3847
* Creates a ViewSwitch provider component
@@ -44,155 +53,164 @@ export const createViewSwitchProvider = () => {
4453
* @param props - Component props
4554
*/
4655
const ViewSwitchProvider = ({ children }: { children: React.ReactNode }) => {
47-
const [activeView, setActiveView] = useState<View | null>(null);
48-
const [activeGene, setActiveGene] = useState<GeneticElement | null>(null);
49-
const [geneticElements, setGeneticElements] = useGeneticElements();
50-
51-
const { userViews } = useConfig();
52-
const setActiveViewId = useSetActiveViewId();
53-
const setActiveGeneId = useSetActiveGeneId();
54-
const [speciesList] = useSpecies();
55-
const species = speciesList.length ? speciesList[0] : undefined;
56+
const [activeView, setActiveView] = useState<View | null>(null)
57+
const [activeGene, setActiveGene] = useState<GeneticElement | null>(null)
58+
const [geneticElements, setGeneticElements] = useGeneticElements()
59+
60+
const { userViews } = useConfig()
61+
const setActiveViewId = useSetActiveViewId()
62+
const setActiveGeneId = useSetActiveGeneId()
63+
const [speciesList] = useSpecies()
64+
const species = speciesList.length ? speciesList[0] : undefined
5665

5766
/**
5867
* Adds genetic elements to the state, ensuring uniqueness
5968
* @param genes - Array of genetic elements to add
6069
*/
6170
const addGeneticElements = (genes: GeneticElement[]) => {
6271
setGeneticElements((prev) => {
63-
const updatedGenes = _.uniqBy([...prev, ...genes], (gene) => gene.id);
64-
return updatedGenes;
65-
});
72+
const updatedGenes = _.uniqBy([...prev, ...genes], (gene) => gene.id)
73+
return updatedGenes
74+
})
6675

6776
if (genes.length > 0) {
68-
setActiveGeneId(genes[0].id);
77+
setActiveGeneId(genes[0].id)
6978
}
70-
};
79+
}
7180

7281
// Ensure genetic elements remain unique
7382
useEffect(() => {
74-
const uniqueGenes = _.uniqBy(geneticElements, (gene) => gene.id);
83+
const uniqueGenes = _.uniqBy(geneticElements, (gene) => gene.id)
7584
if (uniqueGenes.length !== geneticElements.length) {
76-
setGeneticElements(uniqueGenes);
85+
setGeneticElements(uniqueGenes)
7786
}
78-
}, [geneticElements, setGeneticElements]);
87+
}, [geneticElements, setGeneticElements])
7988

8089
/**
8190
* Validates and retrieves a view by ID
8291
* @param viewId - The ID of the view to validate
8392
* @returns The validated view or null
8493
*/
8594
const validateView = (viewId: string): View | null => {
86-
const targetView = userViews.find((view) => view.id === viewId);
95+
const targetView = userViews.find((view) => view.id === viewId)
8796
if (!targetView) {
88-
console.warn(`View with ID ${viewId} not found`);
89-
return null;
97+
console.warn(`View with ID ${viewId} not found`)
98+
return null
9099
}
91-
return targetView;
92-
};
100+
return targetView
101+
}
93102

94103
/**
95104
* Loads a gene by name
96105
* @param geneName - The name of the gene to load
97106
* @returns The loaded genetic element or null
98107
*/
99-
const loadGene = async (geneName: string): Promise<GeneticElement | null> => {
108+
const loadGene = async (
109+
geneName: string
110+
): Promise<GeneticElement | null> => {
100111
if (!species) {
101-
console.error("Species configuration is missing.");
102-
return null;
112+
console.error('Species configuration is missing.')
113+
return null
103114
}
104115

105116
try {
106-
const loadedGene = await species.api.searchGene(geneName);
107-
return loadedGene as GeneticElement;
117+
const loadedGene = await species.api.searchGene(geneName)
118+
return loadedGene as GeneticElement
108119
} catch (error) {
109-
console.error(`Error loading gene ${geneName}:`, error);
110-
return null;
120+
console.error(`Error loading gene ${geneName}:`, error)
121+
return null
111122
}
112-
};
123+
}
113124

114125
/**
115126
* Handles navigation to external species links
116127
* @param speciesUrl - The URL to navigate to
117128
* @param geneName - The gene identifier
118129
*/
119-
const handleExternalSpecies = (speciesUrl: string, geneName: string): void => {
120-
/** const fullUrl = `${speciesUrl}${geneName}`; */
121-
const fullUrl = `${speciesUrl}`;
122-
window.open(fullUrl, '_blank');
123-
};
130+
const handleExternalSpecies = (
131+
speciesUrl: string,
132+
geneName: string
133+
): void => {
134+
/** const fullUrl = `${speciesUrl}${geneName}`; */
135+
const fullUrl = `${speciesUrl}`
136+
window.open(fullUrl, '_blank')
137+
}
124138

125139
/**
126140
* Switches only the view, keeping the current gene
127141
* @param viewId - ID of the view to switch to
128142
*/
129143
const switchViewOnly = async (viewId: string): Promise<void> => {
130-
131-
const targetView = validateView(viewId);
132-
144+
const targetView = validateView(viewId)
145+
133146
if (targetView) {
134-
setActiveViewId(targetView.id);
135-
setActiveView(targetView);
147+
setActiveViewId(targetView.id)
148+
setActiveView(targetView)
136149
}
137-
};
150+
}
138151

139152
/**
140153
* Switches only the gene, keeping the current view
141154
* @param geneName - Name of the gene to switch to
142155
*/
143-
const switchGeneOnly = async (geneName: string, speciesUrl?: string): Promise<void> => {
144-
156+
const switchGeneOnly = async (
157+
geneName: string,
158+
speciesUrl?: string
159+
): Promise<void> => {
145160
if (speciesUrl) {
146-
handleExternalSpecies(speciesUrl, geneName);
161+
handleExternalSpecies(speciesUrl, geneName)
147162
}
148-
149-
const geneticElement = await loadGene(geneName);
150-
163+
164+
const geneticElement = await loadGene(geneName)
165+
151166
if (geneticElement) {
152-
addGeneticElements([geneticElement]);
153-
setActiveGeneId(geneticElement.id);
154-
setActiveGene(geneticElement);
167+
addGeneticElements([geneticElement])
168+
setActiveGeneId(geneticElement.id)
169+
setActiveGene(geneticElement)
155170
}
156-
};
171+
}
157172

158173
/**
159174
* Switches both view and gene
160175
* @param viewId - ID of the view to switch to
161176
* @param geneName - Name of the gene to switch to
162177
*/
163-
const switchViewAndGene = async (viewId: string, geneName: string, speciesUrl?: string): Promise<void> => {
164-
178+
const switchViewAndGene = async (
179+
viewId: string,
180+
geneName: string,
181+
speciesUrl?: string
182+
): Promise<void> => {
165183
if (speciesUrl) {
166-
handleExternalSpecies(speciesUrl, geneName);
184+
handleExternalSpecies(speciesUrl, geneName)
167185
}
168186

169-
const targetView = validateView(viewId);
170-
const geneticElement = await loadGene(geneName);
187+
const targetView = validateView(viewId)
188+
const geneticElement = await loadGene(geneName)
171189

172190
if (targetView && geneticElement) {
173-
addGeneticElements([geneticElement]);
174-
setActiveViewId(targetView.id);
175-
setActiveView(targetView);
176-
setActiveGeneId(geneticElement.id);
177-
setActiveGene(geneticElement);
191+
addGeneticElements([geneticElement])
192+
setActiveViewId(targetView.id)
193+
setActiveView(targetView)
194+
setActiveGeneId(geneticElement.id)
195+
setActiveGene(geneticElement)
178196
}
179-
};
197+
}
180198

181199
return (
182-
<ViewSwitchContext.Provider
183-
value={{
184-
activeView,
185-
activeGene,
200+
<ViewSwitchContext.Provider
201+
value={{
202+
activeView,
203+
activeGene,
186204
switchViewOnly,
187205
switchGeneOnly,
188-
switchViewAndGene
206+
switchViewAndGene,
189207
}}
190208
>
191209
{children}
192210
</ViewSwitchContext.Provider>
193-
);
194-
};
211+
)
212+
}
195213

196-
ViewSwitchProvider.displayName = 'ViewSwitchProvider';
197-
return ViewSwitchProvider;
198-
};
214+
ViewSwitchProvider.displayName = 'ViewSwitchProvider'
215+
return ViewSwitchProvider
216+
}

0 commit comments

Comments
 (0)