mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
chore: deprecate /superset/slice_json/<int:slice_id> and /superset/annotation_json/<int:layer_id> (#22496)
This commit is contained in:
parent
8226110be8
commit
bed10a0e2b
@ -30,10 +30,7 @@ import {
|
|||||||
shouldUseLegacyApi,
|
shouldUseLegacyApi,
|
||||||
getChartDataUri,
|
getChartDataUri,
|
||||||
} from 'src/explore/exploreUtils';
|
} from 'src/explore/exploreUtils';
|
||||||
import {
|
import { requiresQuery } from 'src/modules/AnnotationTypes';
|
||||||
requiresQuery,
|
|
||||||
ANNOTATION_SOURCE_TYPES,
|
|
||||||
} from 'src/modules/AnnotationTypes';
|
|
||||||
|
|
||||||
import { addDangerToast } from 'src/components/MessageToasts/actions';
|
import { addDangerToast } from 'src/components/MessageToasts/actions';
|
||||||
import { logEvent } from 'src/logger/actions';
|
import { logEvent } from 'src/logger/actions';
|
||||||
@ -290,26 +287,35 @@ export function runAnnotationQuery({
|
|||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isNative = annotation.sourceType === ANNOTATION_SOURCE_TYPES.NATIVE;
|
const url = getAnnotationJsonUrl(annotation.value, force);
|
||||||
const url = getAnnotationJsonUrl(
|
|
||||||
annotation.value,
|
|
||||||
sliceFormData,
|
|
||||||
isNative,
|
|
||||||
force,
|
|
||||||
);
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const { signal } = controller;
|
const { signal } = controller;
|
||||||
|
|
||||||
dispatch(annotationQueryStarted(annotation, controller, sliceKey));
|
dispatch(annotationQueryStarted(annotation, controller, sliceKey));
|
||||||
|
|
||||||
return SupersetClient.get({
|
const annotationIndex = fd?.annotation_layers?.findIndex(
|
||||||
|
it => it.name === annotation.name,
|
||||||
|
);
|
||||||
|
if (annotationIndex >= 0) {
|
||||||
|
fd.annotation_layers[annotationIndex].overrides = sliceFormData;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SupersetClient.post({
|
||||||
url,
|
url,
|
||||||
signal,
|
signal,
|
||||||
timeout: timeout * 1000,
|
timeout: timeout * 1000,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
jsonPayload: buildV1ChartDataPayload({
|
||||||
|
formData: fd,
|
||||||
|
force,
|
||||||
|
resultFormat: 'json',
|
||||||
|
resultType: 'full',
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
.then(({ json }) =>
|
.then(({ json }) => {
|
||||||
dispatch(annotationQuerySuccess(annotation, json, sliceKey)),
|
const data = json?.result?.[0]?.annotation_data?.[annotation.name];
|
||||||
)
|
return dispatch(annotationQuerySuccess(annotation, { data }, sliceKey));
|
||||||
|
})
|
||||||
.catch(response =>
|
.catch(response =>
|
||||||
getClientErrorObject(response).then(err => {
|
getClientErrorObject(response).then(err => {
|
||||||
if (err.statusText === 'timeout') {
|
if (err.statusText === 'timeout') {
|
||||||
|
@ -71,7 +71,7 @@ class AnnotationLayerControl extends React.PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// preload the AnotationLayer component and dependent libraries i.e. mathjs
|
// preload the AnnotationLayer component and dependent libraries i.e. mathjs
|
||||||
AnnotationLayer.preload();
|
AnnotationLayer.preload();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,51 +0,0 @@
|
|||||||
/**
|
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
|
||||||
* or more contributor license agreements. See the NOTICE file
|
|
||||||
* distributed with this work for additional information
|
|
||||||
* regarding copyright ownership. The ASF licenses this file
|
|
||||||
* to you under the Apache License, Version 2.0 (the
|
|
||||||
* "License"); you may not use this file except in compliance
|
|
||||||
* with the License. You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
import { getAnnotationJsonUrl } from '.';
|
|
||||||
|
|
||||||
let windowLocation: any;
|
|
||||||
|
|
||||||
beforeAll(() => {
|
|
||||||
windowLocation = window.location;
|
|
||||||
// @ts-expect-error
|
|
||||||
delete window.location;
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
window.location = {
|
|
||||||
search: '?testA=0&testB=1',
|
|
||||||
} as any;
|
|
||||||
});
|
|
||||||
|
|
||||||
afterAll(() => {
|
|
||||||
window.location = windowLocation;
|
|
||||||
});
|
|
||||||
|
|
||||||
test('get correct annotation when isNative:true', () => {
|
|
||||||
const response = getAnnotationJsonUrl('slice_id', 'form_data', true);
|
|
||||||
expect(response).toBe(
|
|
||||||
'/superset/annotation_json/slice_id?form_data=%22form_data%22',
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('get correct annotation when isNative:false', () => {
|
|
||||||
const response = getAnnotationJsonUrl('slice_id', { json: 'my-data' }, false);
|
|
||||||
expect(response).toBe(
|
|
||||||
'/superset/slice_json/slice_id?form_data=%7B%22json%22%3A%22my-data%22%7D',
|
|
||||||
);
|
|
||||||
});
|
|
@ -61,18 +61,16 @@ export function getHostName(allowDomainSharding = false) {
|
|||||||
return availableDomains[currentIndex];
|
return availableDomains[currentIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getAnnotationJsonUrl(slice_id, form_data, isNative, force) {
|
export function getAnnotationJsonUrl(slice_id, force) {
|
||||||
if (slice_id === null || slice_id === undefined) {
|
if (slice_id === null || slice_id === undefined) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uri = URI(window.location.search);
|
const uri = URI(window.location.search);
|
||||||
const endpoint = isNative ? 'annotation_json' : 'slice_json';
|
|
||||||
return uri
|
return uri
|
||||||
.pathname(`/superset/${endpoint}/${slice_id}`)
|
.pathname('/api/v1/chart/data')
|
||||||
.search({
|
.search({
|
||||||
form_data: safeStringify(form_data, (key, value) =>
|
form_data: safeStringify({ slice_id }),
|
||||||
value === null ? undefined : value,
|
|
||||||
),
|
|
||||||
force,
|
force,
|
||||||
})
|
})
|
||||||
.toString();
|
.toString();
|
||||||
|
@ -576,6 +576,7 @@ class QueryContextProcessor:
|
|||||||
if not chart.datasource:
|
if not chart.datasource:
|
||||||
raise QueryObjectValidationError(_("The chart datasource does not exist"))
|
raise QueryObjectValidationError(_("The chart datasource does not exist"))
|
||||||
form_data = chart.form_data.copy()
|
form_data = chart.form_data.copy()
|
||||||
|
form_data.update(annotation_layer.get("overrides", {}))
|
||||||
try:
|
try:
|
||||||
viz_obj = get_viz(
|
viz_obj = get_viz(
|
||||||
datasource_type=chart.datasource.type,
|
datasource_type=chart.datasource.type,
|
||||||
|
@ -505,6 +505,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||||||
@expose("/slice_json/<int:slice_id>")
|
@expose("/slice_json/<int:slice_id>")
|
||||||
@etag_cache()
|
@etag_cache()
|
||||||
@check_resource_permissions(check_slice_perms)
|
@check_resource_permissions(check_slice_perms)
|
||||||
|
@deprecated()
|
||||||
def slice_json(self, slice_id: int) -> FlaskResponse:
|
def slice_json(self, slice_id: int) -> FlaskResponse:
|
||||||
form_data, slc = get_form_data(slice_id, use_slice_data=True)
|
form_data, slc = get_form_data(slice_id, use_slice_data=True)
|
||||||
if not slc:
|
if not slc:
|
||||||
@ -528,6 +529,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||||||
@has_access_api
|
@has_access_api
|
||||||
@event_logger.log_this
|
@event_logger.log_this
|
||||||
@expose("/annotation_json/<int:layer_id>")
|
@expose("/annotation_json/<int:layer_id>")
|
||||||
|
@deprecated()
|
||||||
def annotation_json( # pylint: disable=no-self-use
|
def annotation_json( # pylint: disable=no-self-use
|
||||||
self, layer_id: int
|
self, layer_id: int
|
||||||
) -> FlaskResponse:
|
) -> FlaskResponse:
|
||||||
|
Loading…
Reference in New Issue
Block a user