import * as React from 'react';
import styles from 'shared/components/GeneSelectionBox/styles.module.scss';
import FontAwesome from 'react-fontawesome';
import { GeneValidationResult } from 'shared/components/GeneSelectionBox/GeneSymbolValidator';
import { OQL } from 'shared/components/GeneSelectionBox/OQLTextArea';
import { GeneReplacement } from 'shared/components/query/QueryStore';
import ReactSelect from 'react-select1';
import classNames from 'classnames';
import _ from 'lodash';
import { DropdownButton, MenuItem } from 'react-bootstrap';
export type GeneSymbolValidatorMessageProps = {
errorMessageOnly?: boolean;
oql: OQL | Error;
validatingGenes: boolean;
genes: GeneValidationResult | Error;
wrapTheContent?: boolean;
replaceGene: ReplaceGene;
highlightError?: () => void;
};
export type ReplaceGene = (oldSymbol: string, newSymbol: string) => void;
type RenderSuggestionProps = GeneReplacement & {
replaceGene: ReplaceGene;
};
const RenderSuggestion = function(props: RenderSuggestionProps) {
if (props.genes.length == 0) {
let title =
'Could not find gene symbol. Click to remove it from the gene list.';
let onClick = () => props.replaceGene(props.alias, '');
return (
{props.alias}
);
}
if (props.genes.length == 1) {
let { hugoGeneSymbol } = props.genes[0];
let title = `'${props.alias}' is a synonym for '${hugoGeneSymbol}'. Click here to replace it with the official symbol.`;
let onClick = () => props.replaceGene(props.alias, hugoGeneSymbol);
return (
{props.alias}
{`: ${hugoGeneSymbol}`}
);
}
let title =
'Ambiguous gene symbol. Click on one of the alternatives to replace it.';
let options = props.genes.map(gene => ({
label: gene.hugoGeneSymbol,
value: gene.hugoGeneSymbol,
}));
return (
{props.alias}
{':'}
{options.map((item, i) => {
return (
);
})}
);
};
const GeneSymbolValidatorMessageChild = (
props: GeneSymbolValidatorMessageProps
) => {
if (props.oql instanceof Error) {
return (
);
}
if (props.oql.query.length === 0) {
return null;
}
if (!props.errorMessageOnly && props.validatingGenes) {
return (
Validating gene symbols...
);
}
if (props.genes instanceof Error) {
return (
Unable to validate gene symbols.
);
}
if (props.genes.suggestions.length > 0) {
return (
Invalid gene symbols.
{props.genes.suggestions.map((suggestion, index) => (
))}
);
}
// TDOD: remove this condition once multiple entrez gene ids is supported
const hugoGeneSymbolSet = _.groupBy(
props.genes.found,
gene => gene.hugoGeneSymbol
);
const genesWithMultipleEntrezGeneIds = _.reduce(
hugoGeneSymbolSet,
(acc, genes, hugoGeneSymbol) => {
if (genes.length > 1) {
acc.push(hugoGeneSymbol);
}
return acc;
},
[] as string[]
);
if (genesWithMultipleEntrezGeneIds.length > 0) {
return (
The portal does not currently support the following
gene(s):
{genesWithMultipleEntrezGeneIds.map((gene, index) => (
))}
);
}
if (props.errorMessageOnly) {
return null;
}
return (
All gene symbols are valid.
);
};
export default class GeneSymbolValidatorMessage extends React.Component<
GeneSymbolValidatorMessageProps,
{}
> {
render() {
if (this.props.children) {
return (
{this.props.children}
);
}
return (
);
}
}