mirror of
https://github.com/apache/superset.git
synced 2026-04-26 19:44:58 +00:00
feat: finalize Word Cloud move to new chart data endpoint (#9975)
* remove word cloud from viz.py * Fix Run in SQL Lab * remove deprecated python tests * break out legacy endpoint type into function * Break out exploreChart from exportChart and implement results type * Fix jest tests and refactor accordingly * lint * Rename v1 payload function * Add dashboard id to v1 chart data request url params * Add support for domain sharding to v1 chart data request
This commit is contained in:
@@ -19,8 +19,12 @@
|
||||
/* eslint camelcase: 0 */
|
||||
import URI from 'urijs';
|
||||
import { SupersetClient } from '@superset-ui/connection';
|
||||
import { allowCrossDomain, availableDomains } from '../utils/hostNamesConfig';
|
||||
import { safeStringify } from '../utils/safeStringify';
|
||||
import { allowCrossDomain, availableDomains } from 'src/utils/hostNamesConfig';
|
||||
import { safeStringify } from 'src/utils/safeStringify';
|
||||
import {
|
||||
getChartBuildQueryRegistry,
|
||||
getChartMetadataRegistry,
|
||||
} from '@superset-ui/chart';
|
||||
|
||||
const MAX_URL_LENGTH = 8000;
|
||||
|
||||
@@ -30,7 +34,7 @@ export function getChartKey(explore) {
|
||||
}
|
||||
|
||||
let requestCounter = 0;
|
||||
function getHostName(allowDomainSharding = false) {
|
||||
export function getHostName(allowDomainSharding = false) {
|
||||
let currentIndex = 0;
|
||||
if (allowDomainSharding) {
|
||||
currentIndex = requestCounter % availableDomains.length;
|
||||
@@ -44,7 +48,6 @@ function getHostName(allowDomainSharding = false) {
|
||||
requestCounter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return availableDomains[currentIndex];
|
||||
}
|
||||
|
||||
@@ -109,6 +112,22 @@ export function getExploreLongUrl(
|
||||
return url;
|
||||
}
|
||||
|
||||
export function getChartDataUri({ path, qs, allowDomainSharding = false }) {
|
||||
// The search params from the window.location are carried through,
|
||||
// but can be specified with curUrl (used for unit tests to spoof
|
||||
// the window.location).
|
||||
let uri = new URI({
|
||||
protocol: location.protocol.slice(0, -1),
|
||||
hostname: getHostName(allowDomainSharding),
|
||||
port: location.port ? location.port : '',
|
||||
path,
|
||||
});
|
||||
if (qs) {
|
||||
uri = uri.search(qs);
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
export function getExploreUrl({
|
||||
formData,
|
||||
endpointType = 'base',
|
||||
@@ -121,17 +140,7 @@ export function getExploreUrl({
|
||||
if (!formData.datasource) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// The search params from the window.location are carried through,
|
||||
// but can be specified with curUrl (used for unit tests to spoof
|
||||
// the window.location).
|
||||
let uri = new URI({
|
||||
protocol: location.protocol.slice(0, -1),
|
||||
hostname: getHostName(allowDomainSharding),
|
||||
port: location.port ? location.port : '',
|
||||
path: '/',
|
||||
});
|
||||
|
||||
let uri = getChartDataUri({ path: '/', allowDomainSharding });
|
||||
if (curUrl) {
|
||||
uri = URI(URI(curUrl).search());
|
||||
}
|
||||
@@ -183,6 +192,23 @@ export function getExploreUrl({
|
||||
return uri.search(search).directory(directory).toString();
|
||||
}
|
||||
|
||||
export const shouldUseLegacyApi = formData => {
|
||||
const { useLegacyApi } = getChartMetadataRegistry().get(formData.viz_type);
|
||||
return useLegacyApi || false;
|
||||
};
|
||||
|
||||
export const buildV1ChartDataPayload = ({ formData, force }) => {
|
||||
const buildQuery = getChartBuildQueryRegistry().get(formData.viz_type);
|
||||
return buildQuery({
|
||||
...formData,
|
||||
force,
|
||||
});
|
||||
};
|
||||
|
||||
export const getLegacyEndpointType = ({ resultType, resultFormat }) => {
|
||||
return resultFormat === 'csv' ? resultFormat : resultType;
|
||||
};
|
||||
|
||||
export function postForm(url, payload, target = '_blank') {
|
||||
if (!url) {
|
||||
return;
|
||||
@@ -208,11 +234,40 @@ export function postForm(url, payload, target = '_blank') {
|
||||
document.body.removeChild(hiddenForm);
|
||||
}
|
||||
|
||||
export function exportChart(formData, endpointType) {
|
||||
export const exportChart = ({
|
||||
formData,
|
||||
resultFormat = 'json',
|
||||
resultType = 'full',
|
||||
force = false,
|
||||
}) => {
|
||||
let url;
|
||||
let payload;
|
||||
if (shouldUseLegacyApi(formData)) {
|
||||
const endpointType = getLegacyEndpointType({ resultFormat, resultType });
|
||||
url = getExploreUrl({
|
||||
formData,
|
||||
endpointType,
|
||||
allowDomainSharding: false,
|
||||
});
|
||||
payload = formData;
|
||||
} else {
|
||||
url = '/api/v1/chart/data';
|
||||
const buildQuery = getChartBuildQueryRegistry().get(formData.viz_type);
|
||||
payload = buildQuery({
|
||||
...formData,
|
||||
force,
|
||||
});
|
||||
payload.result_type = resultType;
|
||||
payload.result_format = resultFormat;
|
||||
}
|
||||
postForm(url, payload);
|
||||
};
|
||||
|
||||
export const exploreChart = formData => {
|
||||
const url = getExploreUrl({
|
||||
formData,
|
||||
endpointType,
|
||||
endpointType: 'base',
|
||||
allowDomainSharding: false,
|
||||
});
|
||||
postForm(url, formData);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user