[Reporting] Relax save requirement for CSV reports (#99313)

* update requirement to save csv report in ui

* update expectation that CSV reporting is disabled for new discover searches

* update test expectations (again)

* refactor to using props-driven approach

* provide a fallback title

* refine title a bit more

* added component level test

* return ISO string with offset

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2021-05-12 10:32:51 +02:00 committed by GitHub
parent 07ed7161ad
commit c22d9fd690
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 79 additions and 7 deletions

View file

@ -7,6 +7,7 @@
*/
import { i18n } from '@kbn/i18n';
import moment from 'moment';
import { showOpenSearchPanel } from './show_open_search_panel';
import { getSharingData, showPublicUrlSwitch } from '../../helpers/get_sharing_data';
import { unhashUrl } from '../../../../../kibana_utils/public';
@ -122,7 +123,13 @@ export const getTopNavLinks = ({
objectType: 'search',
sharingData: {
...sharingData,
title: savedSearch.title,
// CSV reports can be generated without a saved search so we provide a fallback title
title:
savedSearch.title ||
i18n.translate('discover.localMenu.fallbackReportTitle', {
defaultMessage: 'Discover search [{date}]',
values: { date: moment().toISOString(true) },
}),
},
isDirty: !savedSearch.id || state.isAppStateDirty(),
showPublicUrlSwitch,

View file

@ -0,0 +1,55 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';
import { mountWithIntl } from '@kbn/test/jest';
import { notificationServiceMock } from 'src/core/public/mocks';
import { ReportingPanelContent, Props } from './reporting_panel_content';
describe('ReportingPanelContent', () => {
const mountComponent = (props: Partial<Props>) =>
mountWithIntl(
<ReportingPanelContent
requiresSavedState
// We have unsaved changes
isDirty={true}
reportType="test"
layoutId="test"
getJobParams={jest.fn().mockReturnValue({})}
objectId={'my-object-id'}
apiClient={{ getReportingJobPath: () => 'test' } as any}
toasts={notificationServiceMock.createSetupContract().toasts}
{...props}
/>
);
describe('saved state', () => {
it('prevents generating reports when saving is required and we have unsaved changes', () => {
const wrapper = mountComponent({
requiresSavedState: true,
isDirty: true,
objectId: undefined,
});
wrapper.update();
expect(wrapper.find('[data-test-subj="generateReportButton"]').last().props().disabled).toBe(
true
);
});
it('allows generating reports when saving is not required', () => {
const wrapper = mountComponent({
requiresSavedState: false,
isDirty: true,
objectId: undefined,
});
wrapper.update();
expect(wrapper.find('[data-test-subj="generateReportButton"]').last().props().disabled).toBe(
false
);
});
});
});

View file

@ -19,6 +19,11 @@ export interface Props {
apiClient: ReportingAPIClient;
toasts: ToastsSetup;
reportType: string;
/**
* Whether the report to be generated requires saved state that is not captured in the URL submitted to the report generator.
*/
requiresSavedState: boolean;
layoutId: string | undefined;
objectId?: string;
getJobParams: () => BaseParams;
@ -85,7 +90,10 @@ class ReportingPanelContentUi extends Component<Props, State> {
}
public render() {
if (this.isNotSaved() || this.props.isDirty || this.state.isStale) {
if (
this.props.requiresSavedState &&
(this.isNotSaved() || this.props.isDirty || this.state.isStale)
) {
return (
<EuiForm className="kbnShareContextMenu__finalPanel" data-test-subj="shareReportingForm">
<EuiFormRow

View file

@ -43,6 +43,7 @@ export class ScreenCapturePanelContent extends Component<Props, State> {
public render() {
return (
<ReportingPanelContent
requiresSavedState
apiClient={this.props.apiClient}
toasts={this.props.toasts}
reportType={this.props.reportType}

View file

@ -107,6 +107,7 @@ export const ReportingCsvShareProvider = ({
title: panelTitle,
content: (
<ReportingPanelContent
requiresSavedState={false}
apiClient={apiClient}
toasts={toasts}
reportType={CSV_JOB_TYPE}

View file

@ -41,9 +41,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
describe('Check Available', () => {
beforeEach(() => PageObjects.common.navigateToApp('discover'));
it('is not available if new', async () => {
it('is available if new', async () => {
await PageObjects.reporting.openCsvReportingPanel();
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be('true');
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be(null);
});
it('becomes available when saved', async () => {
@ -52,11 +52,11 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be(null);
});
it('becomes available/not available when a saved search is created, changed and saved again', async () => {
it('remains available regardless of the saved search state', async () => {
// create new search, csv export is not available
await PageObjects.discover.clickNewSearchButton();
await PageObjects.reporting.openCsvReportingPanel();
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be('true');
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be(null);
// save search, csv export is available
await PageObjects.discover.saveSearch('my search - expectEnabledGenerateReportButton 2');
await PageObjects.reporting.openCsvReportingPanel();
@ -64,7 +64,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// add filter, csv export is not available
await filterBar.addFilter('currency', 'is', 'EUR');
await PageObjects.reporting.openCsvReportingPanel();
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be('true');
expect(await PageObjects.reporting.isGenerateReportButtonDisabled()).to.be(null);
// save search again, csv export is available
await PageObjects.discover.saveSearch('my search - expectEnabledGenerateReportButton 2');
await PageObjects.reporting.openCsvReportingPanel();