Skip to content

Commit 6871c6d

Browse files
committed
Changes to add other species links to the working icons
1 parent 6211fdd commit 6871c6d

2 files changed

Lines changed: 69 additions & 7 deletions

File tree

Eplant/views/NavigatorViewer/NavigatorView.tsx

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import CellEFPIcon from './Icons/CellEFPIcon';
1111
import GeneInfoViewIcon from './Icons/GeneInfoViewerIcon'; /** Placeholder icon for those that are not yet implemented in ePlant3 */
1212
import PlantEFPIcon from './Icons/PlantEFPIcon'
1313
import * as constants from './constants';
14-
//import { NavigatorContext, useViewSwitch, ViewSwitchProvider} from './index';
1514
import { NavigatorContext, ViewSwitchProvider} from './index';
1615

1716

@@ -52,6 +51,21 @@ const grameneLinks: { [key: string]: string } = {
5251
"default": "https://ensembl.gramene.org/Arabidopsis_thaliana/Gene/Summary?g={geneName}"
5352
};
5453

54+
/**
55+
* Static declaration of other ePlant site links for non-Arabidopsis species
56+
*/
57+
const ePlantLinks:{ [key: string]: string } = {
58+
"POPLAR": "https://bar.utoronto.ca/eplant_poplar/",
59+
"SOYBEAN": "https://bar.utoronto.ca/eplant_soybean/",
60+
"M. TRUNCATULA": "https://bar.utoronto.ca/eplant_medicago/",
61+
"TOMATO": "https://bar.utoronto.ca/eplant_tomato/",
62+
"POTATO": "https://bar.utoronto.ca/eplant_potato/",
63+
"GRAPE": "",
64+
"RICE": "https://bar.utoronto.ca/eplant_rice/",
65+
"MAIZE": "https://bar.utoronto.ca/eplant_maize/",
66+
"BARLEY": "https://bar.utoronto.ca/eplant_barley/",
67+
};
68+
5569
/**
5670
* Generate Gramene link based on species and gene name
5771
* @param species - The species name
@@ -916,8 +930,19 @@ useEffect(() => {
916930
onClick={(event) => {
917931
/** Extract the geneName */
918932
const geneName = displayName;
919-
/** Call switch view function to swap the view using designated view id and gene name */
933+
/** Get species from node data or props - default to Arabidopsis */
934+
const species = node.data.metadata?.genome;
935+
920936
switchViewAndGene('plant', geneName);
937+
938+
/** Call switch view function with species information */
939+
if (!species || !(species in ePlantLinks)) {
940+
/** Call switch view function to swap the view using designated view id and gene name */
941+
switchViewAndGene('plant', geneName);
942+
} else {
943+
/** Handle external species navigation */
944+
switchViewAndGene('plant', geneName, ePlantLinks[species]);
945+
}
921946
}}
922947
>
923948
<rect
@@ -945,8 +970,19 @@ useEffect(() => {
945970
onClick={(event) => {
946971
/** Extract the geneName */
947972
const geneName = displayName;
948-
/** Call switch view function to swap the view using designated view id and gene name */
973+
/** Get species from node data or props - default to Arabidopsis */
974+
const species = node.data.metadata?.genome;
975+
949976
switchViewAndGene('Cell eFP', geneName);
977+
978+
/** Call switch view function with species information */
979+
if (!species || !(species in ePlantLinks)) {
980+
/** Call switch view function to swap the view using designated view id and gene name */
981+
switchViewAndGene('Cell eFP', geneName);
982+
} else {
983+
/** Handle external species navigation */
984+
switchViewAndGene('Cell eFP', geneName, ePlantLinks[species]);
985+
}
950986
}}
951987
>
952988
<rect

Eplant/views/ViewGeneSwitching.tsx

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface ViewSwitchContextType {
1919
/** Function to switch gene only */
2020
switchGeneOnly: (geneName: string) => Promise<void>;
2121
/** Function to switch both view and gene */
22-
switchViewAndGene: (viewId: string, geneName: string) => Promise<void>;
22+
switchViewAndGene: (viewId: string, geneName: string, species?: string) => Promise<void>;
2323
}
2424

2525
/** Default context value */
@@ -111,12 +111,25 @@ export const createViewSwitchProvider = () => {
111111
}
112112
};
113113

114+
/**
115+
* Handles navigation to external species links
116+
* @param speciesUrl - The URL to navigate to
117+
* @param geneName - The gene identifier
118+
*/
119+
const handleExternalSpecies = (speciesUrl: string, geneName: string): void => {
120+
/** const fullUrl = `${speciesUrl}${geneName}`; */
121+
const fullUrl = `${speciesUrl}`;
122+
window.open(fullUrl, '_blank');
123+
};
124+
114125
/**
115126
* Switches only the view, keeping the current gene
116127
* @param viewId - ID of the view to switch to
117128
*/
118129
const switchViewOnly = async (viewId: string): Promise<void> => {
130+
119131
const targetView = validateView(viewId);
132+
120133
if (targetView) {
121134
setActiveViewId(targetView.id);
122135
setActiveView(targetView);
@@ -127,8 +140,15 @@ export const createViewSwitchProvider = () => {
127140
* Switches only the gene, keeping the current view
128141
* @param geneName - Name of the gene to switch to
129142
*/
130-
const switchGeneOnly = async (geneName: string): Promise<void> => {
143+
const switchGeneOnly = async (geneName: string, speciesUrl?: string): Promise<void> => {
144+
145+
if (speciesUrl) {
146+
handleExternalSpecies(speciesUrl, geneName);
147+
return;
148+
}
149+
131150
const geneticElement = await loadGene(geneName);
151+
132152
if (geneticElement) {
133153
addGeneticElements([geneticElement]);
134154
setActiveGeneId(geneticElement.id);
@@ -141,7 +161,13 @@ export const createViewSwitchProvider = () => {
141161
* @param viewId - ID of the view to switch to
142162
* @param geneName - Name of the gene to switch to
143163
*/
144-
const switchViewAndGene = async (viewId: string, geneName: string): Promise<void> => {
164+
const switchViewAndGene = async (viewId: string, geneName: string, speciesUrl?: string): Promise<void> => {
165+
166+
if (speciesUrl) {
167+
handleExternalSpecies(speciesUrl, geneName);
168+
return;
169+
}
170+
145171
const targetView = validateView(viewId);
146172
const geneticElement = await loadGene(geneName);
147173

@@ -161,7 +187,7 @@ export const createViewSwitchProvider = () => {
161187
activeGene,
162188
switchViewOnly,
163189
switchGeneOnly,
164-
switchViewAndGene
190+
switchViewAndGene
165191
}}
166192
>
167193
{children}

0 commit comments

Comments
 (0)