Sha256: bd1480b6a80142548eaba25ec19151d97f4135d45d773d8432447c71abd00d55

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

var React = require('react');

import {take} from 'lodash';

var RoleLink = require('../generic/role_link'),
    Refresh = require('../refresh/refresh');

export default React.createClass({
    displayName: 'VariableFetchers',

    propTypes: {
        data: React.PropTypes.array,
        isLoading: React.PropTypes.bool
    },

    getDefaultProps() {
        return {
            data: [],
            isLoading: false
        };
    },

    getInitialState() {
        return {showAll: false};
    },

    handleClick(e) {
        e.preventDefault();

        this.setState({showAll: !this.state.showAll});
    },

    getItems() {
        return this.props.data.map((e) => {
            return (
              <li className="list-group-item list-group-item-noborder">
                <RoleLink id={e} />
              </li>
            );
        });
    },

    render() {
        var items = this.getItems(),
            itemsToDisplay = this.state.showAll ? items : take(items, 5),
            msg = this.state.showAll ? 'Show top 5' : 'See all',
            empty = items.length === 0,
            lessThan5 = items.length <= 5,
            body = [(<h2>Fetchers<Refresh show={this.props.isLoading} /></h2>)];

        if (!empty) {
            body.push(
              <ul className="b-variable-fetchers__list list-unstyled list-group">
                {itemsToDisplay}
              </ul>
            );
        } else {
            body.push(
              <p>There are no fetchers</p>
            );
        }

        if (!lessThan5) {
            body.push(
              <div className="b-variable-fetchers__toggle">
                <a href="#" onClick={this.handleClick}>{msg}</a>
              </div>
            );
        }

        return (
          <div className="b-variable-fetchers">
            {body}
          </div>
        );
    }
});

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
conjur-asset-ui-1.6.0 app/src/components/variable/fetchers.js