From c145800710b221cce9ab6f032e0af932e1b7bef1 Mon Sep 17 00:00:00 2001 From: hughhhh Date: Thu, 22 Jul 2021 14:15:25 -0400 Subject: [PATCH] saving for now --- .../components/PropertiesModal/index.tsx | 25 ++++++++++++++++++- .../src/explore/exploreUtils/index.js | 2 ++ superset/charts/api.py | 5 +++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/explore/components/PropertiesModal/index.tsx b/superset-frontend/src/explore/components/PropertiesModal/index.tsx index 0c46f6ba792f1..490e989f4c816 100644 --- a/superset-frontend/src/explore/components/PropertiesModal/index.tsx +++ b/superset-frontend/src/explore/components/PropertiesModal/index.tsx @@ -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; @@ -70,7 +71,9 @@ export default function PropertiesModal({ const fetchChartData = useCallback( async function fetchChartData() { + console.log(slice); try { + console.log('fetching chart data!'); const response = await SupersetClient.get({ endpoint: `/api/v1/chart/${slice.slice_id}`, }); @@ -81,6 +84,26 @@ export default function PropertiesModal({ label: `${owner.first_name} ${owner.last_name}`, })), ); + + if (chart.query_context === null) { + // Build query context + const queryContext = buildV1ChartDataPayload({ + formData: slice.form_data as QueryFormData, + force: false, + resultFormat: 'json', + resultType: 'full', + }); + + console.log('queryContext', queryContext); + + // Todo: Make PUT to update query context + // const response = await makeApi({ + // method: 'PUT', + // endpoint: `/api/v1/chart/${}`, + // })(`q=${queryParams}`); + } + + // set query_context if null } catch (response) { const clientError = await getClientErrorObject(response); showError(clientError); diff --git a/superset-frontend/src/explore/exploreUtils/index.js b/superset-frontend/src/explore/exploreUtils/index.js index ddcd95b82a437..20fa4f2d3ec79 100644 --- a/superset-frontend/src/explore/exploreUtils/index.js +++ b/superset-frontend/src/explore/exploreUtils/index.js @@ -303,6 +303,8 @@ export const exportChart = ({ ownState, }); } + + console.log('making POST for getting data'); postForm(url, payload); }; diff --git a/superset/charts/api.py b/superset/charts/api.py index 0d394cd51857c..2f7f4c7ec5624 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -129,6 +129,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "params", "slice_name", "viz_type", + "query_context", ] show_select_columns = show_columns + ["table.id"] list_columns = [ @@ -337,6 +338,9 @@ def put(self, pk: int) -> Response: 500: $ref: '#/components/responses/500' """ + logger.info("*" * 20) + logger.info("hit put endpoint!!") + logger.info("*" * 20) if not request.is_json: return self.response_400(message="Request is not JSON") @@ -345,7 +349,6 @@ def put(self, pk: int) -> Response: # 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)