<commit_before>import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import shortUUID from '../helpers/uuid';

export default class NomadLink extends Component {

    findNodeNameById(nodeId) {
        const r = Object.keys(this.props.nodeList).filter(node =>
            this.props.nodeList[node].ID === nodeId
        );

        if (r.length !== 0) {
            return this.props.nodeList[r].Name;
        }

        return nodeId;
    }

    render() {
        const short = this.props.short === 'true';
        const linkAppend = this.props.linkAppend || '';

        let children = this.props.children;
        const linkProps = Object.assign({}, this.props);
        Object.keys(linkProps).filter(key => key.endsWith('Id')).forEach((key) => {
            delete linkProps[key];
        });
        delete linkProps.short;
        delete linkProps.nodeList;
        delete linkProps.linkAppend;

        // member
        if (this.props.memberId !== undefined) {
            const memberId = this.props.memberId;
            if (children === undefined) {
                children = short ? shortUUID(memberId) : memberId;
            }
            return (
              <Link { ...linkProps } to={ `/servers/${memberId}` }>{ children }</Link>
            );
        }

        // node
        if (this.props.nodeId !== undefined) {
            const nodeId = this.props.nodeId;
            if (children === undefined) {
                if (this.props.nodeList) {
                    children = this.findNodeNameById(this.props.nodeId);
                } else {
                    children = short ? shortUUID(this.props.nodeId) : nodeId;
                }
            }
            return (
              <Link { ...linkProps } to={ `/clients/${nodeId}${linkAppend}` }>{ children }</Link>
            );
        }

        // eval
        if (this.props.evalId !== undefined) {
            const evalId = this.props.evalId;
            if (children === undefined) {
                children = short ? shortUUID(evalId) : evalId;
            }
            return (
              <Link { ...linkProps } to={ `/evaluations/${evalId}${linkAppend}` }>{ children }</Link>
            );
        }

        // alloc
        if (this.props.allocId !== undefined) {
            const allocId = this.props.allocId;
            if (children === undefined) {
                children = short ? shortUUID(allocId) : allocId;
            }

            return (
              <Link { ...linkProps } to={ `/allocations/${allocId}${linkAppend}` }>{ children }</Link>
            );
        }

        // tasks
        if (this.props.taskId !== undefined) {
            if (this.props.jobId !== undefined && this.props.taskGroupId !== undefined) {
                const jobId = encodeURIComponent(this.props.jobId);
                const taskGroupId = this.props.taskGroupId;
                const taskId = this.props.taskId;

                if (children === undefined) {
                    children = short ? shortUUID(taskId) : taskId;
                }
                return (
                  <Link { ...linkProps } to={ `/jobs/${jobId}/tasks${linkAppend}` } query={{ taskGroupId, taskId }} >
                    { children }
                  </Link>
                );
            }
            console.error('NomadLink: You must also provide taskGroupId and jobId for task links!');
        }

        // taskGroup (must be after task)
        if (this.props.taskGroupId !== undefined) {
            if (this.props.jobId !== undefined) {
                const jobId = encodeURIComponent(this.props.jobId);
                const taskGroupId = this.props.taskGroupId;

                if (children === undefined) {
                    children = short ? shortUUID(taskGroupId) : taskGroupId;
                }
                return (
                  <Link { ...linkProps } to={ `/jobs/${jobId}/taskGroups${linkAppend}` } query={{ taskGroupId }} >
                    { children }
                  </Link>
                );
            }
            console.error('NomadLink: You must also provide jobId for taskGroup links!');
        }

        // job (must be after task & taskGroup
        if (this.props.jobId !== undefined) {
            const jobId = encodeURIComponent(this.props.jobId);

            if (children === undefined) {
                children = short ? shortUUID(jobId) : jobId;
            }
            return (
              <Link { ...linkProps } to={ `/jobs/${jobId}${linkAppend}` }>{ children }</Link>
            );
        }

        // nothing by default
        return null;
    }
}

NomadLink.propTypes = {
    nodeList: PropTypes.array,
    short: PropTypes.string,
    children: PropTypes.oneOfType([
        PropTypes.array,
        PropTypes.string,
        React.PropTypes.node,
    ]),
    memberId: PropTypes.string,
    nodeId: PropTypes.string,
    evalId: PropTypes.string,
    allocId: PropTypes.string,
    taskId: PropTypes.string,
    jobId: PropTypes.string,
    linkAppend: PropTypes.string,
    taskGroupId: PropTypes.string,
};<commit_msg>don't encode the visual name<commit_after>import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router';
import shortUUID from '../helpers/uuid';

export default class NomadLink extends Component {

    findNodeNameById(nodeId) {
        const r = Object.keys(this.props.nodeList).filter(node =>
            this.props.nodeList[node].ID === nodeId
        );

        if (r.length !== 0) {
            return this.props.nodeList[r].Name;
        }

        return nodeId;
    }

    render() {
        const short = this.props.short === 'true';
        const linkAppend = this.props.linkAppend || '';

        let children = this.props.children;
        const linkProps = Object.assign({}, this.props);
        Object.keys(linkProps).filter(key => key.endsWith('Id')).forEach((key) => {
            delete linkProps[key];
        });
        delete linkProps.short;
        delete linkProps.nodeList;
        delete linkProps.linkAppend;

        // member
        if (this.props.memberId !== undefined) {
            const memberId = this.props.memberId;
            if (children === undefined) {
                children = short ? shortUUID(memberId) : memberId;
            }
            return (
              <Link { ...linkProps } to={ `/servers/${memberId}` }>{ children }</Link>
            );
        }

        // node
        if (this.props.nodeId !== undefined) {
            const nodeId = this.props.nodeId;
            if (children === undefined) {
                if (this.props.nodeList) {
                    children = this.findNodeNameById(this.props.nodeId);
                } else {
                    children = short ? shortUUID(this.props.nodeId) : nodeId;
                }
            }
            return (
              <Link { ...linkProps } to={ `/clients/${nodeId}${linkAppend}` }>{ children }</Link>
            );
        }

        // eval
        if (this.props.evalId !== undefined) {
            const evalId = this.props.evalId;
            if (children === undefined) {
                children = short ? shortUUID(evalId) : evalId;
            }
            return (
              <Link { ...linkProps } to={ `/evaluations/${evalId}${linkAppend}` }>{ children }</Link>
            );
        }

        // alloc
        if (this.props.allocId !== undefined) {
            const allocId = this.props.allocId;
            if (children === undefined) {
                children = short ? shortUUID(allocId) : allocId;
            }

            return (
              <Link { ...linkProps } to={ `/allocations/${allocId}${linkAppend}` }>{ children }</Link>
            );
        }

        // tasks
        if (this.props.taskId !== undefined) {
            if (this.props.jobId !== undefined && this.props.taskGroupId !== undefined) {
                const jobId = this.props.jobId;
                const jobIdUrl = encodeURIComponent(jobId);
                const taskGroupId = this.props.taskGroupId;
                const taskId = this.props.taskId;

                if (children === undefined) {
                    children = short ? shortUUID(taskId) : taskId;
                }
                return (
                  <Link { ...linkProps } to={ `/jobs/${jobIdUrl}/tasks${linkAppend}` } query={{ taskGroupId, taskId }} >
                    { children }
                  </Link>
                );
            }
            console.error('NomadLink: You must also provide taskGroupId and jobId for task links!');
        }

        // taskGroup (must be after task)
        if (this.props.taskGroupId !== undefined) {
            if (this.props.jobId !== undefined) {
                const jobId = this.props.jobId;
                const jobIdUrl = encodeURIComponent(jobId);
                const taskGroupId = this.props.taskGroupId;

                if (children === undefined) {
                    children = short ? shortUUID(taskGroupId) : taskGroupId;
                }
                return (
                  <Link { ...linkProps } to={ `/jobs/${jobIdUrl}/taskGroups${linkAppend}` } query={{ taskGroupId }} >
                    { children }
                  </Link>
                );
            }
            console.error('NomadLink: You must also provide jobId for taskGroup links!');
        }

        // job (must be after task & taskGroup
        if (this.props.jobId !== undefined) {
            const jobId = this.props.jobId;
            const jobIdUrl = encodeURIComponent(jobId);

            if (children === undefined) {
                children = short ? shortUUID(jobId) : jobId;
            }
            return (
              <Link { ...linkProps } to={ `/jobs/${jobIdUrl}${linkAppend}` }>{ children }</Link>
            );
        }

        // nothing by default
        return null;
    }
}

NomadLink.propTypes = {
    nodeList: PropTypes.array,
    short: PropTypes.string,
    children: PropTypes.oneOfType([
        PropTypes.array,
        PropTypes.string,
        React.PropTypes.node,
    ]),
    memberId: PropTypes.string,
    nodeId: PropTypes.string,
    evalId: PropTypes.string,
    allocId: PropTypes.string,
    taskId: PropTypes.string,
    jobId: PropTypes.string,
    linkAppend: PropTypes.string,
    taskGroupId: PropTypes.string,
};
{'fraction_non_alphanumeric': 0.1283653846153846, 'fraction_numerical': 0.0001923076923076923, 'mean_word_length': 1.5486400392060768, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 37, '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': '6622596', 'n_tokens_mistral': 2814, 'n_tokens_neox': 2796, 'n_words': 597}