Use a key-value store model for sharing long queries (#1951)

* Add KeyValue model for storing id-value pairs
use it for storing shared queries

* Change string to text and added test

* Put getQueryLink in one place

* Changed migration down version

* Changes based on comments

* Update bcf3126872fc_add_keyvalue.py
This commit is contained in:
vera-liu
2017-01-27 10:20:24 -08:00
committed by GitHub
parent 1ac2273984
commit 85806624db
9 changed files with 183 additions and 45 deletions

View File

@@ -10,7 +10,7 @@ import ModalTrigger from '../../components/ModalTrigger';
import HighlightedSql from './HighlightedSql';
import { STATE_BSSTYLE_MAP } from '../constants';
import { fDuration } from '../../modules/dates';
import { getLink } from '../../../utils/common';
import { storeQuery } from '../../../utils/common';
const propTypes = {
columns: React.PropTypes.array,
@@ -38,10 +38,17 @@ class QueryTable extends React.PureComponent {
activeQuery: null,
};
}
getQueryLink(dbId, sql) {
const params = ['dbid=' + dbId, 'sql=' + sql, 'title=Untitled Query'];
const link = getLink(this.state.cleanUri, params);
return encodeURI(link);
callback(url) {
window.open(url);
}
openQuery(dbId, schema, sql) {
const newQuery = {
dbId,
title: 'Untitled Query',
schema,
sql,
};
storeQuery(newQuery, this.callback);
}
hideVisualizeModal() {
this.setState({ showVisualizeModal: false });
@@ -98,12 +105,12 @@ class QueryTable extends React.PureComponent {
q.started = moment(q.startDttm).format('HH:mm:ss');
q.querylink = (
<div style={{ width: '100px' }}>
<a
href={this.getQueryLink(q.dbId, q.sql)}
className="btn btn-primary btn-xs"
<button
className="btn btn-link btn-xs"
onClick={this.openQuery.bind(this, q.dbId, q.schema, q.sql)}
>
<i className="fa fa-external-link" />Open in SQL Editor
</a>
</button>
</div>
);
q.sql = (