You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by di...@apache.org on 2023/01/27 16:50:27 UTC
[superset] branch master updated: chore: deprecate /superset/slice_json/ and /superset/annotation_json/ (#22496)
This is an automated email from the ASF dual-hosted git repository.
diegomedina24 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new bed10a0e2b chore: deprecate /superset/slice_json/<int:slice_id> and /superset/annotation_json/<int:layer_id> (#22496)
bed10a0e2b is described below
commit bed10a0e2bf8f29e2568cdbe1af0839890dfa58d
Author: Diego Medina <di...@gmail.com>
AuthorDate: Fri Jan 27 13:50:19 2023 -0300
chore: deprecate /superset/slice_json/<int:slice_id> and /superset/annotation_json/<int:layer_id> (#22496)
---
.../src/components/Chart/chartAction.js | 36 ++++++++-------
.../controls/AnnotationLayerControl/index.jsx | 2 +-
.../exploreUtils/getAnnotationJsonUrl.test.ts | 51 ----------------------
.../src/explore/exploreUtils/index.js | 10 ++---
superset/common/query_context_processor.py | 1 +
superset/views/core.py | 2 +
6 files changed, 29 insertions(+), 73 deletions(-)
diff --git a/superset-frontend/src/components/Chart/chartAction.js b/superset-frontend/src/components/Chart/chartAction.js
index f59c2da719..7418a8f8b7 100644
--- a/superset-frontend/src/components/Chart/chartAction.js
+++ b/superset-frontend/src/components/Chart/chartAction.js
@@ -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') {
diff --git a/superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.jsx b/superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.jsx
index db3bbca272..f70557170c 100644
--- a/superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.jsx
+++ b/superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.jsx
@@ -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();
}
diff --git a/superset-frontend/src/explore/exploreUtils/getAnnotationJsonUrl.test.ts b/superset-frontend/src/explore/exploreUtils/getAnnotationJsonUrl.test.ts
deleted file mode 100644
index 388c3b9a03..0000000000
--- a/superset-frontend/src/explore/exploreUtils/getAnnotationJsonUrl.test.ts
+++ /dev/null
@@ -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',
- );
-});
diff --git a/superset-frontend/src/explore/exploreUtils/index.js b/superset-frontend/src/explore/exploreUtils/index.js
index 0e6a79ab91..1d678427ff 100644
--- a/superset-frontend/src/explore/exploreUtils/index.js
+++ b/superset-frontend/src/explore/exploreUtils/index.js
@@ -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();
diff --git a/superset/common/query_context_processor.py b/superset/common/query_context_processor.py
index 17cc5fd411..e6fa964e4d 100644
--- a/superset/common/query_context_processor.py
+++ b/superset/common/query_context_processor.py
@@ -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,
diff --git a/superset/views/core.py b/superset/views/core.py
index d65023d600..9733ea2910 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -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: