Sha256: da876ea05f2f3f4a77c344320a21db197b6b22081db6937c6ffe3ecb205ed5cb

Contents?: true

Size: 1.73 KB

Versions: 1

Compression:

Stored size: 1.73 KB

Contents

var React = require('react'),
    Link = require('react-router').Link;

import {includes} from 'lodash';

/**
 Renders a link to the resource with id given by this.props.data.

 Includes a slick little icon for the following kinds:
 TODO which kinds?
 **/
export default React.createClass({
    displayName: 'ResourceLink',

    knownTypes: ['user', 'group', 'layer', 'host', 'variable', 'policy'],

    render() {
        var resourceId = this.props.id;

        // guard against misuse such as https://github.com/conjurinc/conjur-asset-ui/issues/78
        if (typeof resourceId === 'undefined') {
            return (
              <em>undefined</em>
            );
        }

        var tokens = resourceId.split(':'),
            kind = tokens[1],
            id = tokens[tokens.length - 1],
            text = this.props.text || id;

        var resourceIsKnown = includes(this.knownTypes, kind),
            classes = ['resource-link'];

        if (!this.props.noIcon) {
            if (resourceIsKnown) {
                classes.push(kind);
            } else {
                classes.push('abstract');

                if (text === id) {
                    text = [kind, text].join(':'); // prepend kind to id
                }
            }
        } else if (text === id) {
            text = [kind, text].join(':'); // prepend kind to id
        }

        if (resourceIsKnown) {
            return (
              <Link to={kind} params={{id: window.encodeURIComponent(id)}}
                    className={classes.join(' ')}>
                {text}
              </Link>
            );
        } else {
            return (
              <a href="#" className={classes.join(' ')}>
                {text}
              </a>
            );
        }
    }
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conjur-asset-ui-1.6.0 app/src/components/generic/resource_link.js