Skip to content

Commit

Permalink
[Tests] Share Modal Redesign clean up and tests (#180406)
Browse files Browse the repository at this point in the history
## Summary

This PR makes the share redesign modal work the primary share context
paradigm (excluding Canvas) by removing the share plugin config that had
share.new_version.enabled for testing and implementation.
This PR cleans up the FTRs. 

Closes [#151523](#151523)
As a result of defaulting to short urls, some tests were removed since
they are now obsolete.
One fix in this PR to avoid customer known issues is to allow reporting
(if license is permitted) for watcher users. Refer to
elastic/sdh-kibana#4481 (comment).

I've opened a separate issue to track any skipped or deleted tests as a
result of short urls by default here
#181066

### Checklist

- [x]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))


### Release Note

The share menu is updated for a more streamlined user experience. Users
can navigate through a tabbed modal to copy links for discover,
dashboard, and lens.

---------

Co-authored-by: Eyo Okon Eyo <eyo.eyo@elastic.co>
Co-authored-by: Marco Liberati <dej611@users.noreply.github.com>
  • Loading branch information
3 people authored May 15, 2024
1 parent 5da2bb8 commit dc1fd5a
Show file tree
Hide file tree
Showing 68 changed files with 2,075 additions and 3,698 deletions.
22 changes: 20 additions & 2 deletions packages/kbn-reporting/public/reporting_api_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { BaseParams, JobId, ManagementLinkFn, ReportApiJSON } from '@kbn/reporti
import rison from '@kbn/rison';
import moment from 'moment';
import { stringify } from 'query-string';
import { ReactElement } from 'react';
import { Job } from '.';
import { jobCompletionNotifications } from './job_completion_notifications';

Expand All @@ -41,7 +42,10 @@ interface IReportingAPI {
// Helpers
getReportURL(jobId: string): string;
getReportingPublicJobPath<T>(exportType: string, jobParams: BaseParams & T): string; // Return a URL to queue a job, with the job params encoded in the query string of the URL. Used for copying POST URL
createReportingJob<T>(exportType: string, jobParams: BaseParams & T): Promise<Job | undefined>; // Sends a request to queue a job, with the job params in the POST body
createReportingJob<T>(
exportType: string,
jobParams: BaseParams & T
): Promise<Job | undefined | ReactElement>; // Sends a request to queue a job, with the job params in the POST body
getServerBasePath(): string; // Provides the raw server basePath to allow it to be stripped out from relativeUrls in job params

// CRUD
Expand Down Expand Up @@ -172,6 +176,20 @@ export class ReportingAPIClient implements IReportingAPI {
return `${this.http.basePath.prepend(PUBLIC_ROUTES.GENERATE_PREFIX)}/${exportType}?${params}`;
}

public async createReportingShareJob(exportType: string, jobParams: BaseParams) {
const jobParamsRison = rison.encode(jobParams);
const resp: { job?: ReportApiJSON } | undefined = await this.http.post(
`${INTERNAL_ROUTES.GENERATE_PREFIX}/${exportType}`,
{
method: 'POST',
body: JSON.stringify({ jobParams: jobParamsRison }),
}
);
if (resp?.job) {
this.addPendingJobId(resp.job.id);
return new Job(resp.job);
}
}
/**
* Calls the internal API to generate a report job on-demand
*/
Expand All @@ -192,7 +210,7 @@ export class ReportingAPIClient implements IReportingAPI {
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
throw new Error('invalid response!');
throw new Error(`${err.body?.message}`);
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/kbn-reporting/public/share/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
* Side Public License, v 1.
*/

export { getSharedComponents } from './shared';
export { reportingExportModalProvider } from './share_context_menu/register_pdf_png_modal_reporting';
export { reportingScreenshotShareProvider } from './share_context_menu/register_pdf_png_reporting';
export { reportingCsvShareProvider } from './share_context_menu/register_csv_reporting';
export { reportingCsvShareProvider as reportingCsvShareModalProvider } from './share_context_menu/register_csv_modal_reporting';
export type { ReportingPublicComponents } from './shared/get_shared_components';
export type { JobParamsProviderOptions, StartServices } from './share_context_menu';
export { getSharedComponents } from './shared';
export type { ReportingPublicComponents } from './shared';
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ export interface ReportingSharingData {

export interface JobParamsProviderOptions {
sharingData: ReportingSharingData;
shareableUrl: string;
shareableUrl?: string;
objectType: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const reportingCsvShareProvider = ({
const generateReportingJobCSV = ({ intl }: { intl: InjectedIntl }) => {
const decoratedJobParams = apiClient.getDecoratedJobParams(getJobParams());
return apiClient
.createReportingJob(reportType, decoratedJobParams)
.createReportingShareJob(reportType, decoratedJobParams)
.then(() => firstValueFrom(startServices$))
.then(([startServices]) => {
toasts.addSuccess({
Expand Down Expand Up @@ -122,7 +122,10 @@ export const reportingCsvShareProvider = ({
id: 'reporting.share.modalContent.notification.reportingErrorTitle',
defaultMessage: 'Unable to create report',
}),
toastMessage: error.body?.message,
toastMessage: (
// eslint-disable-next-line react/no-danger
<span dangerouslySetInnerHTML={{ __html: error.body?.message }} />
) as unknown as string,
});
});
};
Expand Down Expand Up @@ -154,7 +157,7 @@ export const reportingCsvShareProvider = ({
helpText: (
<FormattedMessage
id="reporting.share.csv.reporting.helpTextCSV"
defaultMessage="Export a CSV of this {objectType}"
defaultMessage="Export a CSV of this {objectType}."
values={{ objectType }}
/>
),
Expand All @@ -165,14 +168,14 @@ export const reportingCsvShareProvider = ({
dataTestSubj: 'shareReportingCopyURL',
label: 'Post URL',
},
generateReportButton: (
generateExportButton: (
<FormattedMessage
id="reporting.share.generateButtonLabelCSV"
data-test-subj="generateReportButton"
defaultMessage="Generate CSV"
/>
),
generateReport: generateReportingJobCSV,
generateExport: generateReportingJobCSV,
generateCopyUrl: reportingUrl,
absoluteUrl,
renderCopyURLButton: true,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,13 @@ export const reportingExportModalProvider = ({
};

const generateReportPNG = ({ intl }: { intl: InjectedIntl }) => {
const el = document.querySelector('[data-shared-items-container]');
const { height, width } = el ? el.getBoundingClientRect() : { height: 768, width: 1024 };
const dimensions = { height, width };

const { layout: outerLayout } = getJobParams(jobProviderOptions, 'pngV2')();
let dimensions = outerLayout?.dimensions;
if (!dimensions) {
const el = document.querySelector('[data-shared-items-container]');
const { height, width } = el ? el.getBoundingClientRect() : { height: 768, width: 1024 };
dimensions = { height, width };
}
const decoratedJobParams = apiClient.getDecoratedJobParams({
...getJobParams(jobProviderOptions, 'pngV2')(),
layout: { id: 'preserve_layout', dimensions },
Expand Down Expand Up @@ -393,20 +396,19 @@ export const reportingExportModalProvider = ({
['data-test-subj']: 'imageExports',
},
label: 'PDF' as const,
generateReport: generateReportPDF,
generateExport: generateReportPDF,
reportType: 'printablePdfV2',
requiresSavedState,
helpText: (
<FormattedMessage
id="reporting.printablePdfV2.helpText"
defaultMessage="Exports can take a few minutes to generate."
defaultMessage="Select the file type you would like to export for this visualization."
/>
),
generateReportButton: (
generateExportButton: (
<FormattedMessage
id="reporting.printablePdfV2.generateButtonLabel"
data-test-subj="generateReportButton"
defaultMessage="Generate export"
defaultMessage="Export file"
/>
),
layoutOption: objectType === 'dashboard' ? ('print' as const) : undefined,
Expand All @@ -425,21 +427,17 @@ export const reportingExportModalProvider = ({
['data-test-subj']: 'imageExports',
},
label: 'PNG' as const,
generateReport: generateReportPNG,
generateExport: generateReportPNG,
reportType: 'pngV2',
requiresSavedState,
helpText: (
<FormattedMessage
id="reporting.pngV2.helpText"
defaultMessage="Exports can take a few minutes to generate."
defaultMessage="Select the file type you would like to export for this visualization."
/>
),
generateReportButton: (
<FormattedMessage
id="reporting.pngV2.generateButtonLabel"
defaultMessage="Generate export"
data-test-subj="generateReportButton"
/>
generateExportButton: (
<FormattedMessage id="reporting.pngV2.generateButtonLabel" defaultMessage="Export file" />
),
layoutOption: objectType === 'dashboard' ? ('print' as const) : undefined,
renderCopyURLButton: true,
Expand Down
Loading

0 comments on commit dc1fd5a

Please sign in to comment.