[Discover/Reporting] Fix potential time drift with relative time when requesting a report (#114274)
* updated Discover getSharingData to accept flag for absolute time * update snapshots * simplify fallback title * more appropriate title? * remove old translations * implement PR feedback Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
b5771c81ba
commit
a0d36e7a69
|
@ -7,7 +7,6 @@
|
|||
*/
|
||||
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import moment from 'moment';
|
||||
import type { IndexPattern, ISearchSource } from 'src/plugins/data/common';
|
||||
import { showOpenSearchPanel } from './show_open_search_panel';
|
||||
import { getSharingData, showPublicUrlSwitch } from '../../utils/get_sharing_data';
|
||||
|
@ -128,8 +127,7 @@ export const getTopNavLinks = ({
|
|||
title:
|
||||
savedSearch.title ||
|
||||
i18n.translate('discover.localMenu.fallbackReportTitle', {
|
||||
defaultMessage: 'Discover search [{date}]',
|
||||
values: { date: moment().toISOString(true) },
|
||||
defaultMessage: 'Untitled discover search',
|
||||
}),
|
||||
},
|
||||
isDirty: !savedSearch.id || state.isAppStateDirty(),
|
||||
|
|
|
@ -41,14 +41,7 @@ describe('getSharingData', () => {
|
|||
expect(result).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"columns": Array [],
|
||||
"searchSource": Object {
|
||||
"index": "the-index-pattern-id",
|
||||
"sort": Array [
|
||||
Object {
|
||||
"_score": "desc",
|
||||
},
|
||||
],
|
||||
},
|
||||
"getSearchSource": [Function],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
@ -66,14 +59,7 @@ describe('getSharingData', () => {
|
|||
"column_a",
|
||||
"column_b",
|
||||
],
|
||||
"searchSource": Object {
|
||||
"index": "the-index-pattern-id",
|
||||
"sort": Array [
|
||||
Object {
|
||||
"_score": "desc",
|
||||
},
|
||||
],
|
||||
},
|
||||
"getSearchSource": [Function],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
@ -108,14 +94,7 @@ describe('getSharingData', () => {
|
|||
"cool-field-5",
|
||||
"cool-field-6",
|
||||
],
|
||||
"searchSource": Object {
|
||||
"index": "the-index-pattern-id",
|
||||
"sort": Array [
|
||||
Object {
|
||||
"_doc": "desc",
|
||||
},
|
||||
],
|
||||
},
|
||||
"getSearchSource": [Function],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
@ -158,14 +137,7 @@ describe('getSharingData', () => {
|
|||
"cool-field-5",
|
||||
"cool-field-6",
|
||||
],
|
||||
"searchSource": Object {
|
||||
"index": "the-index-pattern-id",
|
||||
"sort": Array [
|
||||
Object {
|
||||
"_doc": false,
|
||||
},
|
||||
],
|
||||
},
|
||||
"getSearchSource": [Function],
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
import type { Capabilities } from 'kibana/public';
|
||||
import type { IUiSettingsClient } from 'src/core/public';
|
||||
import type { DataPublicPluginStart } from 'src/plugins/data/public';
|
||||
import type { ISearchSource } from 'src/plugins/data/common';
|
||||
import type { ISearchSource, SearchSourceFields } from 'src/plugins/data/common';
|
||||
import { DOC_HIDE_TIME_COLUMN_SETTING, SORT_DEFAULT_ORDER_SETTING } from '../../../../../common';
|
||||
import type { SavedSearch, SortOrder } from '../../../../saved_searches/types';
|
||||
import { getSortForSearchSource } from '../components/doc_table';
|
||||
|
@ -31,8 +31,8 @@ export async function getSharingData(
|
|||
'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(index));
|
||||
|
||||
searchSource.removeField('filter');
|
||||
searchSource.removeField('highlight');
|
||||
searchSource.removeField('highlightAll');
|
||||
searchSource.removeField('aggs');
|
||||
|
@ -54,7 +54,15 @@ export async function getSharingData(
|
|||
}
|
||||
|
||||
return {
|
||||
searchSource: searchSource.getSerializedFields(true),
|
||||
getSearchSource: (absoluteTime?: boolean): SearchSourceFields => {
|
||||
const filter = absoluteTime
|
||||
? data.query.timefilter.timefilter.createFilter(index)
|
||||
: data.query.timefilter.timefilter.createRelativeFilter(index);
|
||||
|
||||
searchSource.setField('filter', filter);
|
||||
|
||||
return searchSource.getSerializedFields(true);
|
||||
},
|
||||
columns,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -117,10 +117,10 @@ export class ReportingCsvPanelAction implements ActionDefinition<ActionContext>
|
|||
}
|
||||
|
||||
const savedSearch = embeddable.getSavedSearch();
|
||||
const { columns, searchSource } = await this.getSearchSource(savedSearch, embeddable);
|
||||
const { columns, getSearchSource } = await this.getSearchSource(savedSearch, embeddable);
|
||||
|
||||
const immediateJobParams = this.apiClient.getDecoratedJobParams({
|
||||
searchSource,
|
||||
searchSource: getSearchSource(true),
|
||||
columns,
|
||||
title: savedSearch.title,
|
||||
objectType: 'downloadCsv', // FIXME: added for typescript, but immediate download job does not need objectType
|
||||
|
|
|
@ -48,14 +48,23 @@ export const ReportingCsvShareProvider = ({
|
|||
return [];
|
||||
}
|
||||
|
||||
const getSearchSource = sharingData.getSearchSource as (
|
||||
absoluteTime?: boolean
|
||||
) => SearchSourceFields;
|
||||
|
||||
const jobParams = {
|
||||
title: sharingData.title as string,
|
||||
objectType,
|
||||
searchSource: sharingData.searchSource as SearchSourceFields,
|
||||
columns: sharingData.columns as string[] | undefined,
|
||||
};
|
||||
|
||||
const getJobParams = () => jobParams;
|
||||
const getJobParams = (forShareUrl?: boolean) => {
|
||||
const absoluteTime = !forShareUrl;
|
||||
return {
|
||||
...jobParams,
|
||||
searchSource: getSearchSource(absoluteTime),
|
||||
};
|
||||
};
|
||||
|
||||
const shareActions = [];
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ export interface ReportingPanelProps {
|
|||
requiresSavedState: boolean; // Whether the report to be generated requires saved state that is not captured in the URL submitted to the report generator.
|
||||
layoutId?: string;
|
||||
objectId?: string;
|
||||
getJobParams: () => Omit<BaseParams, 'browserTimezone' | 'version'>;
|
||||
getJobParams: (forShareUrl?: boolean) => Omit<BaseParams, 'browserTimezone' | 'version'>;
|
||||
options?: ReactElement | null;
|
||||
isDirty?: boolean;
|
||||
onClose?: () => void;
|
||||
|
@ -75,7 +75,7 @@ class ReportingPanelContentUi extends Component<Props, State> {
|
|||
private getAbsoluteReportGenerationUrl = (props: Props) => {
|
||||
const relativePath = this.props.apiClient.getReportingJobPath(
|
||||
props.reportType,
|
||||
this.props.apiClient.getDecoratedJobParams(this.props.getJobParams())
|
||||
this.props.apiClient.getDecoratedJobParams(this.props.getJobParams(true))
|
||||
);
|
||||
return url.resolve(window.location.href, relativePath); // FIXME: '(from: string, to: string): string' is deprecated
|
||||
};
|
||||
|
|
|
@ -2522,7 +2522,6 @@
|
|||
"discover.loadingDocuments": "ドキュメントを読み込み中",
|
||||
"discover.loadingJSON": "JSONを読み込んでいます",
|
||||
"discover.loadingResults": "結果を読み込み中",
|
||||
"discover.localMenu.fallbackReportTitle": "Discover検索[{date}]",
|
||||
"discover.localMenu.inspectTitle": "検査",
|
||||
"discover.localMenu.localMenu.newSearchTitle": "新規",
|
||||
"discover.localMenu.localMenu.optionsTitle": "オプション",
|
||||
|
|
|
@ -2548,7 +2548,6 @@
|
|||
"discover.loadingDocuments": "正在加载文档",
|
||||
"discover.loadingJSON": "正在加载 JSON",
|
||||
"discover.loadingResults": "正在加载结果",
|
||||
"discover.localMenu.fallbackReportTitle": "Discover 搜索 [{date}]",
|
||||
"discover.localMenu.inspectTitle": "检查",
|
||||
"discover.localMenu.localMenu.newSearchTitle": "新建",
|
||||
"discover.localMenu.localMenu.optionsTitle": "选项",
|
||||
|
|
Loading…
Reference in a new issue