mirror of https://github.com/apache/superset.git
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,
|
||||
getChartDataUri,
|
||||
} from 'src/explore/exploreUtils';
|
||||
import {
|
||||
requiresQuery,
|
||||
ANNOTATION_SOURCE_TYPES,
|
||||
} from 'src/modules/AnnotationTypes';
|
||||
import { requiresQuery } from 'src/modules/AnnotationTypes';
|
||||
|
||||
import { addDangerToast } from 'src/components/MessageToasts/actions';
|
||||
import { logEvent } from 'src/logger/actions';
|
||||
|
@ -290,26 +287,35 @@ export function runAnnotationQuery({
|
|||
: undefined;
|
||||
}
|
||||
|
||||
const isNative = annotation.sourceType === ANNOTATION_SOURCE_TYPES.NATIVE;
|
||||
const url = getAnnotationJsonUrl(
|
||||
annotation.value,
|
||||
sliceFormData,
|
||||
isNative,
|
||||
force,
|
||||
);
|
||||
const url = getAnnotationJsonUrl(annotation.value, force);
|
||||
const controller = new AbortController();
|
||||
const { signal } = controller;
|
||||
|
||||
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,
|
||||
signal,
|
||||
timeout: timeout * 1000,
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
jsonPayload: buildV1ChartDataPayload({
|
||||
formData: fd,
|
||||
force,
|
||||
resultFormat: 'json',
|
||||
resultType: 'full',
|
||||
}),
|
||||
})
|
||||
.then(({ json }) =>
|
||||
dispatch(annotationQuerySuccess(annotation, json, sliceKey)),
|
||||
)
|
||||
.then(({ json }) => {
|
||||
const data = json?.result?.[0]?.annotation_data?.[annotation.name];
|
||||
return dispatch(annotationQuerySuccess(annotation, { data }, sliceKey));
|
||||
})
|
||||
.catch(response =>
|
||||
getClientErrorObject(response).then(err => {
|
||||
if (err.statusText === 'timeout') {
|
||||
|
|
|
@ -71,7 +71,7 @@ class AnnotationLayerControl extends React.PureComponent {
|
|||
}
|
||||
|
||||
componentDidMount() {
|
||||
// preload the AnotationLayer component and dependent libraries i.e. mathjs
|
||||
// preload the AnnotationLayer component and dependent libraries i.e. mathjs
|
||||
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];
|
||||
}
|
||||
|
||||
export function getAnnotationJsonUrl(slice_id, form_data, isNative, force) {
|
||||
export function getAnnotationJsonUrl(slice_id, force) {
|
||||
if (slice_id === null || slice_id === undefined) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const uri = URI(window.location.search);
|
||||
const endpoint = isNative ? 'annotation_json' : 'slice_json';
|
||||
return uri
|
||||
.pathname(`/superset/${endpoint}/${slice_id}`)
|
||||
.pathname('/api/v1/chart/data')
|
||||
.search({
|
||||
form_data: safeStringify(form_data, (key, value) =>
|
||||
value === null ? undefined : value,
|
||||
),
|
||||
form_data: safeStringify({ slice_id }),
|
||||
force,
|
||||
})
|
||||
.toString();
|
||||
|
|
|
@ -576,6 +576,7 @@ class QueryContextProcessor:
|
|||
if not chart.datasource:
|
||||
raise QueryObjectValidationError(_("The chart datasource does not exist"))
|
||||
form_data = chart.form_data.copy()
|
||||
form_data.update(annotation_layer.get("overrides", {}))
|
||||
try:
|
||||
viz_obj = get_viz(
|
||||
datasource_type=chart.datasource.type,
|
||||
|
|
|
@ -505,6 +505,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||
@expose("/slice_json/<int:slice_id>")
|
||||
@etag_cache()
|
||||
@check_resource_permissions(check_slice_perms)
|
||||
@deprecated()
|
||||
def slice_json(self, slice_id: int) -> FlaskResponse:
|
||||
form_data, slc = get_form_data(slice_id, use_slice_data=True)
|
||||
if not slc:
|
||||
|
@ -528,6 +529,7 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
|||
@has_access_api
|
||||
@event_logger.log_this
|
||||
@expose("/annotation_json/<int:layer_id>")
|
||||
@deprecated()
|
||||
def annotation_json( # pylint: disable=no-self-use
|
||||
self, layer_id: int
|
||||
) -> FlaskResponse:
|
||||
|
|
Loading…
Reference in New Issue