<commit_before>import * as React from 'react';
import * as classNames from 'classnames';
import { ILeftNavigationProps, ILeftNavigationOption, ExpandCaptionsBehaviorEnum, LeftNavigationOptionPositionEnum } from './LeftNavigation.Props';
import { assign } from '../../utilities/object';
import { findIndex } from '../../utilities/array';
import { Icon } from '../../components/Icon/Icon';
import { CommonComponent } from '../Common/Common';
import { elementContains } from '../../utilities/elementContains';
import { getWindow } from '../../utilities/getDocument';
import { autobind } from '../../utilities/autobind';
import './LeftNavigation.scss';

const nullFunc = () => { };

export class LeftNavigation extends CommonComponent<ILeftNavigationProps, any> {
    private _targetWindow: Window;
    private _leftNavElement: HTMLDivElement;
    private _target: HTMLElement | MouseEvent;

    public static defaultProps: Partial<ILeftNavigationProps> = {
        expandCaptionsBehavior: ExpandCaptionsBehaviorEnum.ShowCaptionsOnHover,
        onClick: nullFunc
    };

    constructor(props: ILeftNavigationProps) {
        super(props);

        this.state = {
            isOpen: false,
            selectedId: this.getSelectedId(this.props.options)
        };
    }

    public componentDidMount() {
        let target = this._leftNavElement;
        this.setTargetWindowAndElement(target);
        this._events.on(this._targetWindow, 'click', this.dismissOnClickOutsideComponent, true);
    }

    public componentWillUnmount() {
        this._events.dispose();
    }

    private setTargetWindowAndElement(target: HTMLElement): void {
        if (target) {
            let targetElement: HTMLElement = target as HTMLElement;
            this._target = target;
            this._targetWindow = getWindow(targetElement);
        } else {
            this._targetWindow = getWindow();
        }
    }

    public componentWillReceiveProps(newProps: ILeftNavigationProps) {
        this.setState({ selectedId: this.getSelectedId(newProps.options) });
    }

    protected dismissOnClickOutsideComponent(ev: Event) {
        let target = ev.target as HTMLElement;
        if (ev.target !== this._targetWindow && (!this._target || !elementContains(this._target as HTMLElement, target, false))) {
            this.setState({ isOpen: false });
        }
    }

    private onLinkClick(id, item: any, ev: React.MouseEvent<HTMLElement>) {
        if (this.state.isOpen) {
            this.setState({ isOpen: false });
        }

        if (id !== this.state.selectedId) {
            this.setState({
                selectedId: id
            });
        }

        this.props.onClick(ev, item);
    }

    private getSelectedId(options: Array<ILeftNavigationOption>) {
        const selectedOptions = options.filter(option => { return option.selected ? option.id : null; });
        
        if (selectedOptions.length > 0) {
            return selectedOptions[0].id;
        }
    }

    @autobind
    private setNavigationReference(ref: HTMLDivElement) {
        this._leftNavElement = ref;
    }

    @autobind
    private onNavigationMouseOut() {
        if (this.props.expandCaptionsBehavior === ExpandCaptionsBehaviorEnum.ShowCaptionsOnHover && this.state.isOpen) {
            this.setState({ isOpen: false });
        }
    }

    @autobind
    private onNavigationMouseOver() {
        if (this.props.expandCaptionsBehavior === ExpandCaptionsBehaviorEnum.ShowCaptionsOnHover && !this.state.isOpen) {
            this.setState({ isOpen: true });<commit_msg> return some value from getSelectedId, declare type<commit_after>import * as React from 'react';
import * as classNames from 'classnames';
import { ILeftNavigationProps, ILeftNavigationOption, ExpandCaptionsBehaviorEnum, LeftNavigationOptionPositionEnum } from './LeftNavigation.Props';
import { assign } from '../../utilities/object';
import { findIndex } from '../../utilities/array';
import { Icon } from '../../components/Icon/Icon';
import { CommonComponent } from '../Common/Common';
import { elementContains } from '../../utilities/elementContains';
import { getWindow } from '../../utilities/getDocument';
import { autobind } from '../../utilities/autobind';
import './LeftNavigation.scss';

const nullFunc = () => { };

export class LeftNavigation extends CommonComponent<ILeftNavigationProps, any> {
    private _targetWindow: Window;
    private _leftNavElement: HTMLDivElement;
    private _target: HTMLElement | MouseEvent;

    public static defaultProps: Partial<ILeftNavigationProps> = {
        expandCaptionsBehavior: ExpandCaptionsBehaviorEnum.ShowCaptionsOnHover,
        onClick: nullFunc
    };

    constructor(props: ILeftNavigationProps) {
        super(props);

        this.state = {
            isOpen: false,
            selectedId: this.getSelectedId(this.props.options)
        };
    }

    public componentDidMount() {
        let target = this._leftNavElement;
        this.setTargetWindowAndElement(target);
        this._events.on(this._targetWindow, 'click', this.dismissOnClickOutsideComponent, true);
    }

    public componentWillUnmount() {
        this._events.dispose();
    }

    private setTargetWindowAndElement(target: HTMLElement): void {
        if (target) {
            let targetElement: HTMLElement = target as HTMLElement;
            this._target = target;
            this._targetWindow = getWindow(targetElement);
        } else {
            this._targetWindow = getWindow();
        }
    }

    public componentWillReceiveProps(newProps: ILeftNavigationProps) {
        this.setState({ selectedId: this.getSelectedId(newProps.options) });
    }

    protected dismissOnClickOutsideComponent(ev: Event) {
        let target = ev.target as HTMLElement;
        if (ev.target !== this._targetWindow && (!this._target || !elementContains(this._target as HTMLElement, target, false))) {
            this.setState({ isOpen: false });
        }
    }

    private onLinkClick(id, item: any, ev: React.MouseEvent<HTMLElement>) {
        if (this.state.isOpen) {
            this.setState({ isOpen: false });
        }

        if (id !== this.state.selectedId) {
            this.setState({
                selectedId: id
            });
        }

        this.props.onClick(ev, item);
    }

    private getSelectedId(options: Array<ILeftNavigationOption>) : string {
        const selectedOptions = options.filter(option => { return option.selected ? option.id : null; });

        if (selectedOptions.length > 0) {
            return selectedOptions[0].id;
        }

        return '';
    }

    @autobind
    private setNavigationReference(ref: HTMLDivElement) {
        this._leftNavElement = ref;
    }

    @autobind
    private onNavigationMouseOut() {
        if (this.props.expandCaptionsBehavior === ExpandCaptionsBehaviorEnum.ShowCaptionsOnHover && this.state.isOpen) {
            this.setState({ isOpen: false });
        }
    }

    @autobind
    private onNavigationMouseOver() {
        if (this.props.expandCaptionsBehavior === ExpandCaptionsBehaviorEnum.ShowCaptionsOnHover && !this.state.isOpen) {
            this.setState({ isOpen: true });
{'fraction_non_alphanumeric': 0.11544353154156803, 'fraction_numerical': 0.0005570254839158892, 'mean_word_length': 2.810079575596817, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '7652695', 'n_tokens_mistral': 1942, 'n_tokens_neox': 1937, 'n_words': 407}