import React from 'react' import Sortable from 'react-sortablejs'; import Icon from '../Icon'; import Link from '../Link'; import * as helpers from '../../helpers'; export default class Commands extends React.Component{ constructor(props){ super(props); } onChange(order){ let commands = {}; for (let i = 0; i <= order.length; i++){ let command = this.props.commands[order[i]]; if (command){ commands[command.id] = {...command, ...{sort_order: i}}; } } this.props.onChange(commands); } commands(){ let commands = []; if (this.props.commands){ for (let key of Object.keys(this.props.commands)){ commands.push({...this.props.commands[key]}); } } commands = helpers.sortItems(commands, 'sort_order'); return commands; } render(){ const commands = this.commands(); if (!commands){ return null; } return ( {this.onChange(order)}}> { commands.map(command => { return (
this.props.runCommand(command.id, true)}>
{command.name ? command.name : {command.url}}
); }) }
); } }