mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Explore: Allow users to save Explore queries to dashboards (#47083)
* Select: Expose AsyncSelectProps interface * DashboardPicker: Add a generic DashboardPicker component * Dashboard Service: improve types * Explore: allow saving explore state in a new panel in an existing dashboard * Handle saving provisioned dashboards error * Improve test coverage * simplify test setup * Strip base path from url when redirecting to a dashboard * Keep existing variables when saving to an existing dashboard * group assertions in test * SearchCard: handle undefined in meta.updated * Change required error message * Add to dashboard alternative * Add to existing is working * Add to dashboard form * remove default add-panel when creating a dashboard from explore * types cleanup * remove unneeded BE change * simplify selector * Add explore2Dashboard feature toggle * add tests * Small refactor & add tests * small DashboardPicker improvements * use partial from lodash * Better error handling * improve tests & disable button when there are no queries * rename addPanelToDashboard function * remove localStorage item if opening tab fails * UI touchups & tracking * Fix tests & remove close reporting * remove echologger debug * fix adding a panel to an existing dashboard * Enable explore2Dashboard by default and add docs * Ensure each panel in dashboards has a valid ID * force CI restart Co-authored-by: Elfo404 <me@giordanoricci.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import { config, locationService } from '@grafana/runtime';
|
||||
import { createDashboardQueryRunner } from '../../query/state/DashboardQueryRunner/DashboardQueryRunner';
|
||||
import { getIfExistsLastKey } from '../../variables/state/selectors';
|
||||
import { toStateKey } from 'app/features/variables/utils';
|
||||
import store from 'app/core/store';
|
||||
|
||||
export interface InitDashboardArgs {
|
||||
urlUid?: string;
|
||||
@@ -34,6 +35,13 @@ async function fetchDashboard(
|
||||
dispatch: ThunkDispatch,
|
||||
getState: () => StoreState
|
||||
): Promise<DashboardDTO | null> {
|
||||
// When creating new or adding panels to a dashboard from explore we load it from local storage
|
||||
const model = store.getObject<DashboardDTO>(DASHBOARD_FROM_LS_KEY);
|
||||
if (model) {
|
||||
removeDashboardToFetchFromLocalStorage();
|
||||
return model;
|
||||
}
|
||||
|
||||
try {
|
||||
switch (args.routeName) {
|
||||
case DashboardRoutes.Home: {
|
||||
@@ -200,7 +208,7 @@ export function initDashboard(args: InitDashboardArgs): ThunkResult<void> {
|
||||
};
|
||||
}
|
||||
|
||||
function getNewDashboardModelData(urlFolderId?: string | null): any {
|
||||
export function getNewDashboardModelData(urlFolderId?: string | null): any {
|
||||
const data = {
|
||||
meta: {
|
||||
canStar: false,
|
||||
@@ -226,3 +234,13 @@ function getNewDashboardModelData(urlFolderId?: string | null): any {
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
const DASHBOARD_FROM_LS_KEY = 'DASHBOARD_FROM_LS_KEY';
|
||||
|
||||
export function setDashboardToFetchFromLocalStorage(model: DashboardDTO) {
|
||||
store.setObject(DASHBOARD_FROM_LS_KEY, model);
|
||||
}
|
||||
|
||||
export function removeDashboardToFetchFromLocalStorage() {
|
||||
store.delete(DASHBOARD_FROM_LS_KEY);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user