[9.0] [Discover Session] Fix "Untitled" export title when exporting CSV on a dashboard (#210143) (#216849)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Discover Session] Fix "Untitled" export title when exporting CSV on
a dashboard (#210143)](https://github.com/elastic/kibana/pull/210143)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Matthias
Wilhelm","email":"matthias.wilhelm@elastic.co"},"sourceCommit":{"committedDate":"2025-02-12T16:24:43Z","message":"[Discover
Session] Fix \"Untitled\" export title when exporting CSV on a dashboard
(#210143)\n\n- Fixes \"Untitled\" CSV exports when an export of a
Discover session CSV is triggered on a Dashboard\n- Switches to make use
of the embeddable title when exporting CSV of Discover session
embeddables on a
Dashboard.","sha":"7a72b14fd5a032f6bcf5ad5d68f84d7e092a23c8","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Discover","release_note:fix","Team:DataDiscovery","backport:prev-major","v8.18.0","v9.1.0","v8.19.0","v8.17.3","v8.16.5"],"title":"[Discover
Session] Fix \"Untitled\" export title when exporting CSV on a
dashboard","number":210143,"url":"https://github.com/elastic/kibana/pull/210143","mergeCommit":{"message":"[Discover
Session] Fix \"Untitled\" export title when exporting CSV on a dashboard
(#210143)\n\n- Fixes \"Untitled\" CSV exports when an export of a
Discover session CSV is triggered on a Dashboard\n- Switches to make use
of the embeddable title when exporting CSV of Discover session
embeddables on a
Dashboard.","sha":"7a72b14fd5a032f6bcf5ad5d68f84d7e092a23c8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/210882","number":210882,"state":"MERGED","mergeCommit":{"sha":"daf2be3efe6458e03e9cb08cedab95c41fbc2129","message":"[8.18]
[Discover Session] Fix &quot;Untitled&quot; export title when exporting
CSV on a dashboard (#210143) (#210882)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.18`:\n- [[Discover
Session] Fix &quot;Untitled&quot; export title when\nexporting CSV on a
dashboard\n(#210143)](https://github.com/elastic/kibana/pull/210143)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by:
Matthias Wilhelm
<matthias.wilhelm@elastic.co>"}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/210143","number":210143,"mergeCommit":{"message":"[Discover
Session] Fix \"Untitled\" export title when exporting CSV on a dashboard
(#210143)\n\n- Fixes \"Untitled\" CSV exports when an export of a
Discover session CSV is triggered on a Dashboard\n- Switches to make use
of the embeddable title when exporting CSV of Discover session
embeddables on a
Dashboard.","sha":"7a72b14fd5a032f6bcf5ad5d68f84d7e092a23c8"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/210883","number":210883,"state":"MERGED","mergeCommit":{"sha":"2dc7b4f7d9f549907ca21e7d3cf79155d8d71b82","message":"[8.x]
[Discover Session] Fix &quot;Untitled&quot; export title when exporting
CSV on a dashboard (#210143) (#210883)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.x`:\n- [[Discover
Session] Fix &quot;Untitled&quot; export title when\nexporting CSV on a
dashboard\n(#210143)](https://github.com/elastic/kibana/pull/210143)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by:
Matthias Wilhelm
<matthias.wilhelm@elastic.co>"}},{"branch":"8.17","label":"v8.17.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/210881","number":210881,"state":"MERGED","mergeCommit":{"sha":"bf94e613b9cca71d7071101b5444b6e461ffc20f","message":"[8.17]
[Discover Session] Fix &quot;Untitled&quot; export title when exporting
CSV on a dashboard (#210143) (#210881)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.17`:\n- [[Discover
Session] Fix &quot;Untitled&quot; export title when\nexporting CSV on a
dashboard\n(#210143)](https://github.com/elastic/kibana/pull/210143)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\n---------\n\nCo-authored-by:
Matthias Wilhelm
<matthias.wilhelm@elastic.co>"}},{"branch":"8.16","label":"v8.16.5","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/210880","number":210880,"state":"MERGED","mergeCommit":{"sha":"90c24f5dd1bf2979e46f5fc2f0e88f40d1f3a3d3","message":"[8.16]
[Discover Session] Fix &quot;Untitled&quot; export title when exporting
CSV on a dashboard (#210143) (#210880)\n\n# Backport\n\nThis will
backport the following commits from `main` to `8.16`:\n- [[Discover
Session] Fix &quot;Untitled&quot; export title when\nexporting CSV on a
dashboard\n(#210143)](https://github.com/elastic/kibana/pull/210143)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\n---------\n\nCo-authored-by:
Matthias Wilhelm <matthias.wilhelm@elastic.co>\nCo-authored-by: Elastic
Machine <elasticmachine@users.noreply.github.com>"}}]}] BACKPORT-->

Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
This commit is contained in:
Julia Rechkunova 2025-04-02 18:40:22 +02:00 committed by GitHub
parent b43b00920c
commit 6956c54738
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 8 deletions

View file

@ -93,7 +93,6 @@ describe('GetCsvReportPanelAction', () => {
embeddable: {
type: 'search',
savedSearch$: new BehaviorSubject({ searchSource: mockSearchSource }),
getTitle: () => `The Dude`,
getInspectorAdapters: () => null,
getInput: () => ({
viewMode: 'list',
@ -103,6 +102,8 @@ describe('GetCsvReportPanelAction', () => {
},
}),
hasTimeRange: () => true,
title$: new BehaviorSubject('embeddable title'),
hideTitle$: new BehaviorSubject(false),
parentApi: {
viewMode$: new BehaviorSubject('view'),
},
@ -131,7 +132,7 @@ describe('GetCsvReportPanelAction', () => {
columns: [],
objectType: 'search',
searchSource: {},
title: '',
title: 'embeddable title',
version: '7.15.0',
});
});
@ -165,7 +166,7 @@ describe('GetCsvReportPanelAction', () => {
columns: ['column_a', 'column_b'],
objectType: 'search',
searchSource: { testData: 'testDataValue' },
title: '',
title: 'embeddable title',
version: '7.15.0',
});
});
@ -183,7 +184,7 @@ describe('GetCsvReportPanelAction', () => {
await panel.execute(context);
expect(core.http.post).toHaveBeenCalledWith('/internal/reporting/generate/csv_searchsource', {
body: '{"jobParams":"(columns:!(),objectType:search,searchSource:(),title:\'\',version:\'7.15.0\')"}',
body: '{"jobParams":"(columns:!(),objectType:search,searchSource:(),title:\'embeddable title\',version:\'7.15.0\')"}',
method: 'POST',
});
});

View file

@ -30,10 +30,12 @@ import {
apiCanAccessViewMode,
apiHasType,
apiIsOfType,
apiPublishesTitle,
CanAccessViewMode,
EmbeddableApiContext,
getInheritedViewMode,
HasType,
PublishesTitle,
} from '@kbn/presentation-publishing';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { CSV_REPORTING_ACTION, JobAppParamsCSV } from '@kbn/reporting-export-types-csv-common';
@ -43,7 +45,6 @@ import { IncompatibleActionError } from '@kbn/ui-actions-plugin/public';
import type { ClientConfigType } from '@kbn/reporting-public/types';
import { checkLicense } from '@kbn/reporting-public/license_check';
import type { ReportingAPIClient } from '@kbn/reporting-public/reporting_api_client';
import { getI18nStrings } from './strings';
export interface PanelActionDependencies {
@ -82,7 +83,11 @@ interface ExecutionParams {
i18nStart: I18nStart;
}
type GetCsvActionApi = HasType & PublishesSavedSearch & CanAccessViewMode & HasTimeRange;
type GetCsvActionApi = HasType &
PublishesSavedSearch &
CanAccessViewMode &
HasTimeRange &
PublishesTitle;
const compatibilityCheck = (api: EmbeddableApiContext['embeddable']): api is GetCsvActionApi => {
return (
@ -90,7 +95,8 @@ const compatibilityCheck = (api: EmbeddableApiContext['embeddable']): api is Get
apiIsOfType(api, SEARCH_EMBEDDABLE_TYPE) &&
apiPublishesSavedSearch(api) &&
apiCanAccessViewMode(api) &&
Boolean((api as unknown as HasTimeRange).hasTimeRange)
Boolean((api as unknown as HasTimeRange).hasTimeRange) &&
apiPublishesTitle(api)
);
};
@ -196,7 +202,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
addGlobalTimeFilter: !embeddable.hasTimeRange(),
absoluteTime: true,
});
const title = savedSearch.title || '';
const title = embeddable.title$.getValue() ?? '';
const executionParams = { searchSource, columns, title, savedSearch, i18nStart, analytics };
return this.executeGenerate(executionParams);