|
| 1 | +/** |
| 2 | + * See the NOTICE file distributed with this work for additional information |
| 3 | + * regarding copyright ownership. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import { Link } from 'react-router-dom'; |
| 18 | + |
| 19 | +import * as urlFor from 'src/shared/helpers/urlHelper'; |
| 20 | + |
| 21 | +import { useAppSelector } from 'src/store'; |
| 22 | + |
| 23 | +import { getSelectedSpecies } from 'src/content/app/tools/vep/state/vep-form/vepFormSelectors'; |
| 24 | + |
| 25 | +import { |
| 26 | + ScientificName, |
| 27 | + AssemblyName |
| 28 | +} from 'src/shared/components/species-name-parts'; |
| 29 | +import PlusButton from 'src/shared/components/plus-button/PlusButton'; |
| 30 | +import TextButton from 'src/shared/components/text-button/TextButton'; |
| 31 | + |
| 32 | +import styles from './VepFormSpeciesSection.module.css'; |
| 33 | + |
| 34 | +/** |
| 35 | + * TODO: Consider the following |
| 36 | + * The component below displays a species label after a species has been selected for VEP analysis. |
| 37 | + * - Is this going to be a recurring pattern of displaying species info outside of tables? |
| 38 | + * - Does it need to show the type information for the selected assembly (is reference, population)? |
| 39 | + * - Does it need to consider user's selection of species info display (as chosen in species manager) |
| 40 | + * The answer may justify exxtracting this into a reusable component. |
| 41 | + */ |
| 42 | + |
| 43 | +const vepSpeciesSelectorUrl = urlFor.vepSpeciesSelector(); |
| 44 | + |
| 45 | +export const VepFormSpecies = (props: { className?: string }) => { |
| 46 | + const selectedSpecies = useAppSelector(getSelectedSpecies); |
| 47 | + |
| 48 | + if (!selectedSpecies) { |
| 49 | + return <Link to={vepSpeciesSelectorUrl}>Select a species / assembly</Link>; |
| 50 | + } |
| 51 | + |
| 52 | + return ( |
| 53 | + <div className={props.className}> |
| 54 | + {selectedSpecies.common_name && ( |
| 55 | + <span className={styles.commonName}>{selectedSpecies.common_name}</span> |
| 56 | + )} |
| 57 | + {!selectedSpecies.common_name && <ScientificName {...selectedSpecies} />}{' '} |
| 58 | + <AssemblyName {...selectedSpecies} /> |
| 59 | + </div> |
| 60 | + ); |
| 61 | +}; |
| 62 | + |
| 63 | +export const VepSpeciesSelectorNavButton = (props: { className?: string }) => { |
| 64 | + const selectedSpecies = useAppSelector(getSelectedSpecies); |
| 65 | + |
| 66 | + return ( |
| 67 | + <Link to={vepSpeciesSelectorUrl} className={props.className}> |
| 68 | + {!selectedSpecies ? <PlusButton /> : <TextButton>Change</TextButton>} |
| 69 | + </Link> |
| 70 | + ); |
| 71 | +}; |
0 commit comments