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

[Reporting/Discover/Search Sessions] Only use relative time filter when generating share data #112588

Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ export const getTopNavLinks = ({
const sharingData = await getSharingData(
searchSource,
state.appStateContainer.getState(),
services.uiSettings
indexPattern,
services
);

services.share.toggleShareContextMenu({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
* Side Public License, v 1.
*/

import type { Capabilities, IUiSettingsClient } from 'kibana/public';
import { ISearchSource } from '../../../../../../data/common';
import type { Capabilities } from 'kibana/public';
import type { IndexPattern, ISearchSource } from 'src/plugins/data/common';
import { DOC_HIDE_TIME_COLUMN_SETTING, SORT_DEFAULT_ORDER_SETTING } from '../../../../../common';
import type { DiscoverServices } from '../../../../build_services';
import type { SavedSearch, SortOrder } from '../../../../saved_searches/types';
import { getSortForSearchSource } from '../components/doc_table';
import { AppState } from '../services/discover_state';
Expand All @@ -19,15 +20,22 @@ import { AppState } from '../services/discover_state';
export async function getSharingData(
currentSearchSource: ISearchSource,
state: AppState | SavedSearch,
config: IUiSettingsClient
indexPattern: IndexPattern,
services: DiscoverServices
) {
const { uiSettings: config, data } = services;
const searchSource = currentSearchSource.createCopy();
const index = searchSource.getField('index')!;

searchSource.setField(
'sort',
getSortForSearchSource(state.sort as SortOrder[], index, config.get(SORT_DEFAULT_ORDER_SETTING))
);
// When sharing externally we preserve relative time values
searchSource.setField(
'filter',
data.query.timefilter.timefilter.createRelativeFilter(indexPattern)
);
searchSource.removeField('highlight');
searchSource.removeField('highlightAll');
searchSource.removeField('aggs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ export function updateSearchSource(

// this is not the default index pattern, it determines that it's not of type rollup
if (indexPatternsUtils.isDefault(indexPattern)) {
searchSource.setField(
'filter',
data.query.timefilter.timefilter.createRelativeFilter(indexPattern)
);
// Set the date range filter fields from timeFilter using the absolute format. Search sessions requires that it be converted from a relative range
searchSource.setField('filter', data.query.timefilter.timefilter.createFilter(indexPattern));
jloleysens marked this conversation as resolved.
Show resolved Hide resolved
}

if (useNewFieldsApi) {
Expand Down