Explore: Adds ability to save a panel's query from Explore (#17982)

* Explore: Adds ability to return to origin dashboard
This commit is contained in:
kay delaney
2019-09-05 13:44:37 +01:00
committed by GitHub
parent 991f77cee1
commit a838d2b30a
22 changed files with 404 additions and 87 deletions

View File

@@ -263,14 +263,15 @@ export class BackendSrv implements BackendService {
return this.get(`/api/folders/${uid}`);
}
saveDashboard(dash: DashboardModel, options: any) {
options = options || {};
saveDashboard(
dash: DashboardModel,
{ message = '', folderId, overwrite = false }: { message?: string; folderId?: number; overwrite?: boolean } = {}
) {
return this.post('/api/dashboards/db/', {
dashboard: dash,
folderId: options.folderId,
overwrite: options.overwrite === true,
message: options.message || '',
folderId,
overwrite,
message,
});
}

View File

@@ -186,7 +186,6 @@ export class KeybindingSrv {
if (dashboard.meta.focusPanelId) {
appEvents.emit('panel-change-view', {
fullscreen: true,
edit: null,
panelId: dashboard.meta.focusPanelId,
toggle: true,
});
@@ -199,7 +198,7 @@ export class KeybindingSrv {
if (dashboard.meta.focusPanelId) {
const panel = dashboard.getPanelById(dashboard.meta.focusPanelId);
const datasource = await this.datasourceSrv.get(panel.datasource);
const url = await getExploreUrl(panel.targets, datasource, this.datasourceSrv, this.timeSrv);
const url = await getExploreUrl(panel, panel.targets, datasource, this.datasourceSrv, this.timeSrv);
if (url) {
this.$timeout(() => this.$location.url(url));
}

View File

@@ -30,6 +30,7 @@ const DEFAULT_EXPLORE_STATE: ExploreUrlState = {
showingLogs: true,
dedupStrategy: LogsDedupStrategy.none,
},
originPanelId: undefined,
};
describe('state functions', () => {

View File

@@ -18,7 +18,7 @@ import { renderUrl } from 'app/core/utils/url';
import store from 'app/core/store';
import { getNextRefIdChar } from './query';
// Types
import { DataQuery, DataSourceApi, DataQueryError, DataQueryRequest } from '@grafana/ui';
import { DataQuery, DataSourceApi, DataQueryError, DataQueryRequest, PanelModel } from '@grafana/ui';
import {
ExploreUrlState,
HistoryItem,
@@ -29,6 +29,7 @@ import {
} from 'app/types/explore';
import { config } from '../config';
import { PanelQueryState } from '../../features/dashboard/state/PanelQueryState';
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
export const DEFAULT_RANGE = {
from: 'now-1h',
@@ -55,7 +56,13 @@ export const lastUsedDatasourceKeyForOrgId = (orgId: number) => `${LAST_USED_DAT
* @param datasourceSrv Datasource service to query other datasources in case the panel datasource is mixed
* @param timeSrv Time service to get the current dashboard range from
*/
export async function getExploreUrl(panelTargets: any[], panelDatasource: any, datasourceSrv: any, timeSrv: any) {
export async function getExploreUrl(
panel: PanelModel,
panelTargets: DataQuery[],
panelDatasource: any,
datasourceSrv: any,
timeSrv: TimeSrv
) {
let exploreDatasource = panelDatasource;
let exploreTargets: DataQuery[] = panelTargets;
let url: string;
@@ -86,7 +93,7 @@ export async function getExploreUrl(panelTargets: any[], panelDatasource: any, d
};
}
const exploreState = JSON.stringify(state);
const exploreState = JSON.stringify({ ...state, originPanelId: panel.id });
url = renderUrl('/explore', { left: exploreState });
}
return url;
@@ -198,6 +205,7 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
range: DEFAULT_RANGE,
ui: DEFAULT_UI_STATE,
mode: null,
originPanelId: null,
};
if (!parsed) {
@@ -234,7 +242,8 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
}
: DEFAULT_UI_STATE;
return { datasource, queries, range, ui, mode };
const originPanelId = parsedSegments.filter(segment => isSegment(segment, 'originPanelId'))[0];
return { datasource, queries, range, ui, mode, originPanelId };
}
export function serializeStateToUrlParam(urlState: ExploreUrlState, compact?: boolean): string {