Skip to content

Commit

Permalink
chore: deprecate /superset/slice_json/<int:slice_id> and /superset/an…
Browse files Browse the repository at this point in the history
…notation_json/<int:layer_id> (#22496)
  • Loading branch information
diegomedina248 authored Jan 27, 2023
1 parent 8226110 commit bed10a0
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 73 deletions.
36 changes: 21 additions & 15 deletions superset-frontend/src/components/Chart/chartAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

This file was deleted.

10 changes: 4 additions & 6 deletions superset-frontend/src/explore/exploreUtils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions superset/common/query_context_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,7 @@ def get_viz_annotation_data(
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,
Expand Down
2 changes: 2 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ def generate_json(
@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:
Expand All @@ -528,6 +529,7 @@ def slice_json(self, slice_id: int) -> FlaskResponse:
@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:
Expand Down

0 comments on commit bed10a0

Please sign in to comment.