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 { AsyncSelect } from 'src/components/Select';
|
||||
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 { Form, FormItem } from 'src/components/Form';
|
||||
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
|
||||
import { buildV1ChartDataPayload } from '../../exploreUtils';
|
||||
|
||||
type PropertiesModalProps = {
|
||||
slice: Slice;
|
||||
|
@ -81,6 +82,26 @@ export default function PropertiesModal({
|
|||
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) {
|
||||
const clientError = await getClientErrorObject(response);
|
||||
showError(clientError);
|
||||
|
|
|
@ -130,6 +130,7 @@ class ChartRestApi(BaseSupersetModelRestApi):
|
|||
"params",
|
||||
"slice_name",
|
||||
"viz_type",
|
||||
"query_context",
|
||||
]
|
||||
show_select_columns = show_columns + ["table.id"]
|
||||
list_columns = [
|
||||
|
@ -338,7 +339,6 @@ class ChartRestApi(BaseSupersetModelRestApi):
|
|||
500:
|
||||
$ref: '#/components/responses/500'
|
||||
"""
|
||||
|
||||
if not request.is_json:
|
||||
return self.response_400(message="Request is not JSON")
|
||||
try:
|
||||
|
@ -346,7 +346,6 @@ class ChartRestApi(BaseSupersetModelRestApi):
|
|||
# This validates custom Schema with custom validations
|
||||
except ValidationError as error:
|
||||
return self.response_400(message=error.messages)
|
||||
|
||||
try:
|
||||
changed_model = UpdateChartCommand(g.user, pk, item).run()
|
||||
response = self.response(200, id=changed_model.id, result=item)
|
||||
|
|
|
@ -722,6 +722,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin):
|
|||
"params": None,
|
||||
"slice_name": "title",
|
||||
"viz_type": None,
|
||||
"query_context": None,
|
||||
}
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(data["result"], expected_result)
|
||||
|
|
Loading…
Reference in New Issue