From d85786290257fc6d5f1c47d9b071fddf417789d3 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Wed, 21 Apr 2021 14:08:20 +0300 Subject: [PATCH] feat(native-filters): make fetch predicate optional --- .../src/filters/components/Range/buildQuery.ts | 11 +++++++---- .../src/filters/components/Range/controlPanel.ts | 13 +++++++++++++ .../src/filters/components/Range/types.ts | 7 +++++-- .../src/filters/components/Select/buildQuery.ts | 7 +++++-- .../src/filters/components/Select/controlPanel.ts | 13 +++++++++++++ .../src/filters/components/Select/types.ts | 6 ++++-- 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/superset-frontend/src/filters/components/Range/buildQuery.ts b/superset-frontend/src/filters/components/Range/buildQuery.ts index d0ed52454ed61..f5901affa6fa0 100644 --- a/superset-frontend/src/filters/components/Range/buildQuery.ts +++ b/superset-frontend/src/filters/components/Range/buildQuery.ts @@ -19,8 +19,8 @@ import { buildQueryContext, ColumnType, - QueryFormData, } from '@superset-ui/core'; +import { DEFAULT_FORM_DATA, PluginFilterRangeQueryFormData } from './types'; /** * The buildQuery function is used to create an instance of QueryContext that's @@ -36,14 +36,17 @@ import { * it is possible to define post processing operations in the QueryObject, or multiple queries * if a viz needs multiple different result sets. */ -export default function buildQuery(formData: QueryFormData) { - const { groupby } = formData; +export default function buildQuery(formData: PluginFilterRangeQueryFormData) { + const { groupby, applyFetchValuesPredicate } = { + ...DEFAULT_FORM_DATA, + ...formData, + }; const [column = ''] = groupby || []; // @ts-ignore (need update interface Column ) return buildQueryContext(formData, baseQueryObject => [ { ...baseQueryObject, - apply_fetch_values_predicate: true, + apply_fetch_values_predicate: applyFetchValuesPredicate, columns: [], groupby: [], metrics: [ diff --git a/superset-frontend/src/filters/components/Range/controlPanel.ts b/superset-frontend/src/filters/components/Range/controlPanel.ts index 8f9501d7a5077..82ed97882d1e1 100644 --- a/superset-frontend/src/filters/components/Range/controlPanel.ts +++ b/superset-frontend/src/filters/components/Range/controlPanel.ts @@ -22,6 +22,7 @@ import { sections, sharedControls, } from '@superset-ui/chart-controls'; +import { DEFAULT_FORM_DATA } from './types'; const config: ControlPanelConfig = { controlPanelSections: [ @@ -41,6 +42,18 @@ const config: ControlPanelConfig = { }, }, ], + [ + { + name: 'applyFetchValuesPredicate', + config: { + type: 'CheckboxControl', + renderTrigger: true, + label: t('Apply dataset filter predicate'), + default: DEFAULT_FORM_DATA.apply_fetch_values_predicate, + description: t('Apply filter predicate if defined in dataset'), + }, + }, + ], ], }, ], diff --git a/superset-frontend/src/filters/components/Range/types.ts b/superset-frontend/src/filters/components/Range/types.ts index 38e445a9dd85c..4810600b8d84a 100644 --- a/superset-frontend/src/filters/components/Range/types.ts +++ b/superset-frontend/src/filters/components/Range/types.ts @@ -27,8 +27,7 @@ import { RefObject } from 'react'; import { PluginFilterStylesProps } from '../types'; interface PluginFilterSelectCustomizeProps { - max?: number; - min?: number; + applyFetchValuesPredicate: boolean; } export type PluginFilterRangeQueryFormData = QueryFormData & @@ -43,3 +42,7 @@ export type PluginFilterRangeProps = PluginFilterStylesProps & { behaviors: Behavior[]; inputRef: RefObject; }; + +export const DEFAULT_FORM_DATA = { + apply_fetch_values_predicate: true, +}; diff --git a/superset-frontend/src/filters/components/Select/buildQuery.ts b/superset-frontend/src/filters/components/Select/buildQuery.ts index 27fe3fa6eb155..19f2fd0ae6a23 100644 --- a/superset-frontend/src/filters/components/Select/buildQuery.ts +++ b/superset-frontend/src/filters/components/Select/buildQuery.ts @@ -20,7 +20,10 @@ import { buildQueryContext } from '@superset-ui/core'; import { DEFAULT_FORM_DATA, PluginFilterSelectQueryFormData } from './types'; export default function buildQuery(formData: PluginFilterSelectQueryFormData) { - const { sortAscending, sortMetric } = { ...DEFAULT_FORM_DATA, ...formData }; + const { applyFetchValuesPredicate, sortAscending, sortMetric } = { + ...DEFAULT_FORM_DATA, + ...formData, + }; return buildQueryContext(formData, baseQueryObject => { const { columns = [], filters = [] } = baseQueryObject; @@ -28,7 +31,7 @@ export default function buildQuery(formData: PluginFilterSelectQueryFormData) { return [ { ...baseQueryObject, - apply_fetch_values_predicate: true, + apply_fetch_values_predicate: applyFetchValuesPredicate, groupby: columns, filters: filters.concat( columns.map(column => ({ col: column, op: 'IS NOT NULL' })), diff --git a/superset-frontend/src/filters/components/Select/controlPanel.ts b/superset-frontend/src/filters/components/Select/controlPanel.ts index 1fad9305b6c8a..d36f198d64a67 100644 --- a/superset-frontend/src/filters/components/Select/controlPanel.ts +++ b/superset-frontend/src/filters/components/Select/controlPanel.ts @@ -26,6 +26,7 @@ const { multiSelect, defaultToFirstItem, sortAscending, + applyFetchValuesPredicate, } = DEFAULT_FORM_DATA; const config: ControlPanelConfig = { @@ -109,6 +110,18 @@ const config: ControlPanelConfig = { }, }, ], + [ + { + name: 'applyFetchValuesPredicate', + config: { + type: 'CheckboxControl', + renderTrigger: true, + label: t('Apply dataset filter predicate'), + default: applyFetchValuesPredicate, + description: t('Apply filter predicate if defined in dataset'), + }, + }, + ], ], }, ], diff --git a/superset-frontend/src/filters/components/Select/types.ts b/superset-frontend/src/filters/components/Select/types.ts index 834a02468c1e5..b3e2d766deede 100644 --- a/superset-frontend/src/filters/components/Select/types.ts +++ b/superset-frontend/src/filters/components/Select/types.ts @@ -34,12 +34,13 @@ export const FIRST_VALUE = '__FIRST_VALUE__'; export type SelectValue = (number | string)[] | null; interface PluginFilterSelectCustomizeProps { + applyFetchValuesPredicate: boolean; + defaultToFirstItem: boolean; defaultValue?: SelectValue | typeof FIRST_VALUE; enableEmptyFilter: boolean; + inputRef?: RefObject; inverseSelection: boolean; multiSelect: boolean; - defaultToFirstItem: boolean; - inputRef?: RefObject; sortAscending: boolean; sortMetric?: string; } @@ -69,4 +70,5 @@ export const DEFAULT_FORM_DATA: PluginFilterSelectCustomizeProps = { defaultToFirstItem: false, multiSelect: true, sortAscending: true, + applyFetchValuesPredicate: true, };