<commit_before>import React, {Component, PropTypes} from "react";
import { Scrollbars } from "react-custom-scrollbars";
import style from "./style.less";

class Gallery extends Component {

    getElementSize() {
        const { size } = this.props;
        return size === "big" ? 198 : 130;        
    }

    calculateGalleryWidth() {
        const { children } = this.props;
        return this.getElementSize() * children.length;
    }

    scrollToSelectedItem(scrollToIndex) {
        const indexToScroll = scrollToIndex !== -1 ? scrollToIndex : 0; 
        const scrollbars = this.refs.scrollbars;
        const scrollClientWidth = scrollbars.getClientWidth();
        const scrollLeft = indexToScroll * this.getElementSize();
        const currentScrollLeft = scrollbars.getScrollLeft();
        const lowBoundary = currentScrollLeft;
        const highBoundary = currentScrollLeft + scrollClientWidth;        
        if (scrollLeft > lowBoundary && scrollLeft < highBoundary) {
            return;
        }
        this.refs.scrollbars.scrollLeft(scrollLeft);
    }

    componentWillReceiveProps(newProps) {
        setTimeout(() => this.scrollToSelectedItem(newProps.scrollToIndex), 0);
    }
    
    componentDidMount() {
        setTimeout(() => this.scrollToSelectedItem(this.props.scrollToIndex), 0);
    }

    render() {  
        const width = this.calculateGalleryWidth();    
        return (
            <div className={style.moduleContainer}>
                <Scrollbars ref="scrollbars"
                    className="container"
                    autoHeight<commit_msg>DNN-10354: added null check<commit_after>import React, {Component, PropTypes} from "react";
import { Scrollbars } from "react-custom-scrollbars";
import style from "./style.less";

class Gallery extends Component {

    getElementSize() {
        const { size } = this.props;
        return size === "big" ? 198 : 130;        
    }

    calculateGalleryWidth() {
        const { children } = this.props;
        return this.getElementSize() * children.length;
    }

    scrollToSelectedItem(scrollToIndex) {
        const indexToScroll = scrollToIndex !== -1 ? scrollToIndex : 0; 
        const scrollbars = this.refs.scrollbars;
        if (scrollbars) {
            const scrollClientWidth = scrollbars.getClientWidth();
            const scrollLeft = indexToScroll * this.getElementSize();
            const currentScrollLeft = scrollbars.getScrollLeft();
            const lowBoundary = currentScrollLeft;
            const highBoundary = currentScrollLeft + scrollClientWidth;        
            if (scrollLeft > lowBoundary && scrollLeft < highBoundary) {
                return;
            }
            this.refs.scrollbars.scrollLeft(scrollLeft);
        }
    }

    componentWillReceiveProps(newProps) {
        setTimeout(() => this.scrollToSelectedItem(newProps.scrollToIndex), 0);
    }
    
    componentDidMount() {
        setTimeout(() => this.scrollToSelectedItem(this.props.scrollToIndex), 0);
    }

    render() {  
        const width = this.calculateGalleryWidth();    
        return (
            <div className={style.moduleContainer}>
                <Scrollbars ref="scrollbars"
                    className="container"
                    autoHeight
{'fraction_non_alphanumeric': 0.10115783059110299, 'fraction_numerical': 0.007617306520414382, 'mean_word_length': 2.36028659160696, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4632581', 'n_tokens_mistral': 876, 'n_tokens_neox': 833, 'n_words': 178}