Skip to content

Commit

Permalink
Mostly shimmed client, save for a few APIs and routing
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Griffith committed Jan 27, 2020
1 parent e1e0ef3 commit 70947b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export const API_BASE_URL = '/api/reporting'; // "Generation URL" from share men
export const API_BASE_URL_V1 = '/api/reporting/v1'; //
export const API_BASE_GENERATE_V1 = `${API_BASE_URL_V1}/generate`;
export const API_LIST_URL = '/api/reporting/jobs';
export const API_GENERATE_IMMEDIATE = `${API_BASE_URL_V1}/generate/immediate/csv/saved-object`;

export const CONTENT_TYPE_CSV = 'text/csv';
export const CSV_REPORTING_ACTION = 'downloadCsvReport';

export const WHITELISTED_JOB_CONTENT_TYPES = [
'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import dateMath from '@elastic/datemath';
import { i18n } from '@kbn/i18n';
import moment from 'moment-timezone';

import { kfetch } from 'ui/kfetch';
import { toastNotifications } from 'ui/notify';
import chrome from 'ui/chrome';

import { npSetup } from 'ui/new_platform';
import { npSetup, npStart } from 'ui/new_platform';
import { IAction, IncompatibleActionError } from '../../../../../../src/plugins/ui_actions/public';

import {
Expand All @@ -22,11 +18,9 @@ import {
import { SEARCH_EMBEDDABLE_TYPE } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/constants';
import { ISearchEmbeddable } from '../../../../../../src/legacy/core_plugins/kibana/public/discover/np_ready/embeddable/types';

import { API_BASE_URL_V1 } from '../../common/constants';

const API_BASE_URL = `${API_BASE_URL_V1}/generate/immediate/csv/saved-object`;
import { API_GENERATE_IMMEDIATE, CSV_REPORTING_ACTION } from '../../common/constants';

const CSV_REPORTING_ACTION = 'downloadCsvReport';
const { core } = npStart;

function isSavedSearchEmbeddable(
embeddable: IEmbeddable | ISearchEmbeddable
Expand Down Expand Up @@ -71,12 +65,6 @@ class GetCsvReportPanelAction implements IAction<ActionContext> {
}

public isCompatible = async (context: ActionContext) => {
const enablePanelActionDownload = chrome.getInjected('enablePanelActionDownload');

if (!enablePanelActionDownload) {
return false;
}

const { embeddable } = context;

return embeddable.getInput().viewMode !== ViewMode.EDIT && embeddable.type === 'search';
Expand All @@ -100,7 +88,7 @@ class GetCsvReportPanelAction implements IAction<ActionContext> {
const searchEmbeddable = embeddable;
const searchRequestBody = await this.getSearchRequestBody({ searchEmbeddable });
const state = _.pick(searchRequestBody, ['sort', 'docvalue_fields', 'query']);
const kibanaTimezone = chrome.getUiSettingsClient().get('dateFormat:tz');
const kibanaTimezone = core.uiSettings.get('dateFormat:tz');

const id = `search:${embeddable.getSavedSearch().id}`;
const filename = embeddable.getTitle();
Expand All @@ -125,7 +113,7 @@ class GetCsvReportPanelAction implements IAction<ActionContext> {

this.isDownloading = true;

toastNotifications.addSuccess({
core.notifications.toasts.addSuccess({
title: i18n.translate('xpack.reporting.dashboard.csvDownloadStartedTitle', {
defaultMessage: `CSV Download Started`,
}),
Expand All @@ -135,7 +123,8 @@ class GetCsvReportPanelAction implements IAction<ActionContext> {
'data-test-subj': 'csvDownloadStarted',
});

await kfetch({ method: 'POST', pathname: `${API_BASE_URL}/${id}`, body })
await core.http
.post(`${API_GENERATE_IMMEDIATE}/${id}`, { body })
.then((rawResponse: string) => {
this.isDownloading = false;

Expand All @@ -162,7 +151,7 @@ class GetCsvReportPanelAction implements IAction<ActionContext> {

private onGenerationFail(error: Error) {
this.isDownloading = false;
toastNotifications.addDanger({
core.notifications.toasts.addDanger({
title: i18n.translate('xpack.reporting.dashboard.failedCsvDownloadTitle', {
defaultMessage: `CSV download failed`,
}),
Expand All @@ -175,5 +164,6 @@ class GetCsvReportPanelAction implements IAction<ActionContext> {
}

const action = new GetCsvReportPanelAction();

npSetup.plugins.uiActions.registerAction(action);
npSetup.plugins.uiActions.attachAction(CONTEXT_MENU_TRIGGER, action.id);
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import chrome from 'ui/chrome';
import { ScreenCapturePanelContent } from '../components/screen_capture_panel_content';
import { ShareContext } from '../../../../../../src/plugins/share/public';

const { core } = npSetup;

async function reportingProvider() {
const injector = await chrome.dangerouslyGetActiveInjector();
const getShareMenuItems = ({
Expand All @@ -35,12 +37,15 @@ async function reportingProvider() {

const getReportingJobParams = () => {
// Replace hashes with original RISON values.
const relativeUrl = shareableUrl.replace(window.location.origin + chrome.getBasePath(), '');
const relativeUrl = shareableUrl.replace(
window.location.origin + core.http.basePath.get(),
''
);

const browserTimezone =
chrome.getUiSettingsClient().get('dateFormat:tz') === 'Browser'
core.uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
: chrome.getUiSettingsClient().get('dateFormat:tz');
: core.uiSettings.get('dateFormat:tz');

return {
...sharingData,
Expand All @@ -52,12 +57,15 @@ async function reportingProvider() {

const getPngJobParams = () => {
// Replace hashes with original RISON values.
const relativeUrl = shareableUrl.replace(window.location.origin + chrome.getBasePath(), '');
const relativeUrl = shareableUrl.replace(
window.location.origin + core.http.basePath.get(),
''
);

const browserTimezone =
chrome.getUiSettingsClient().get('dateFormat:tz') === 'Browser'
core.uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
: chrome.getUiSettingsClient().get('dateFormat:tz');
: core.uiSettings.get('dateFormat:tz');

return {
...sharingData,
Expand Down

0 comments on commit 70947b3

Please sign in to comment.