<commit_before>import React from "react";
import Translate from "react-translate-component";
import cnames from "classnames";
import {isArray, isString} from "lodash-es";
import Icon from "../Icon/Icon";
import MenuItemType from "./MenuItemType";

class DropdownMenuItem extends React.Component {
    render() {
        const {
            target,
            currentPath,
            includePattern,
            excludePattern,
            additionalClassName,
            icon,
            text,
            behavior,
            submenu, // {target, text, disabled}
            hidden,
            disabled
        } = this.props;

        // Defalut icon title if not set
        if (!icon.title) {
            icon.title = "icons." + icon.name;
        }

        // Default icon size if not set
        if (!icon.size) {
            icon.size = "2x";
        }

        // Convert sigle strings to array
        let includePatternArray = includePattern;
        if (isString(includePattern)) {
            includePatternArray = [includePattern];
        }

        let excludePatternArray = excludePattern;
        if (isString(excludePattern)) {
            excludePatternArray = [excludePattern];
        }

        // Check patterns which decides should the class names be assigned or not
        let patternMatched = false;
        if (includePattern || excludePattern) {
            patternMatched = true;

            if (includePatternArray) {
                for (let i = 0; i < includePatternArray.length; i++) {
                    if (currentPath.indexOf(includePatternArray[i]) === -1) {
                        patternMatched = false;
                        break;
                    }
                }
            }

            if (excludePatternArray) {
                for (let i = 0; i < excludePatternArray.length; i++) {
                    if (currentPath.indexOf(excludePatternArray[i]) !== -1) {
                        patternMatched = false;
                        break;
                    }
                }
            }
        }

        // Choose a behavior, defaults to Always
        let actualBehavior = MenuItemType.Always;
        if (behavior) {
            actualBehavior = behavior;
        }

        // Show or hide element by it's behavior
        let actuallyHidden = true;
        if (
            actualBehavior == MenuItemType.Always ||
            (actualBehavior == MenuItemType.Dynamic && patternMatched)
        ) {
            actuallyHidden = false;
        }

        //But also count a direct hidding
        if (hidden) {
            actuallyHidden = true;
        }

        // Click handler for disabled elements
        const emptyClickHandler = event => {
            event.stopPropagation();
        };

        // If submenu is a single object, render it as pure link
        let renderAlternativeSubmenu = submenu && !isArray(submenu);

        return actuallyHidden ? null : (
            <li
                className={cnames(
                    {
                        active: patternMatched,
                        disabled: disabled
                    },
                    additionalClassName
                )}
                onClick={disabled ? emptyClickHandler : target}
            >
                <div className="table-cell">
                    <Icon
                        size={icon.size}
                        name={icon.name}
                        title={icon.title}
                    />
                </div>
                <div className="table-cell">
                    <Translate content={text} />

                    {renderAlternativeSubmenu ? " " : null}
                    {renderAlternativeSubmenu ? (
                        <span
                            onClick={
                                submenu.disabled
                                    ? emptyClickHandler
                                    : submenu.target
                            }
                            className={cnames("header-dropdown-sub-link", {
                                enabled: !submenu.disabled
                            })}
                        >
                            <Translate content={submenu.text} />
                        </span>
                    ) : null}
                </div>
            </li>
        );
    }
}

export default DropdownMenuItem;<commit_msg>Fixed small bug when modal shows on navigation for alternative menu items.<commit_after>import React from "react";
import Translate from "react-translate-component";
import cnames from "classnames";
import {isArray, isString} from "lodash-es";
import Icon from "../Icon/Icon";
import MenuItemType from "./MenuItemType";

class DropdownMenuItem extends React.Component {
    render() {
        const {
            target,
            currentPath,
            includePattern,
            excludePattern,
            additionalClassName,
            icon,
            text,
            behavior,
            submenu, // {target, text, disabled}
            hidden,
            disabled
        } = this.props;

        // Defalut icon title if not set
        if (!icon.title) {
            icon.title = "icons." + icon.name;
        }

        // Default icon size if not set
        if (!icon.size) {
            icon.size = "2x";
        }

        // Convert sigle strings to array
        let includePatternArray = includePattern;
        if (isString(includePattern)) {
            includePatternArray = [includePattern];
        }

        let excludePatternArray = excludePattern;
        if (isString(excludePattern)) {
            excludePatternArray = [excludePattern];
        }

        // Check patterns which decides should the class names be assigned or not
        let patternMatched = false;
        if (includePattern || excludePattern) {
            patternMatched = true;

            if (includePatternArray) {
                for (let i = 0; i < includePatternArray.length; i++) {
                    if (currentPath.indexOf(includePatternArray[i]) === -1) {
                        patternMatched = false;
                        break;
                    }
                }
            }

            if (excludePatternArray) {
                for (let i = 0; i < excludePatternArray.length; i++) {
                    if (currentPath.indexOf(excludePatternArray[i]) !== -1) {
                        patternMatched = false;
                        break;
                    }
                }
            }
        }

        // Choose a behavior, defaults to Always
        let actualBehavior = MenuItemType.Always;
        if (behavior) {
            actualBehavior = behavior;
        }

        // Show or hide element by it's behavior
        let actuallyHidden = true;
        if (
            actualBehavior == MenuItemType.Always ||
            (actualBehavior == MenuItemType.Dynamic && patternMatched)
        ) {
            actuallyHidden = false;
        }

        //But also count a direct hidding
        if (hidden) {
            actuallyHidden = true;
        }

        // Click handler for disabled elements
        const emptyClickHandler = event => {
            event.stopPropagation();
        };

        // If submenu is a single object, render it as pure link
        let renderAlternativeSubmenu = submenu && !isArray(submenu);

        return actuallyHidden ? null : (
            <li
                className={cnames(
                    {
                        active: patternMatched,
                        disabled: disabled
                    },
                    additionalClassName
                )}
                onClick={disabled ? emptyClickHandler : target}
            >
                <div className="table-cell">
                    <Icon
                        size={icon.size}
                        name={icon.name}
                        title={icon.title}
                    />
                </div>
                <div className="table-cell">
                    <Translate content={text} />

                    {renderAlternativeSubmenu ? " " : null}
                    {renderAlternativeSubmenu ? (
                        <span
                            onClick={
                                submenu.disabled
                                    ? emptyClickHandler
                                    : event => {
                                          event.stopPropagation();
                                          submenu.target(event);
                                      }
                            }
                            className={cnames("header-dropdown-sub-link", {
                                enabled: !submenu.disabled
                            })}
                        >
                            <Translate content={submenu.text} />
                        </span>
                    ) : null}
                </div>
            </li>
        );
    }
}

export default DropdownMenuItem;
{'fraction_non_alphanumeric': 0.08277083102799601, 'fraction_numerical': 0.0011065619121389842, 'mean_word_length': 1.0897109826589595, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4880539', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1935, 'n_words': 502}