mirror of https://github.com/apache/superset.git
fix: Update Query Context on Explore loading (#15865)
* create serialize json function * saving for now * saving for now * lint * cleanup * fix network request * update test * Update tests/integration_tests/charts/api_tests.py Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
This commit is contained in:
parent
5be0a89625
commit
62550db385
|
@ -23,10 +23,11 @@ import Button from 'src/components/Button';
|
||||||
import { OptionsType } from 'react-select/src/types';
|
import { OptionsType } from 'react-select/src/types';
|
||||||
import { AsyncSelect } from 'src/components/Select';
|
import { AsyncSelect } from 'src/components/Select';
|
||||||
import rison from 'rison';
|
import rison from 'rison';
|
||||||
import { t, SupersetClient } from '@superset-ui/core';
|
import { t, SupersetClient, QueryFormData } from '@superset-ui/core';
|
||||||
import Chart, { Slice } from 'src/types/Chart';
|
import Chart, { Slice } from 'src/types/Chart';
|
||||||
import { Form, FormItem } from 'src/components/Form';
|
import { Form, FormItem } from 'src/components/Form';
|
||||||
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
|
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
|
||||||
|
import { buildV1ChartDataPayload } from '../../exploreUtils';
|
||||||
|
|
||||||
type PropertiesModalProps = {
|
type PropertiesModalProps = {
|
||||||
slice: Slice;
|
slice: Slice;
|
||||||
|
@ -81,6 +82,26 @@ export default function PropertiesModal({
|
||||||
label: `${owner.first_name} ${owner.last_name}`,
|
label: `${owner.first_name} ${owner.last_name}`,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (chart.query_context === null) {
|
||||||
|
// set query_context if null
|
||||||
|
const queryContext = buildV1ChartDataPayload({
|
||||||
|
formData: slice.form_data as QueryFormData,
|
||||||
|
force: false,
|
||||||
|
resultFormat: 'json',
|
||||||
|
resultType: 'full',
|
||||||
|
setDataMask: null,
|
||||||
|
ownState: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
await SupersetClient.put({
|
||||||
|
endpoint: `/api/v1/chart/${slice.slice_id}`,
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
query_context: JSON.stringify(queryContext),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (response) {
|
} catch (response) {
|
||||||
const clientError = await getClientErrorObject(response);
|
const clientError = await getClientErrorObject(response);
|
||||||
showError(clientError);
|
showError(clientError);
|
||||||
|
|
|
@ -130,6 +130,7 @@ class ChartRestApi(BaseSupersetModelRestApi):
|
||||||
"params",
|
"params",
|
||||||
"slice_name",
|
"slice_name",
|
||||||
"viz_type",
|
"viz_type",
|
||||||
|
"query_context",
|
||||||
]
|
]
|
||||||
show_select_columns = show_columns + ["table.id"]
|
show_select_columns = show_columns + ["table.id"]
|
||||||
list_columns = [
|
list_columns = [
|
||||||
|
@ -338,7 +339,6 @@ class ChartRestApi(BaseSupersetModelRestApi):
|
||||||
500:
|
500:
|
||||||
$ref: '#/components/responses/500'
|
$ref: '#/components/responses/500'
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not request.is_json:
|
if not request.is_json:
|
||||||
return self.response_400(message="Request is not JSON")
|
return self.response_400(message="Request is not JSON")
|
||||||
try:
|
try:
|
||||||
|
@ -346,7 +346,6 @@ class ChartRestApi(BaseSupersetModelRestApi):
|
||||||
# This validates custom Schema with custom validations
|
# This validates custom Schema with custom validations
|
||||||
except ValidationError as error:
|
except ValidationError as error:
|
||||||
return self.response_400(message=error.messages)
|
return self.response_400(message=error.messages)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
changed_model = UpdateChartCommand(g.user, pk, item).run()
|
changed_model = UpdateChartCommand(g.user, pk, item).run()
|
||||||
response = self.response(200, id=changed_model.id, result=item)
|
response = self.response(200, id=changed_model.id, result=item)
|
||||||
|
|
|
@ -722,6 +722,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin):
|
||||||
"params": None,
|
"params": None,
|
||||||
"slice_name": "title",
|
"slice_name": "title",
|
||||||
"viz_type": None,
|
"viz_type": None,
|
||||||
|
"query_context": None,
|
||||||
}
|
}
|
||||||
data = json.loads(rv.data.decode("utf-8"))
|
data = json.loads(rv.data.decode("utf-8"))
|
||||||
self.assertEqual(data["result"], expected_result)
|
self.assertEqual(data["result"], expected_result)
|
||||||
|
|
Loading…
Reference in New Issue