Skip to content

Commit

Permalink
ui config
Browse files Browse the repository at this point in the history
  • Loading branch information
tsullivan committed Apr 16, 2020
1 parent 10ccc0a commit aa330b8
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 58 deletions.
7 changes: 0 additions & 7 deletions x-pack/plugins/reporting/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY =
'xpack.reporting.jobCompletionNotifications';

export const JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG = {
jobCompletionNotifier: {
interval: 10000,
intervalErrorMultiplier: 5,
},
};

// Routes
export const API_BASE_URL = '/api/reporting';
export const API_LIST_URL = `${API_BASE_URL}/jobs`;
Expand Down
12 changes: 0 additions & 12 deletions x-pack/plugins/reporting/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

import {
CoreSetup,
CoreStart,
HttpSetup,
Plugin,
PluginInitializerContext,
NotificationsStart,
} from '../../../src/core/public';

export type JobId = string;
export type JobStatus =
| 'completed'
Expand All @@ -21,9 +12,6 @@ export type JobStatus =
| 'processing'
| 'failed';

export type HttpService = HttpSetup;
export type NotificationsService = NotificationsStart;

export interface SourceJob {
_id: JobId;
_source: {
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/reporting/public/components/report_listing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { get } from 'lodash';
import moment from 'moment';
import { Component, Fragment, default as React } from 'react';
import { Component, default as React, Fragment } from 'react';
import { Subscription } from 'rxjs';
import { ApplicationStart, ToastsSetup } from 'src/core/public';
import { ILicense, LicensingPluginSetup } from '../../../licensing/public';
import { Poller } from '../../common/poller';
import { JobStatuses, JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG } from '../../constants';
import { JobStatuses } from '../../constants';
import { checkLicense } from '../lib/license_check';
import { JobQueueEntry, ReportingAPIClient } from '../lib/reporting_api_client';
import { ClientConfigType } from '../plugin';
import {
ReportDeleteButton,
ReportDownloadButton,
Expand Down Expand Up @@ -53,6 +54,7 @@ export interface Props {
intl: InjectedIntl;
apiClient: ReportingAPIClient;
license$: LicensingPluginSetup['license$'];
pollConfig: ClientConfigType['poll'];
redirect: ApplicationStart['navigateToApp'];
toasts: ToastsSetup;
}
Expand Down Expand Up @@ -167,12 +169,10 @@ class ReportListingUi extends Component<Props, State> {
functionToPoll: () => {
return this.fetchJobs();
},
pollFrequencyInMillis:
JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG.jobCompletionNotifier.interval,
pollFrequencyInMillis: this.props.pollConfig.jobsRefresh.interval,
trailing: false,
continuePollingOnError: true,
pollFrequencyErrorMultiplier:
JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG.jobCompletionNotifier.intervalErrorMultiplier,
pollFrequencyErrorMultiplier: this.props.pollConfig.jobsRefresh.intervalErrorMultiplier,
});
this.poller.start();
this.licenseSubscription = this.props.license$.subscribe(this.licenseHandler);
Expand Down
78 changes: 45 additions & 33 deletions x-pack/plugins/reporting/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,57 @@
* you may not use this file except in compliance with the Elastic License.
*/

import * as Rx from 'rxjs';
import { i18n } from '@kbn/i18n';
import { I18nProvider } from '@kbn/i18n/react';
import React from 'react';
import ReactDOM from 'react-dom';
import * as Rx from 'rxjs';
import { catchError, filter, map, mergeMap, takeUntil } from 'rxjs/operators';
import { i18n } from '@kbn/i18n';
import {
CoreSetup,
CoreStart,
NotificationsSetup,
Plugin,
PluginInitializerContext,
} from 'src/core/public';
import { ManagementSetup } from 'src/plugins/management/public';
import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from 'src/core/public';
import { I18nProvider } from '@kbn/i18n/react';
import { UiActionsSetup } from 'src/plugins/ui_actions/public';

import { ReportListing } from './components/report_listing';
import { getGeneralErrorToast } from './components';

import { ReportingNotifierStreamHandler as StreamHandler } from './lib/stream_handler';
import { ReportingAPIClient } from './lib/reporting_api_client';
import { GetCsvReportPanelAction } from './panel_actions/get_csv_panel_action';
import { csvReportingProvider } from './share_context_menu/register_csv_reporting';
import { reportingPDFPNGProvider } from './share_context_menu/register_pdf_png_reporting';

import { LicensingPluginSetup } from '../../licensing/public';
import { JobId, JobStatusBuckets } from '../';
import { CONTEXT_MENU_TRIGGER } from '../../../../src/plugins/embeddable/public';
import { SharePluginSetup } from '../../../../src/plugins/share/public';

import {
FeatureCatalogueCategory,
HomePublicPluginSetup,
} from '../../../../src/plugins/home/public';
import { SharePluginSetup } from '../../../../src/plugins/share/public';
import { ReportingConfigType } from '../../../legacy/plugins/reporting/server/config';
import { LicensingPluginSetup } from '../../licensing/public';
import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../constants';
import { getGeneralErrorToast } from './components';
import { ReportListing } from './components/report_listing';
import { ReportingAPIClient } from './lib/reporting_api_client';
import { ReportingNotifierStreamHandler as StreamHandler } from './lib/stream_handler';
import { GetCsvReportPanelAction } from './panel_actions/get_csv_panel_action';
import { csvReportingProvider } from './share_context_menu/register_csv_reporting';
import { reportingPDFPNGProvider } from './share_context_menu/register_pdf_png_reporting';

import {
JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG,
JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY,
} from '../constants';

import { JobId, JobStatusBuckets, NotificationsService } from '..';
export interface ClientConfigType {
poll: ReportingConfigType['poll'];
}

const {
jobCompletionNotifier: { interval: JOBS_REFRESH_INTERVAL },
} = JOB_COMPLETION_NOTIFICATIONS_POLLER_CONFIG;
interface PluginsSetup {
config: ClientConfigType;
}
interface PluginsStart {
config: ClientConfigType;
}

function getStored(): JobId[] {
const sessionValue = sessionStorage.getItem(JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY);
return sessionValue ? JSON.parse(sessionValue) : [];
}

function handleError(
notifications: NotificationsService,
notifications: NotificationsSetup,
err: Error
): Rx.Observable<JobStatusBuckets> {
notifications.toasts.addDanger(
Expand All @@ -64,18 +69,19 @@ function handleError(
return Rx.of({ completed: [], failed: [] });
}

export class ReportingPublicPlugin implements Plugin<any, any> {
private readonly stop$ = new Rx.ReplaySubject(1);

export class ReportingPublicPlugin implements Plugin<PluginsSetup, PluginsStart> {
private config: ClientConfigType;
private readonly title = i18n.translate('xpack.reporting.management.reportingTitle', {
defaultMessage: 'Reporting',
});

private readonly breadcrumbText = i18n.translate('xpack.reporting.breadcrumb', {
defaultMessage: 'Reporting',
});
private readonly stop$ = new Rx.ReplaySubject(1);

constructor(initializerContext: PluginInitializerContext) {}
constructor(initializerContext: PluginInitializerContext) {
this.config = initializerContext.config.get<ClientConfigType>();
}

public setup(
core: CoreSetup,
Expand Down Expand Up @@ -130,6 +136,7 @@ export class ReportingPublicPlugin implements Plugin<any, any> {
<ReportListing
toasts={toasts}
license$={license$}
pollConfig={this.config.poll}
redirect={start.application.navigateToApp}
apiClient={apiClient}
/>
Expand All @@ -155,6 +162,8 @@ export class ReportingPublicPlugin implements Plugin<any, any> {
uiSettings,
})
);

return { config: this.config };
}

// FIXME: only perform these actions for authenticated routes
Expand All @@ -163,8 +172,9 @@ export class ReportingPublicPlugin implements Plugin<any, any> {
const { http, notifications } = core;
const apiClient = new ReportingAPIClient(http);
const streamHandler = new StreamHandler(notifications, apiClient);
const jobRefreshInterval = this.config.poll.jobsRefresh.interval;

Rx.timer(0, JOBS_REFRESH_INTERVAL)
Rx.timer(0, jobRefreshInterval)
.pipe(
takeUntil(this.stop$), // stop the interval when stop method is called
map(() => getStored()), // read all pending job IDs from session storage
Expand All @@ -174,6 +184,8 @@ export class ReportingPublicPlugin implements Plugin<any, any> {
catchError(err => handleError(notifications, err))
)
.subscribe();

return { config: this.config };
}

public stop() {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/server/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ConfigSchema, ConfigType } from './schema';
export { createConfig$ } from './create_config';

export const config: PluginConfigDescriptor<ConfigType> = {
exposeToBrowser: { poll: true },
schema: ConfigSchema,
deprecations: ({ unused }) => [
unused('capture.browser.chromium.maxScreenshotDimension'),
Expand Down

0 comments on commit aa330b8

Please sign in to comment.