Skip to content

Commit

Permalink
feat(core): add custom_params to form_data (#929)
Browse files Browse the repository at this point in the history
* feat(core): add custom_params to form_data

* Update packages/superset-ui-chart-controls/src/sections.tsx

Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>

* Update packages/superset-ui-chart-controls/src/sections.tsx

Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>

Co-authored-by: Jesse Yang <jesse.yang@airbnb.com>
  • Loading branch information
2 people authored and zhaoyongjie committed Nov 26, 2021
1 parent 90e6a6f commit b45cc00
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ export const datasourceAndVizType: ControlPanelSectionConfig = {
type: 'HiddenControl',
label: t('URL Parameters'),
hidden: true,
description: t('Extra parameters for use in jinja templated queries'),
description: t('Extra url parameters for use in Jinja templated queries'),
},
},
{
name: 'custom_params',
config: {
type: 'HiddenControl',
label: t('Extra Parameters'),
hidden: true,
description: t(
'Extra parameters that any plugins can choose to set for use in Jinja templated queries',
),
},
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function buildQueryObject<T extends QueryFormData>(
timeseries_limit_metric,
granularity,
url_params = {},
custom_params = {},
...residualFormData
} = formData;
const { append_form_data = {}, override_form_data = {} } = extra_form_data;
Expand Down Expand Up @@ -65,6 +66,7 @@ export default function buildQueryObject<T extends QueryFormData>(
timeseries_limit_metric: timeseries_limit_metric || undefined,
order_desc: typeof order_desc === 'undefined' ? true : order_desc,
url_params: url_params || undefined,
custom_params,
};
// append and override extra form data used by native filters
queryObject = appendExtraFormData(queryObject, append_form_data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ export interface QueryObject extends QueryFields, TimeRange, ResidualQueryObject

url_params?: Record<string, string>;

custom_params?: Record<string, string>;

/** Free-form WHERE SQL: multiple clauses are concatenated by AND */
where?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export interface BaseFormData extends TimeRange, FormDataResidual {
time_range_endpoints?: TimeRangeEndpoints;
annotation_layers?: AnnotationLayer[];
url_params?: Record<string, string>;
custom_params?: Record<string, string>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,15 @@ describe('buildQueryObject', () => {
}).url_params,
).toBeUndefined();
});

it('should populate custom_params', () => {
const customParams = { customObject: { id: 137, name: 'C-137' } };
query = buildQueryObject({
datasource: '5__table',
granularity_sqla: 'ds',
viz_type: 'table',
custom_params: customParams,
});
expect(query.custom_params).toEqual(customParams);
});
});

0 comments on commit b45cc00

Please sign in to comment.