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

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

Merged
merged 8 commits into from
Feb 12, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ describe('GetCsvReportPanelAction', () => {
embeddable: {
type: 'search',
savedSearch$: new BehaviorSubject({ searchSource: mockSearchSource }),
getTitle: () => `The Dude`,
getInspectorAdapters: () => null,
getInput: () => ({
viewMode: 'list',
Expand All @@ -103,6 +102,7 @@ describe('GetCsvReportPanelAction', () => {
},
}),
hasTimeRange: () => true,
title$: new BehaviorSubject('embeddable title'),
parentApi: {
viewMode$: new BehaviorSubject('view'),
},
Expand Down Expand Up @@ -131,7 +131,7 @@ describe('GetCsvReportPanelAction', () => {
columns: [],
objectType: 'search',
searchSource: {},
title: '',
title: 'embeddable title',
version: '7.15.0',
});
});
Expand Down Expand Up @@ -165,7 +165,7 @@ describe('GetCsvReportPanelAction', () => {
columns: ['column_a', 'column_b'],
objectType: 'search',
searchSource: { testData: 'testDataValue' },
title: '',
title: 'embeddable title',
version: '7.15.0',
});
});
Expand All @@ -183,7 +183,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 @@ -34,6 +34,7 @@ import {
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';
Expand All @@ -43,7 +44,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 @@ -82,15 +82,20 @@ 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 (
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) &&
Boolean((api as unknown as PublishesTitle).title$)
);
};

Expand Down Expand Up @@ -196,7 +201,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);
Expand Down