Skip to content

Commit

Permalink
[8.16] [Discover Session] Fix "Untitled" export title when …
Browse files Browse the repository at this point in the history
…exporting CSV on a dashboard (#210143) (#210880)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[Discover Session] Fix "Untitled" export title when
exporting CSV on a dashboard
(#210143)](#210143)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Matthias
Wilhelm","email":"[email protected]"},"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","v9.1.0"],"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":"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"}}]}]
BACKPORT-->

---------

Co-authored-by: Matthias Wilhelm <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
3 people authored Feb 25, 2025
1 parent a0dc29b commit 90c24f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ describe('GetCsvReportPanelAction', () => {
embeddable: {
type: 'search',
savedSearch$: new BehaviorSubject({ searchSource: mockSearchSource }),
getTitle: () => `The Dude`,
getInspectorAdapters: () => null,
getInput: () => ({
viewMode: 'list',
Expand All @@ -104,6 +103,8 @@ describe('GetCsvReportPanelAction', () => {
},
}),
hasTimeRange: () => true,
panelTitle: new BehaviorSubject('embeddable title'),
hidePanelTitle: new BehaviorSubject(false),
parentApi: {
viewMode: new BehaviorSubject('view'),
},
Expand Down Expand Up @@ -133,7 +134,7 @@ describe('GetCsvReportPanelAction', () => {
columns: [],
objectType: 'search',
searchSource: {},
title: '',
title: 'embeddable title',
version: '7.15.0',
});
});
Expand Down Expand Up @@ -168,7 +169,7 @@ describe('GetCsvReportPanelAction', () => {
columns: ['column_a', 'column_b'],
objectType: 'search',
searchSource: { testData: 'testDataValue' },
title: '',
title: 'embeddable title',
version: '7.15.0',
});
});
Expand All @@ -187,7 +188,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',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ import {
apiCanAccessViewMode,
apiHasType,
apiIsOfType,
apiPublishesPanelTitle,
CanAccessViewMode,
EmbeddableApiContext,
getInheritedViewMode,
HasType,
PublishesPanelTitle,
} from '@kbn/presentation-publishing';
import { toMountPoint } from '@kbn/react-kibana-mount';
import { CSV_REPORTING_ACTION, JobAppParamsCSV } from '@kbn/reporting-export-types-csv-common';
Expand All @@ -44,7 +46,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 {
Expand Down Expand Up @@ -83,15 +84,20 @@ interface ExecutionParams {
i18nStart: I18nStart;
}

type GetCsvActionApi = HasType & PublishesSavedSearch & CanAccessViewMode & HasTimeRange;
type GetCsvActionApi = HasType &
PublishesSavedSearch &
CanAccessViewMode &
HasTimeRange &
PublishesPanelTitle;

const compatibilityCheck = (api: EmbeddableApiContext['embeddable']): api is GetCsvActionApi => {
return (
apiHasType(api) &&
apiIsOfType(api, SEARCH_EMBEDDABLE_TYPE) &&
apiPublishesSavedSearch(api) &&
apiCanAccessViewMode(api) &&
Boolean((api as unknown as HasTimeRange).hasTimeRange)
Boolean((api as unknown as HasTimeRange).hasTimeRange) &&
apiPublishesPanelTitle(api)
);
};

Expand Down Expand Up @@ -275,7 +281,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
addGlobalTimeFilter: !embeddable.hasTimeRange(),
absoluteTime: true,
});
const title = savedSearch.title || '';
const title = embeddable.panelTitle.getValue() ?? '';
const executionParams = { searchSource, columns, title, savedSearch, i18nStart, analytics };

if (this.enablePanelActionDownload) {
Expand Down

0 comments on commit 90c24f5

Please sign in to comment.