mirror of
https://github.com/apache/superset.git
synced 2026-04-10 20:06:13 +00:00
URL Params macro (#2537)
This commit is contained in:
committed by
GitHub
parent
b97a8275d4
commit
10773f96a7
@@ -1,3 +1,4 @@
|
||||
/* global notify */
|
||||
import React from 'react';
|
||||
import { Alert, Button, Col, Modal } from 'react-bootstrap';
|
||||
|
||||
@@ -5,6 +6,7 @@ import Select from 'react-select';
|
||||
import { Table } from 'reactable';
|
||||
import shortid from 'shortid';
|
||||
import $ from 'jquery';
|
||||
import { getExploreUrl } from '../../explorev2/exploreUtils';
|
||||
|
||||
const CHART_TYPES = [
|
||||
{ value: 'dist_bar', label: 'Distribution - Bar Chart', requiresTime: false },
|
||||
@@ -89,7 +91,9 @@ class VisualizeModal extends React.PureComponent {
|
||||
}
|
||||
}
|
||||
if (!hasTime) {
|
||||
hints.push('To use this chart type you need at least one column flagged as a date');
|
||||
hints.push(
|
||||
'To use this chart type you need at least one column ' +
|
||||
'flagged as a date');
|
||||
}
|
||||
}
|
||||
this.setState({ hints });
|
||||
@@ -113,9 +117,10 @@ class VisualizeModal extends React.PureComponent {
|
||||
chartType: this.state.chartType.value,
|
||||
datasourceName: this.state.datasourceName,
|
||||
columns: this.state.columns,
|
||||
sql: this.props.query.executedSql,
|
||||
sql: this.props.query.sql,
|
||||
dbId: this.props.query.dbId,
|
||||
};
|
||||
notify.info('Creating a data source and popping a new tab');
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/superset/sqllab_viz/',
|
||||
@@ -123,9 +128,28 @@ class VisualizeModal extends React.PureComponent {
|
||||
data: {
|
||||
data: JSON.stringify(vizOptions),
|
||||
},
|
||||
success: (url) => {
|
||||
window.open(url);
|
||||
dataType: 'json',
|
||||
success: resp => {
|
||||
const columns = Object.keys(this.state.columns).map(k => this.state.columns[k]);
|
||||
const data = JSON.parse(resp);
|
||||
const mainMetric = columns.filter(d => d.agg)[0];
|
||||
const mainGroupBy = columns.filter(d => d.is_dim)[0];
|
||||
const formData = {
|
||||
datasource: `${data.table_id}__table`,
|
||||
viz_type: this.state.chartType.value,
|
||||
since: '100 years ago',
|
||||
limit: '0',
|
||||
};
|
||||
if (mainMetric) {
|
||||
formData.metrics = [mainMetric.name];
|
||||
formData.metric = mainMetric.name;
|
||||
}
|
||||
if (mainGroupBy) {
|
||||
formData.groupby = mainGroupBy.name;
|
||||
}
|
||||
window.open(getExploreUrl(formData));
|
||||
},
|
||||
error: () => notify('An error occurred while creating the data source'),
|
||||
});
|
||||
}
|
||||
changeDatasourceName(event) {
|
||||
|
||||
Reference in New Issue
Block a user