Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(native-filters): make fetch predicate optional #14264

Closed
Closed
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
11 changes: 7 additions & 4 deletions superset-frontend/src/filters/components/Range/buildQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: [
Expand Down
13 changes: 13 additions & 0 deletions superset-frontend/src/filters/components/Range/controlPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
sections,
sharedControls,
} from '@superset-ui/chart-controls';
import { DEFAULT_FORM_DATA } from './types';

const config: ControlPanelConfig = {
controlPanelSections: [
Expand All @@ -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'),
},
},
],
],
},
],
Expand Down
7 changes: 5 additions & 2 deletions superset-frontend/src/filters/components/Range/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ import { RefObject } from 'react';
import { PluginFilterStylesProps } from '../types';

interface PluginFilterSelectCustomizeProps {
max?: number;
min?: number;
applyFetchValuesPredicate: boolean;
}

export type PluginFilterRangeQueryFormData = QueryFormData &
Expand All @@ -43,3 +42,7 @@ export type PluginFilterRangeProps = PluginFilterStylesProps & {
behaviors: Behavior[];
inputRef: RefObject<any>;
};

export const DEFAULT_FORM_DATA = {
apply_fetch_values_predicate: true,
};
7 changes: 5 additions & 2 deletions superset-frontend/src/filters/components/Select/buildQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ 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;

const sortColumns = sortMetric ? [sortMetric] : columns;
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' })),
Expand Down
13 changes: 13 additions & 0 deletions superset-frontend/src/filters/components/Select/controlPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
multiSelect,
defaultToFirstItem,
sortAscending,
applyFetchValuesPredicate,
} = DEFAULT_FORM_DATA;

const config: ControlPanelConfig = {
Expand Down Expand Up @@ -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'),
},
},
],
],
},
],
Expand Down
6 changes: 4 additions & 2 deletions superset-frontend/src/filters/components/Select/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement>;
inverseSelection: boolean;
multiSelect: boolean;
defaultToFirstItem: boolean;
inputRef?: RefObject<HTMLInputElement>;
sortAscending: boolean;
sortMetric?: string;
}
Expand Down Expand Up @@ -69,4 +70,5 @@ export const DEFAULT_FORM_DATA: PluginFilterSelectCustomizeProps = {
defaultToFirstItem: false,
multiSelect: true,
sortAscending: true,
applyFetchValuesPredicate: true,
};