Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

fix: Add force to QueryContext #445

Merged
merged 3 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('ChartPlugin', () => {
const buildQuery = () => ({
datasource: { id: 1, type: DatasourceType.Table },
queries: [{ granularity: 'day' }],
force: false,
});

const controlPanel = { abc: 1 };
Expand Down Expand Up @@ -55,7 +56,7 @@ describe('ChartPlugin', () => {
expect(plugin.loadBuildQuery).toBeUndefined();
});
it('uses loadBuildQuery field if specified', () => {
expect.assertions(1);
expect.assertions(2);
const plugin = new ChartPlugin({
metadata,
Chart: FakeChart,
Expand All @@ -64,6 +65,7 @@ describe('ChartPlugin', () => {

const fn = plugin.loadBuildQuery!() as BuildQueryFunction<QueryFormData>;
expect(fn(FORM_DATA).queries[0]).toEqual({ granularity: 'day' });
expect(fn(FORM_DATA).force).toEqual(false);
});
it('uses buildQuery field if specified', () => {
expect.assertions(1);
Expand Down
1 change: 1 addition & 0 deletions packages/superset-ui-query/src/buildQueryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function buildQueryContext(
): QueryContext {
return {
datasource: new DatasourceKey(formData.datasource).toObject(),
force: formData.force || false,
queries: buildQuery(buildQueryObject(formData)),
};
}
15 changes: 10 additions & 5 deletions packages/superset-ui-query/src/types/Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ export type QueryObjectMetric = {

export type QueryObjectExtras = Partial<{
/** HAVING condition for Druid */
having_druid: string;
druid_time_origin: string;
having_druid?: string;
druid_time_origin?: string;
/** HAVING condition for SQLAlchemy */
having: string;
time_grain_sqla: string;
having?: string;
relative_start?: string;
relative_end?: string;
time_grain_sqla?: string;
time_range_endpoints?: string[];
/** WHERE condition */
where: string;
where?: string;
}>;

export type QueryObject = {
Expand Down Expand Up @@ -77,5 +80,7 @@ export interface QueryContext {
id: number;
type: DatasourceType;
};
/** Force refresh of all queries */
force: boolean;
queries: QueryObject[];
}
2 changes: 2 additions & 0 deletions packages/superset-ui-query/src/types/QueryFormData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export type BaseFormData = {
row_limit?: string | number | null;
/** The metric used to order timeseries for limiting */
timeseries_limit_metric?: QueryFormDataMetric;
/** Force refresh */
force?: boolean;
} & TimeRange &
QueryFormDataMetrics;

Expand Down
7 changes: 5 additions & 2 deletions packages/superset-ui-query/test/buildQueryContext.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import { buildQueryContext } from '../src';

describe('buildQueryContext', () => {
it('should build datasource for table sources', () => {
it('should build datasource for table sources and default force to false', () => {
const queryContext = buildQueryContext({
datasource: '5__table',
granularity_sqla: 'ds',
viz_type: 'table',
});
expect(queryContext.datasource.id).toBe(5);
expect(queryContext.datasource.type).toBe('table');
expect(queryContext.force).toBe(false);
});

it('should build datasource for druid sources', () => {
it('should build datasource for druid sources and set force to true', () => {
const queryContext = buildQueryContext({
datasource: '5__druid',
granularity: 'ds',
viz_type: 'table',
force: true,
});
expect(queryContext.datasource.id).toBe(5);
expect(queryContext.datasource.type).toBe('druid');
expect(queryContext.force).toBe(true);
});
});