feat: expand new chart data endpoint coverage (#9903)

* feat: implement new chart API for additional components

* Fix python tests

* Fix tests

* Fix lint

* fix camel case error in requestParams

* lint

* fix samples row limit

* Add samples row limit to config

* remove unnecessary code

* lint

* Address review comments
This commit is contained in:
Ville Brofeldt
2020-06-02 10:47:28 +03:00
committed by GitHub
parent c7618ee54b
commit 38a6bd79da
12 changed files with 196 additions and 126 deletions

View File

@@ -41,7 +41,7 @@ import { SupersetClient } from '@superset-ui/connection';
import getClientErrorObject from '../../utils/getClientErrorObject';
import CopyToClipboard from './../../components/CopyToClipboard';
import { getExploreUrl } from '../exploreUtils';
import { getChartDataRequest } from '../../chart/chartAction';
import Loading from '../../components/Loading';
import ModalTrigger from './../../components/ModalTrigger';
@@ -87,33 +87,29 @@ export class DisplayQueryButton extends React.PureComponent {
this.openPropertiesModal = this.openPropertiesModal.bind(this);
this.closePropertiesModal = this.closePropertiesModal.bind(this);
}
beforeOpen(endpointType) {
beforeOpen(resultType) {
this.setState({ isLoading: true });
const url = getExploreUrl({
formData: this.props.latestQueryFormData,
endpointType,
});
SupersetClient.post({
url,
postPayload: { form_data: this.props.latestQueryFormData },
})
.then(({ json }) => {
getChartDataRequest(this.props.latestQueryFormData, 'json', resultType)
.then(response => {
// Currently displaying of only first query is supported
const result = response.result[0];
this.setState({
language: json.language,
query: json.query,
data: json.data,
language: result.language,
query: result.query,
data: result.data,
isLoading: false,
error: null,
});
})
.catch(response =>
.catch(response => {
getClientErrorObject(response).then(({ error, statusText }) => {
this.setState({
error: error || statusText || t('Sorry, An error occurred'),
isLoading: false,
});
}),
);
});
});
}
changeFilterText(event) {
this.setState({ filterText: event.target.value });

View File

@@ -48,7 +48,7 @@ export default function ExploreActionButtons({
'disabled disabledButton': !canDownload,
});
const doExportCSV = exportChart.bind(this, latestQueryFormData, 'csv');
const doExportChart = exportChart.bind(this, latestQueryFormData, 'json');
const doExportChart = exportChart.bind(this, latestQueryFormData, 'results');
return (
<div className="btn-group results" role="group">

View File

@@ -18,8 +18,8 @@
*/
/* eslint camelcase: 0 */
import URI from 'urijs';
import { getChartMetadataRegistry } from '@superset-ui/chart';
import { availableDomains } from '../utils/hostNamesConfig';
import { SupersetClient } from '@superset-ui/connection';
import { allowCrossDomain, availableDomains } from '../utils/hostNamesConfig';
import { safeStringify } from '../utils/safeStringify';
const MAX_URL_LENGTH = 8000;
@@ -67,7 +67,9 @@ export function getAnnotationJsonUrl(slice_id, form_data, isNative) {
export function getURIDirectory(endpointType = 'base') {
// Building the directory part of the URI
if (
['json', 'csv', 'query', 'results', 'samples'].indexOf(endpointType) >= 0
['full', 'json', 'csv', 'query', 'results', 'samples'].includes(
endpointType,
)
) {
return '/superset/explore_json/';
}
@@ -107,11 +109,6 @@ export function getExploreLongUrl(
return url;
}
export function shouldUseLegacyApi(formData) {
const { useLegacyApi } = getChartMetadataRegistry().get(formData.viz_type);
return useLegacyApi || false;
}
export function getExploreUrl({
formData,
endpointType = 'base',