import classNames from 'classnames'; import _ from 'lodash'; import { observer } from 'mobx-react'; import * as React from 'react'; import Select from 'react-select'; import { Mutation, RemoteData } from 'cbioportal-utils'; import { EnsemblTranscript, VariantAnnotation, } from 'genome-nexus-ts-api-client'; import styles from './transcriptDropdown.module.scss'; export type TranscriptDropdownProps = { showDropDown: boolean; showOnlyAnnotatedTranscriptsInDropdown: boolean; activeTranscript?: string; transcriptsByTranscriptId: { [transcriptId: string]: EnsemblTranscript }; canonicalTranscript: RemoteData; transcriptsWithProteinLength: RemoteData; transcriptsWithAnnotations: RemoteData; indexedVariantAnnotations: RemoteData< { [genomicLocation: string]: VariantAnnotation } | undefined >; mutationsByTranscriptId?: { [transcriptId: string]: Mutation[] }; onChange: (value: string) => void; loadingIndicator?: JSX.Element; }; @observer export default class TranscriptDropdown extends React.Component< TranscriptDropdownProps, {} > { public render() { const { showDropDown, canonicalTranscript, showOnlyAnnotatedTranscriptsInDropdown, activeTranscript, transcriptsByTranscriptId, transcriptsWithProteinLength, transcriptsWithAnnotations, indexedVariantAnnotations, mutationsByTranscriptId, } = this.props; const canonicalTranscriptId = canonicalTranscript.result && canonicalTranscript.result.transcriptId; if (!showDropDown) { return ; } else if (showOnlyAnnotatedTranscriptsInDropdown) { const isLoading = transcriptsWithProteinLength.isPending || transcriptsWithAnnotations.isPending || canonicalTranscript.isPending; const requiredData = indexedVariantAnnotations.result && Object.keys(indexedVariantAnnotations.result).length > 0 && canonicalTranscriptId && transcriptsWithAnnotations.result && transcriptsWithAnnotations.result.length > 0; return (
{this.loadingIndicator(isLoading)} {!isLoading && requiredData && this.getDropdownTranscripts( activeTranscript || canonicalTranscriptId!, transcriptsWithAnnotations.result!, canonicalTranscriptId!, transcriptsByTranscriptId, mutationsByTranscriptId )}
); } else { // using existing annotations, show all transcripts with protein length const isLoading = transcriptsWithProteinLength.isPending || canonicalTranscript.isPending; const requiredData = transcriptsWithProteinLength.result && transcriptsWithProteinLength.result.length > 0 && canonicalTranscriptId; return (
{this.loadingIndicator(isLoading)} {!isLoading && requiredData && this.getDropdownTranscripts( activeTranscript || canonicalTranscriptId!!, transcriptsWithProteinLength.result!!, canonicalTranscriptId!!, transcriptsByTranscriptId )}
); } } private getDropdownTranscripts( activeTranscript: string, allTranscripts: string[], canonicalTranscript: string, transcriptsByTranscriptId: { [transcriptId: string]: EnsemblTranscript; }, mutationsByTranscriptId?: { [transcriptId: string]: Mutation[] } ) { const activeRefseqMrnaId = transcriptsByTranscriptId[activeTranscript].refseqMrnaId; return (