Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
[dashboard scoped filters] Add all time related options to filter sco…
Browse files Browse the repository at this point in the history
…pe settings (apache#8636)
  • Loading branch information
Grace Guo authored Nov 25, 2019
1 parent f04b72c commit acf0753
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
5 changes: 4 additions & 1 deletion superset/assets/src/dashboard/util/activeDashboardFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
getDashboardFilterKey,
} from './getDashboardFilterKey';
import { CHART_TYPE } from '../util/componentTypes';
import { DASHBOARD_FILTER_SCOPE_GLOBAL } from '../reducers/dashboardFilters';

let allFilterBoxChartIds = [];
let activeFilters = {};
Expand Down Expand Up @@ -61,7 +62,9 @@ export function getAppliedFilterValues(chartId) {
return appliedFilterValuesByChart[chartId];
}

export function getChartIdsInFilterScope({ filterScope }) {
export function getChartIdsInFilterScope({
filterScope = DASHBOARD_FILTER_SCOPE_GLOBAL,
}) {
function traverse(chartIds = [], component = {}, immuneChartIds = []) {
if (!component) {
return;
Expand Down
44 changes: 40 additions & 4 deletions superset/assets/src/dashboard/util/getFilterConfigsFromFormdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@
*/
/* eslint-disable camelcase */
import {
TIME_FILTER_MAP,
TIME_RANGE,
FILTER_LABELS,
} from '../../visualizations/FilterBox/FilterBox';

export default function getFilterConfigsFromFormdata(form_data = {}) {
const { date_filter, filter_configs = [] } = form_data;
const {
date_filter,
filter_configs = [],
show_druid_time_granularity,
show_druid_time_origin,
show_sqla_time_column,
show_sqla_time_granularity,
} = form_data;
let configs = filter_configs.reduce(
({ columns, labels }, config) => {
const updatedColumns = {
Expand All @@ -44,15 +52,43 @@ export default function getFilterConfigsFromFormdata(form_data = {}) {
);

if (date_filter) {
const updatedColumns = {
let updatedColumns = {
...configs.columns,
[TIME_RANGE]: form_data[TIME_RANGE],
[TIME_FILTER_MAP.time_range]: form_data.time_range,
};
const updatedLabels = {
...configs.labels,
[TIME_RANGE]: FILTER_LABELS[TIME_RANGE],
[TIME_FILTER_MAP.time_range]: FILTER_LABELS[TIME_RANGE],
};

if (show_sqla_time_column) {
updatedColumns = {
...updatedColumns,
[TIME_FILTER_MAP.time_grain_sqla]: form_data.time_grain_sqla,
};
}

if (show_sqla_time_granularity) {
updatedColumns = {
...updatedColumns,
[TIME_FILTER_MAP.granularity_sqla]: form_data.granularity_sqla,
};
}

if (show_druid_time_granularity) {
updatedColumns = {
...updatedColumns,
[TIME_FILTER_MAP.granularity]: form_data.granularity,
};
}

if (show_druid_time_origin) {
updatedColumns = {
...updatedColumns,
[TIME_FILTER_MAP.druid_time_origin]: form_data.druid_time_origin,
};
}

configs = {
...configs,
columns: updatedColumns,
Expand Down
5 changes: 3 additions & 2 deletions superset/assets/src/visualizations/FilterBox/FilterBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ import FilterBadgeIcon from '../../components/FilterBadgeIcon';
import './FilterBox.less';

// maps control names to their key in extra_filters
const TIME_FILTER_MAP = {
export const TIME_FILTER_MAP = {
time_range: '__time_range',
granularity_sqla: '__time_col',
time_grain_sqla: '__time_grain',
druid_time_origin: '__time_origin',
granularity: '__granularity',
};

export const TIME_RANGE = '__time_range';
// a shortcut to a map key, used by many components
export const TIME_RANGE = TIME_FILTER_MAP.time_range;
export const FILTER_LABELS = {
[TIME_RANGE]: 'Time range',
};
Expand Down

0 comments on commit acf0753

Please sign in to comment.