From f1e80a8e1b94cc7a58e0760c5b87b7e4ed594294 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Wed, 21 Sep 2016 14:40:33 -0700 Subject: [PATCH] Adding indexes to table metadata (#1160) --- .../SqlLab/components/SqlEditorLeft.jsx | 5 ++++ .../SqlLab/components/TableElement.jsx | 23 +++++++++++++++++++ caravel/models.py | 3 +++ caravel/views.py | 3 +++ 4 files changed, 34 insertions(+) diff --git a/caravel/assets/javascripts/SqlLab/components/SqlEditorLeft.jsx b/caravel/assets/javascripts/SqlLab/components/SqlEditorLeft.jsx index 7886a2c78dfb3..25ea4fd723a02 100644 --- a/caravel/assets/javascripts/SqlLab/components/SqlEditorLeft.jsx +++ b/caravel/assets/javascripts/SqlLab/components/SqlEditorLeft.jsx @@ -102,22 +102,27 @@ class SqlEditorTopToolbar extends React.Component { const tableName = tableOpt.value; const qe = this.props.queryEditor; const url = `/caravel/table/${qe.dbId}/${tableName}/${qe.schema}/`; + + this.setState({ tableLoading: true }); $.get(url, (data) => { this.props.actions.addTable({ id: shortid.generate(), dbId: this.props.queryEditor.dbId, queryEditorId: this.props.queryEditor.id, name: data.name, + indexes: data.indexes, schema: qe.schema, columns: data.columns, expanded: true, }); + this.setState({ tableLoading: false }); }) .fail(() => { this.props.actions.addAlert({ msg: 'Error occurred while fetching metadata', bsStyle: 'danger', }); + this.setState({ tableLoading: false }); }); } render() { diff --git a/caravel/assets/javascripts/SqlLab/components/TableElement.jsx b/caravel/assets/javascripts/SqlLab/components/TableElement.jsx index e0da90dfd9609..a2f108f7ee9dc 100644 --- a/caravel/assets/javascripts/SqlLab/components/TableElement.jsx +++ b/caravel/assets/javascripts/SqlLab/components/TableElement.jsx @@ -5,6 +5,7 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import * as Actions from '../actions'; import shortid from 'shortid'; +import ModalTrigger from '../../components/ModalTrigger.jsx'; class TableElement extends React.Component { setSelectStar() { @@ -86,6 +87,27 @@ class TableElement extends React.Component { ); } + let keyLink; + if (this.props.table.indexes && this.props.table.indexes.length > 0) { + keyLink = ( + + Keys for table {this.props.table.name} + + } + modalBody={ +
{JSON.stringify(this.props.table.indexes, null, 4)}
+ } + triggerNode={ + + } + /> + ); + } return (
@@ -94,6 +116,7 @@ class TableElement extends React.Component {
+ {keyLink}