refactor: add set data mask to build query (#13417)

* refactor: add set data mask to build query

* refactor: update hooks placement
This commit is contained in:
simcha90 2021-03-04 10:08:37 +02:00 committed by GitHub
parent ca27b00f3a
commit 7f0fbb5b45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -41,6 +41,7 @@ import { logEvent } from '../logger/actions';
import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger/LogUtils'; import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger/LogUtils';
import { getClientErrorObject } from '../utils/getClientErrorObject'; import { getClientErrorObject } from '../utils/getClientErrorObject';
import { allowCrossDomain as domainShardingEnabled } from '../utils/hostNamesConfig'; import { allowCrossDomain as domainShardingEnabled } from '../utils/hostNamesConfig';
import { updateExtraFormData } from '../dashboard/actions/nativeFilters';
export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED'; export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED';
export function chartUpdateStarted(queryController, latestQueryFormData, key) { export function chartUpdateStarted(queryController, latestQueryFormData, key) {
@ -163,12 +164,14 @@ const v1ChartDataRequest = async (
resultType, resultType,
force, force,
requestParams, requestParams,
setDataMask,
) => { ) => {
const payload = buildV1ChartDataPayload({ const payload = buildV1ChartDataPayload({
formData, formData,
resultType, resultType,
resultFormat, resultFormat,
force, force,
setDataMask,
}); });
// The dashboard id is added to query params for tracking purposes // The dashboard id is added to query params for tracking purposes
@ -200,6 +203,7 @@ const v1ChartDataRequest = async (
export async function getChartDataRequest({ export async function getChartDataRequest({
formData, formData,
setDataMask = () => {},
resultFormat = 'json', resultFormat = 'json',
resultType = 'full', resultType = 'full',
force = false, force = false,
@ -234,6 +238,7 @@ export async function getChartDataRequest({
resultType, resultType,
force, force,
querySettings, querySettings,
setDataMask,
); );
} }
@ -361,7 +366,11 @@ export function exploreJSON(
}; };
if (dashboardId) requestParams.dashboard_id = dashboardId; if (dashboardId) requestParams.dashboard_id = dashboardId;
const setDataMask = filtersState => {
dispatch(updateExtraFormData(formData.slice_id, filtersState));
};
const chartDataRequest = getChartDataRequest({ const chartDataRequest = getChartDataRequest({
setDataMask,
formData, formData,
resultFormat: 'json', resultFormat: 'json',
resultType: 'full', resultType: 'full',

View File

@ -207,6 +207,7 @@ export const buildV1ChartDataPayload = ({
force, force,
resultFormat, resultFormat,
resultType, resultType,
setDataMask,
}) => { }) => {
const buildQuery = const buildQuery =
getChartBuildQueryRegistry().get(formData.viz_type) ?? getChartBuildQueryRegistry().get(formData.viz_type) ??
@ -216,12 +217,19 @@ export const buildV1ChartDataPayload = ({
...baseQueryObject, ...baseQueryObject,
}, },
])); ]));
return buildQuery({ return buildQuery(
...formData, {
force, ...formData,
result_format: resultFormat, force,
result_type: resultType, result_format: resultFormat,
}); result_type: resultType,
},
{
hooks: {
setDataMask,
},
},
);
}; };
export const getLegacyEndpointType = ({ resultType, resultFormat }) => export const getLegacyEndpointType = ({ resultType, resultFormat }) =>