Replies: 2 comments 3 replies
-
Yes, in version 4.0.2, you can set the dashboard filter time range values based on the date range sent via the dashboard URL as a query parameter. The function Here is the relevant part of the code: const mergeFilterBoxToFormData = (
exploreFormData: QueryFormData,
dashboardFormData: JsonObject,
) => {
const dateColumns = {
__time_range: 'time_range',
__time_col: 'granularity_sqla',
__time_grain: 'time_grain_sqla',
__granularity: 'granularity',
};
const appliedTimeExtras = {};
const filterBoxData: JsonObject = {};
ensureIsArray(dashboardFormData.extra_filters).forEach(filter => {
if (dateColumns[filter.col]) {
if (filter.val !== NO_TIME_RANGE) {
filterBoxData[dateColumns[filter.col]] = filter.val;
appliedTimeExtras[filter.col] = filter.val;
}
} else {
const adhocFilter = simpleFilterToAdhoc({
...(filter as QueryObjectFilterClause),
isExtra: true,
});
filterBoxData.adhoc_filters = [
...ensureIsArray(filterBoxData.adhoc_filters),
adhocFilter,
];
}
});
filterBoxData.applied_time_extras = appliedTimeExtras;
return filterBoxData;
};
const mergeNativeFiltersToFormData = (
exploreFormData: QueryFormData,
dashboardFormData: JsonObject,
) => {
const nativeFiltersData: JsonObject = {};
const extraFormData = dashboardFormData.extra_form_data || {};
Object.entries(EXTRA_FORM_DATA_OVERRIDE_REGULAR_MAPPINGS).forEach(
([srcKey, targetKey]) => {
const val = extraFormData[srcKey];
if (isDefined(val)) {
nativeFiltersData[targetKey] = val;
}
},
);
if ('time_grain_sqla' in extraFormData) {
nativeFiltersData.time_grain_sqla = extraFormData.time_grain_sqla;
}
if ('granularity_sqla' in extraFormData) {
nativeFiltersData.granularity_sqla = extraFormData.granularity_sqla;
}
const extras = dashboardFormData.extras || {};
EXTRA_FORM_DATA_OVERRIDE_EXTRA_KEYS.forEach(key => {
const val = extraFormData[key];
if (isDefined(val)) {
extras[key] = val;
}
});
if (Object.keys(extras).length) {
nativeFiltersData.extras = extras;
}
nativeFiltersData.adhoc_filters = ensureIsArray(
extraFormData.adhoc_filters,
).map(filter => ({
...filter,
isExtra: true,
}));
const appendFilters = ensureIsArray(extraFormData.filters).map(extraFilter =>
simpleFilterToAdhoc({ ...extraFilter, isExtra: true }),
);
Object.keys(exploreFormData).forEach(key => {
if (key.match(/adhoc_filter.*/)) {
nativeFiltersData[key] = [
...ensureIsArray(nativeFiltersData[key]),
...appendFilters,
];
}
});
return nativeFiltersData;
};
export const getFormDataWithDashboardContext = (
exploreFormData: QueryFormData,
dashboardContextFormData: JsonObject,
) => {
const filterBoxData = mergeFilterBoxToFormData(
exploreFormData,
dashboardContextFormData,
);
const nativeFiltersData = mergeNativeFiltersToFormData(
exploreFormData,
dashboardContextFormData,
);
const adhocFilters = [
...Object.keys(exploreFormData),
...Object.keys(filterBoxData),
...Object.keys(nativeFiltersData),
]
.filter(key => key.match(/adhoc_filter.*/))
.reduce(
(acc, key) => ({
...acc,
[key]: removeExtraFieldForNewCharts(
applyTimeRangeFilters(
dashboardContextFormData,
removeAdhocFilterDuplicates([
...ensureIsArray(exploreFormData[key]),
...ensureIsArray(filterBoxData[key]),
...ensureIsArray(nativeFiltersData[key]),
]),
),
exploreFormData.slice_id === 0,
),
}),
{},
);
return {
...exploreFormData,
...dashboardContextFormData,
...filterBoxData,
...nativeFiltersData,
...adhocFilters,
};
}; This code snippet shows that the |
Beta Was this translation helpful? Give feedback.
-
i am able to get the __time_range value in dataset using url_param('__time_range'). but in UI Date filter not setting that value. it shows default value only. |
Beta Was this translation helpful? Give feedback.
-
Hi All
I m using 4.0.2. I have requirement to set the dashboard filter time range values based on the date range sent via dashboard url as a query parameter. Is there any way to set the date range based on the query parameter
Beta Was this translation helpful? Give feedback.
All reactions