import React from 'react'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import * as Actions from '../actions'; import moment from 'moment'; import { Table } from 'reactable'; import SyntaxHighlighter from 'react-syntax-highlighter'; import { github } from 'react-syntax-highlighter/dist/styles'; import Link from './Link'; import VisualizeModal from './VisualizeModal'; // TODO move to CSS const STATE_COLOR_MAP = { failed: 'red', running: 'lime', success: 'green', }; class QueryTable extends React.Component { constructor(props) { super(props); this.state = { showVisualizeModal: false, activeQuery: null, }; } hideVisualizeModal() { this.setState({ showVisualizeModal: false }); } showVisualizeModal(query) { this.setState({ showVisualizeModal: true }); this.setState({ activeQuery: query }); } render() { const data = this.props.queries.map((query) => { const q = Object.assign({}, query); const since = (q.endDttm) ? q.endDttm : new Date(); let duration = since.valueOf() - q.startDttm.valueOf(); duration = moment.utc(duration); if (q.endDttm) { q.duration = duration.format('HH:mm:ss.SS'); } q.started = moment(q.startDttm).format('HH:mm:ss'); q.sql = {q.sql}; q.state = ( {q.state} ); q.actions = (
); return q; }).reverse(); return (
); } } QueryTable.propTypes = { columns: React.PropTypes.array, actions: React.PropTypes.object, queries: React.PropTypes.object, }; QueryTable.defaultProps = { columns: ['state', 'started', 'duration', 'rows', 'sql', 'actions'], queries: [], }; function mapStateToProps() { return {}; } function mapDispatchToProps(dispatch) { return { actions: bindActionCreators(Actions, dispatch), }; } export default connect(mapStateToProps, mapDispatchToProps)(QueryTable);