<commit_before>'use strict';

import React, { PropTypes } from 'react';
import { Form, FormMixin, Input } from '../../libs/bootstrap/form';
import { AUTOSOMAL_DOMINANT, AUTOSOMAL_RECESSIVE, X_LINKED } from './constants/evidence_types';
import CASE_INFO_TYPES from './constants/case_info_types';
import { defaultScore } from './helpers/default_score';
import { scoreRange } from './helpers/score_range';
import { userScore } from './helpers/user_score';

// Render scoring panel in Gene Curation Interface
var ScoreMain = module.exports.ScoreMain = React.createClass({
    mixins: [FormMixin],

    propTypes: {
        session: React.PropTypes.object, // Session object passed from parent
        evidence: React.PropTypes.object, // Individual, Experimental or Case Control
        modeInheritance: React.PropTypes.string, // Mode of Inheritance
        evidenceType: React.PropTypes.string, // 'Individual', 'Experimental' or 'Case Control'
        variantInfo: React.PropTypes.object, // Variant count for Individual evidence
        handleUserScoreObj: React.PropTypes.func, // Function to call create/update score object
        scoreSubmit: React.PropTypes.func, // Function to call when Save button is clicked; This prop's existence makes the Save button exist
        submitBusy: React.PropTypes.bool // TRUE while the form submit is running
    },

    getInitialState() {
        return {
            evidenceScores: [], // One or more scores
            userScoreUuid: null, // Pre-existing logged-in user's score uuuid
            modeInheritanceType: null, // Mode of Inheritance types
            caseInfoTypeGroup: [], // Array of Case Information types given the Mode of Inheritance type
            scoreStatus: null, // Score status that allow scoring (e.g. 'Score', 'Review')
            caseInfoType: null, // Case information type (e.g. 'Variant is De Novo')
            defaultScore: null, // Calculated default score given the 'Score Status' or 'Case Information type'
            modifiedScore: null, // Score that is selected by curator and it is different from the calculated default score
            scoreRange: [], // Calculated score range
            scoreExplanation: null, // Explanation for selecting a different score from the calculated default score
            variantInfo: this.props.variantInfo, // Variant count for Individual evidence
            showScoreInput: false, // TRUE if either 'Score' or 'Review' is selected
            updateDefaultScore: false, // TRUE if either 'Score Status' or 'Case Information type' are changed
            requiredScoreExplanation: false, // TRUE if a different score is selected from the range
            submitBusy: false, // TRUE while form is submitting
            disableScoreStatus: false // TRUE if Individual evidence has no variants at all
        };
    },

    componentDidMount() {
        this.loadData();
    },

    componentWillReceiveProps: function(nextProps) {
        if (nextProps.variantInfo !== this.props.variantInfo && !this.props.evidence) {
            this.setState({variantInfo: nextProps.variantInfo}, () => {
                if (this.state.variantInfo && Object.keys(this.state.variantInfo).length > 0) {
                    this.setState({disableScoreStatus: false});
                } else {
                    this.setState({disableScoreStatus: true});
                }
            });
        }
    },

    loadData() {
        // Prep the following when the component is loaded
        let modeInheritanceType = this.getModeInheritanceType(this.props.modeInheritance);
        this.setState({modeInheritanceType: modeInheritanceType}, () => {
            let caseInfoTypeGroup = this.getCaseInfoTypeGroup(modeInheritanceType);
            this.setState({caseInfoTypeGroup: caseInfoTypeGroup});
        });

        let evidenceObj = this.props.evidence;

        // If the individual evidence has no variants at all, disable the Score Status form field
        if (evidenceObj && this.props.evidenceType === 'Individual') {
            if (!evidenceObj.variants || (evidenceObj.variants && evidenceObj.variants.length < 1)) {
                this.setState({disableScoreStatus: true});
            }
        } else if (!evidenceObj && this.props.evidenceType === 'Individual') {
            if (this.state.variantInfo && Object.keys(this.state.variantInfo).length > 0) {
                this.setState({disableScoreStatus: false});
            } else {
                this.setState({disableScoreStatus: true});
            }
        }

        // Get evidenceScore object for the logged-in user if exists
        if (evidenceObj && evidenceObj.scores && evidenceObj.scores.length) {
            this.setState({evidenceScores: evidenceObj.scores}, () => {
                let loggedInUserScore = this.getUserScore(evidenceObj.scores);
                if (loggedInUserScore) {
                    this.setState({userScoreUuid: loggedInUserScore.uuid});
                    // Render or remove the default score, score range, and explanation fields
                    let scoreStatus = loggedInUserScore.scoreStatus;
                    /**************************************************************************************/
                    /* Curators are allowed to access the score form fields when the 'Score' is selected, */
                    /* or when 'Review' is selected given the matched Mode of Inheritance types           */<commit_msg>Removed checks for Individual evidence because this component is now Individual specific<commit_after>'use strict';

import React, { PropTypes } from 'react';
import { Form, FormMixin, Input } from '../../libs/bootstrap/form';
import { AUTOSOMAL_DOMINANT, AUTOSOMAL_RECESSIVE, X_LINKED } from './constants/evidence_types';
import CASE_INFO_TYPES from './constants/case_info_types';
import { defaultScore } from './helpers/default_score';
import { scoreRange } from './helpers/score_range';
import { userScore } from './helpers/user_score';

// Render scoring panel in Gene Curation Interface
var ScoreMain = module.exports.ScoreMain = React.createClass({
    mixins: [FormMixin],

    propTypes: {
        session: React.PropTypes.object, // Session object passed from parent
        evidence: React.PropTypes.object, // Individual, Experimental or Case Control
        modeInheritance: React.PropTypes.string, // Mode of Inheritance
        evidenceType: React.PropTypes.string, // 'Individual', 'Experimental' or 'Case Control'
        variantInfo: React.PropTypes.object, // Variant count for Individual evidence
        handleUserScoreObj: React.PropTypes.func, // Function to call create/update score object
        scoreSubmit: React.PropTypes.func, // Function to call when Save button is clicked; This prop's existence makes the Save button exist
        submitBusy: React.PropTypes.bool // TRUE while the form submit is running
    },

    getInitialState() {
        return {
            evidenceScores: [], // One or more scores
            userScoreUuid: null, // Pre-existing logged-in user's score uuuid
            modeInheritanceType: null, // Mode of Inheritance types
            caseInfoTypeGroup: [], // Array of Case Information types given the Mode of Inheritance type
            scoreStatus: null, // Score status that allow scoring (e.g. 'Score', 'Review')
            caseInfoType: null, // Case information type (e.g. 'Variant is De Novo')
            defaultScore: null, // Calculated default score given the 'Score Status' or 'Case Information type'
            modifiedScore: null, // Score that is selected by curator and it is different from the calculated default score
            scoreRange: [], // Calculated score range
            scoreExplanation: null, // Explanation for selecting a different score from the calculated default score
            variantInfo: this.props.variantInfo, // Variant count for Individual evidence
            showScoreInput: false, // TRUE if either 'Score' or 'Review' is selected
            updateDefaultScore: false, // TRUE if either 'Score Status' or 'Case Information type' are changed
            requiredScoreExplanation: false, // TRUE if a different score is selected from the range
            submitBusy: false, // TRUE while form is submitting
            disableScoreStatus: false // TRUE if Individual evidence has no variants at all
        };
    },

    componentDidMount() {
        this.loadData();
    },

    componentWillReceiveProps: function(nextProps) {
        if (nextProps.variantInfo !== this.props.variantInfo && !this.props.evidence) {
            this.setState({variantInfo: nextProps.variantInfo}, () => {
                if (this.state.variantInfo && Object.keys(this.state.variantInfo).length > 0) {
                    this.setState({disableScoreStatus: false});
                } else {
                    this.setState({disableScoreStatus: true});
                }
            });
        }
    },

    loadData() {
        // Prep the following when the component is loaded
        let modeInheritanceType = this.getModeInheritanceType(this.props.modeInheritance);
        this.setState({modeInheritanceType: modeInheritanceType}, () => {
            let caseInfoTypeGroup = this.getCaseInfoTypeGroup(modeInheritanceType);
            this.setState({caseInfoTypeGroup: caseInfoTypeGroup});
        });

        let evidenceObj = this.props.evidence;

        // If the individual evidence has no variants at all, disable the Score Status form field
        if (evidenceObj) {
            if (!evidenceObj.variants || (evidenceObj.variants && evidenceObj.variants.length < 1)) {
                this.setState({disableScoreStatus: true});
            }
        } else {
            if (this.state.variantInfo && Object.keys(this.state.variantInfo).length > 0) {
                this.setState({disableScoreStatus: false});
            } else {
                this.setState({disableScoreStatus: true});
            }
        }

        // Get evidenceScore object for the logged-in user if exists
        if (evidenceObj && evidenceObj.scores && evidenceObj.scores.length) {
            this.setState({evidenceScores: evidenceObj.scores}, () => {
                let loggedInUserScore = this.getUserScore(evidenceObj.scores);
                if (loggedInUserScore) {
                    this.setState({userScoreUuid: loggedInUserScore.uuid});
                    // Render or remove the default score, score range, and explanation fields
                    let scoreStatus = loggedInUserScore.scoreStatus;
                    /**************************************************************************************/
                    /* Curators are allowed to access the score form fields when the 'Score' is selected, */
                    /* or when 'Review' is selected given the matched Mode of Inheritance types           */
{'fraction_non_alphanumeric': 0.10860599395105856, 'fraction_numerical': 0.0005499037668408029, 'mean_word_length': 2.526826115061409, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3511808', 'n_tokens_mistral': 2723, 'n_tokens_neox': 2605, 'n_words': 843}