Fixing explore actions & slice controller interactions (#1292)

* Fixing explore actions & slice controller interactions

* Addressing a comment
This commit is contained in:
Maxime Beauchemin
2016-10-07 14:06:26 -07:00
committed by GitHub
parent 382b8e85da
commit 3384e7598e
9 changed files with 150 additions and 120 deletions

View File

@@ -12,7 +12,6 @@ export default class EmbedCodeButton extends React.Component {
this.state = {
height: '400',
width: '600',
srcLink: window.location.origin + props.slice.data.standalone_endpoint,
};
this.handleInputChange = this.handleInputChange.bind(this);
}
@@ -26,11 +25,15 @@ export default class EmbedCodeButton extends React.Component {
}
generateEmbedHTML() {
const { width, height, srcLink } = this.state;
const srcLink = window.location.origin + this.props.slice.data.standalone_endpoint;
/* eslint max-len: 0 */
const embedHTML =
`<iframe src="${srcLink}" width="${width}" height="${height}" seamless frameBorder="0" scrolling="no"></iframe>`;
return embedHTML;
return `
<iframe
src="${srcLink}"
width="${this.state.width}"
height="${this.state.height}"
seamless frameBorder="0" scrolling="no">
</iframe>`;
}
renderPopover() {

View File

@@ -13,7 +13,6 @@ export default function ExploreActionButtons({ canDownload, slice }) {
const exportToCSVClasses = cx('btn btn-default btn-sm', {
'disabled disabledButton': !canDownload,
});
return (
<div className="btn-group results" role="group">
<URLShortLinkButton slice={slice} />

View File

@@ -13,8 +13,6 @@ export default class URLShortLinkButton extends React.Component {
this.state = {
shortUrl: '',
};
this.getShortUrl();
}
getShortUrl() {
@@ -22,7 +20,7 @@ export default class URLShortLinkButton extends React.Component {
type: 'POST',
url: '/r/shortner/',
data: {
data: '/' + window.location.pathname + this.props.slice.querystring(),
data: '/' + window.location.pathname + window.location.search,
},
success: (data) => {
this.setState({
@@ -51,16 +49,15 @@ export default class URLShortLinkButton extends React.Component {
}
render() {
const shortUrl = this.state.shortUrl;
const isDisabled = shortUrl === '';
return (
<OverlayTrigger
trigger="click"
rootClose
placement="left"
onEnter={this.getShortUrl.bind(this)}
overlay={this.renderPopover()}
>
<span className="btn btn-default btn-sm" disabled={isDisabled}>
<span className="btn btn-default btn-sm">
<i className="fa fa-link"></i>&nbsp;
</span>
</OverlayTrigger>

View File

@@ -5,7 +5,7 @@
// js
const $ = window.$ = require('jquery');
const px = require('./../modules/caravel.js');
const showModal = require('./../modules/utils.js').showModal;
const utils = require('./../modules/utils.js');
const jQuery = window.jQuery = require('jquery'); // eslint-disable-line
import React from 'react';
@@ -81,7 +81,7 @@ function saveSlice() {
if (action === 'saveas') {
const sliceName = $('input[name=new_slice_name]').val();
if (sliceName === '') {
showModal({
utils.showModal({
title: 'Error',
body: 'You must pick a name for the new slice',
});
@@ -91,13 +91,13 @@ function saveSlice() {
}
const addToDash = $('input[name=addToDash]:checked').val();
if (addToDash === 'existing' && $('#save_to_dashboard_id').val() === '') {
showModal({
utils.showModal({
title: 'Error',
body: 'You must pick an existing dashboard',
});
return;
} else if (addToDash === 'new' && $('input[name=new_dashboard_name]').val() === '') {
showModal({
utils.showModal({
title: 'Error',
body: 'Please enter a name for the new dashboard',
});
@@ -336,16 +336,7 @@ function initExploreView() {
prepSaveDialog();
}
function initComponents() {
const queryAndSaveBtnsEl = document.getElementById('js-query-and-save-btns');
ReactDOM.render(
<QueryAndSaveBtns
canAdd={queryAndSaveBtnsEl.getAttribute('data-can-add')}
onQuery={() => query(true)}
/>,
queryAndSaveBtnsEl
);
function renderExploreActions() {
const exploreActionsEl = document.getElementById('js-explore-actions');
ReactDOM.render(
<ExploreActionButtons
@@ -356,14 +347,49 @@ function initComponents() {
);
}
function initComponents() {
const queryAndSaveBtnsEl = document.getElementById('js-query-and-save-btns');
ReactDOM.render(
<QueryAndSaveBtns
canAdd={queryAndSaveBtnsEl.getAttribute('data-can-add')}
onQuery={() => query(true)}
/>,
queryAndSaveBtnsEl
);
renderExploreActions();
}
let exploreController = {
type: 'slice',
done: (sliceObj) => {
slice = sliceObj;
renderExploreActions();
const cachedSelector = $('#is_cached');
if (slice.data !== undefined && slice.data.is_cached) {
cachedSelector
.attr(
'title',
`Served from data cached at ${slice.data.cached_dttm}. Click [Query] to force refresh`)
.show()
.tooltip('fixTitle');
} else {
cachedSelector.hide();
}
},
error: (sliceObj) => {
slice = sliceObj;
renderExploreActions();
},
};
exploreController = Object.assign({}, utils.controllerInterface, exploreController);
$(document).ready(function () {
const data = $('.slice').data('slice');
initExploreView();
slice = px.Slice(data);
$('.slice').data('slice', slice);
slice = px.Slice(data, exploreController);
// call vis render method, which issues ajax
// calls render on the slice for the first time