-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
Add png report as panel action #26476
Closed
bgaddis56
wants to merge
5
commits into
elastic:master
from
bgaddis56:add-PNG-report-as-panel-action
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
fbbd8fa
WIP Initial changes for PNG as panel action
bgaddis56 09bd4e4
Fixed dup panel action menus and added code for adding app state to URL
bgaddis56 e732e6e
Changes to handle moment timeranges and added customizations to URL
bgaddis56 713d59c
Moved report link generation into embeddable
bgaddis56 17756db
changes for csv exports
bgaddis56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,12 +17,14 @@ | |
* under the License. | ||
*/ | ||
|
||
import url from 'url'; | ||
import angular from 'angular'; | ||
import { Embeddable } from 'ui/embeddable'; | ||
import searchTemplate from './search_template.html'; | ||
import * as columnActions from 'ui/doc_table/actions/columns'; | ||
import { getTime } from 'ui/timefilter/get_time'; | ||
import { RequestAdapter } from 'ui/inspector/adapters'; | ||
import rison from 'rison-node'; | ||
|
||
export class SearchEmbeddable extends Embeddable { | ||
constructor({ onEmbeddableStateChanged, savedSearch, editUrl, loader, $rootScope, $compile }) { | ||
|
@@ -58,6 +60,32 @@ export class SearchEmbeddable extends Embeddable { | |
}; | ||
} | ||
|
||
/** | ||
* Generates an access URL that will be used in creating a PNG report. | ||
*/ | ||
generateAccessLink(containerState) { | ||
|
||
const id = this.savedSearch.id; | ||
|
||
const appState = rison.encode({ filters: containerState.filters, | ||
uiState: containerState.embeddableCustomization, | ||
query: containerState.query, | ||
}); | ||
|
||
const globalState = rison.encode({ time: containerState.timeRange }); | ||
|
||
// Use a url service to ensure everything is escaped properly | ||
const myurl = `/app/kibana#` + url.format({ | ||
pathname: '/visualize/edit/' + id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn't work, the url for saved searches I think is Tests should probably be added as part of this PR too, so if the url format changes, the ci will fail. |
||
query: { | ||
'_g': globalState, | ||
'_a': appState, | ||
} | ||
}); | ||
|
||
return myurl.toString(); | ||
} | ||
|
||
pushContainerStateParamsToScope() { | ||
// If there is column or sort data on the panel, that means the original columns or sort settings have | ||
// been overridden in a dashboard. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
x-pack/plugins/reporting/public/panel_actions/get_csv_report_panel_action.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import rison from 'rison-node'; | ||
import { | ||
ContainerState, | ||
ContextMenuAction, | ||
ContextMenuActionsRegistryProvider, | ||
Embeddable, | ||
} from 'ui/embeddable'; | ||
import { kfetch } from 'ui/kfetch'; | ||
import { toastNotifications } from 'ui/notify'; | ||
import { SearchEmbeddable } from '../../../../../src/core_plugins/kibana/public/discover/embeddable/search_embeddable'; | ||
import { jobCompletionNotifications } from '../lib/job_completion_notifications'; | ||
|
||
class GetCsvReportPanelAction extends ContextMenuAction { | ||
constructor() { | ||
super( | ||
{ | ||
displayName: i18n.translate('kbn.dashboard.panel.reportPanel.displayName', { | ||
defaultMessage: 'CSV Report', | ||
}), | ||
id: 'openReport', | ||
parentPanelId: 'mainMenu', | ||
}, | ||
{ | ||
icon: 'document', | ||
} | ||
); | ||
} | ||
public isVisible({ embeddable }: { embeddable: Embeddable }): boolean { | ||
if (!embeddable) { | ||
return false; | ||
} | ||
if (!(embeddable instanceof SearchEmbeddable)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public async onClick({ | ||
embeddable, | ||
containerState, | ||
closeContextMenu, | ||
}: { | ||
embeddable: Embeddable; | ||
closeContextMenu: any; | ||
containerState: ContainerState; | ||
}) { | ||
if (!embeddable) { | ||
return; | ||
} | ||
if (!(embeddable instanceof SearchEmbeddable)) { | ||
return; | ||
} | ||
const searchEmbeddable = embeddable as SearchEmbeddable; | ||
|
||
if (!searchEmbeddable.savedSearch.id) { | ||
return; | ||
} | ||
|
||
closeContextMenu(); | ||
|
||
const searchURL = searchEmbeddable.generateAccessLink(containerState); | ||
|
||
const reportconfig = { | ||
browserTimezone: 'America/Phoenix', | ||
layout: { | ||
dimensions: { | ||
width: 960, | ||
height: 720, | ||
}, | ||
}, | ||
objectType: 'search', | ||
relativeUrl: searchURL, | ||
title: 'searchEmbeddable.getPanelTitle(containerState)', | ||
}; | ||
|
||
const query = { | ||
jobParams: rison.encode(reportconfig), | ||
}; | ||
|
||
const API_BASE_URL = '/api/reporting/generate'; | ||
|
||
toastNotifications.addSuccess({ | ||
title: `Queued report for ${reportconfig.objectType}`, | ||
text: 'Track its progress in Management', | ||
'data-test-subj': 'queueReportSuccess', | ||
}); | ||
|
||
const resp = await kfetch({ method: 'POST', pathname: `${API_BASE_URL}/csv`, query }); | ||
|
||
jobCompletionNotifications.add(resp.job.id); | ||
} | ||
} | ||
|
||
ContextMenuActionsRegistryProvider.register(() => new GetCsvReportPanelAction()); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mention PNG report in here, this is on the base embeddable layer now, reporting just happens to use it, but it's not really here specifically for reporting (I think it will be useful in other scenarios as well).