mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Make Dashboard Unsaved Changes Space Specific (#92680)
* Made dashboard unsaved changes space specific
This commit is contained in:
parent
8381fdd60e
commit
a21f48a9f2
7 changed files with 52 additions and 27 deletions
|
@ -1389,15 +1389,15 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 89,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L89"
|
||||
"lineNumber": 90,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L90"
|
||||
}
|
||||
}
|
||||
],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 88,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L88"
|
||||
"lineNumber": 89,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L89"
|
||||
},
|
||||
"initialIsOpen": false
|
||||
},
|
||||
|
@ -1939,8 +1939,8 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 86,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L86"
|
||||
"lineNumber": 87,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L87"
|
||||
},
|
||||
"signature": [
|
||||
"UrlGeneratorContract<\"DASHBOARD_APP_URL_GENERATOR\">"
|
||||
|
@ -2103,8 +2103,8 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 118,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L118"
|
||||
"lineNumber": 120,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L120"
|
||||
},
|
||||
"signature": [
|
||||
"void"
|
||||
|
@ -2127,8 +2127,8 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 121,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L121"
|
||||
"lineNumber": 123,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L123"
|
||||
},
|
||||
"signature": [
|
||||
"() => ",
|
||||
|
@ -2149,8 +2149,8 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 122,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L122"
|
||||
"lineNumber": 124,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L124"
|
||||
},
|
||||
"signature": [
|
||||
{
|
||||
|
@ -2171,8 +2171,8 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 123,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L123"
|
||||
"lineNumber": 125,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L125"
|
||||
},
|
||||
"signature": [
|
||||
{
|
||||
|
@ -2192,8 +2192,8 @@
|
|||
"description": [],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 124,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L124"
|
||||
"lineNumber": 126,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L126"
|
||||
},
|
||||
"signature": [
|
||||
"React.FC<Props>"
|
||||
|
@ -2202,8 +2202,8 @@
|
|||
],
|
||||
"source": {
|
||||
"path": "src/plugins/dashboard/public/plugin.tsx",
|
||||
"lineNumber": 120,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L120"
|
||||
"lineNumber": 122,
|
||||
"link": "https://github.com/elastic/kibana/tree/mastersrc/plugins/dashboard/public/plugin.tsx#L122"
|
||||
},
|
||||
"lifecycle": "start",
|
||||
"initialIsOpen": true
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
],
|
||||
"optionalPlugins": [
|
||||
"home",
|
||||
"spacesOss",
|
||||
"savedObjectsTaggingOss",
|
||||
"usageCollection"],
|
||||
"server": true,
|
||||
|
|
|
@ -13,6 +13,7 @@ import { parse, ParsedQuery } from 'query-string';
|
|||
import { render, unmountComponentAtNode } from 'react-dom';
|
||||
import { Switch, Route, RouteComponentProps, HashRouter, Redirect } from 'react-router-dom';
|
||||
|
||||
import { first } from 'rxjs/operators';
|
||||
import { DashboardListing } from './listing';
|
||||
import { DashboardApp } from './dashboard_app';
|
||||
import { addHelpMenuToAppChrome, DashboardPanelStorage } from './lib';
|
||||
|
@ -47,6 +48,7 @@ export const dashboardUrlParams = {
|
|||
export interface DashboardMountProps {
|
||||
appUnMounted: () => void;
|
||||
restorePreviousUrl: () => void;
|
||||
|
||||
scopedHistory: ScopedHistory<unknown>;
|
||||
element: AppMountParameters['element'];
|
||||
initializerContext: PluginInitializerContext;
|
||||
|
@ -80,6 +82,9 @@ export async function mountApp({
|
|||
savedObjectsTaggingOss,
|
||||
} = pluginsStart;
|
||||
|
||||
const spacesApi = pluginsStart.spacesOss?.isSpacesAvailable ? pluginsStart.spacesOss : undefined;
|
||||
const activeSpaceId = spacesApi && (await spacesApi.activeSpace$.pipe(first()).toPromise())?.id;
|
||||
|
||||
const dashboardServices: DashboardAppServices = {
|
||||
navigation,
|
||||
onAppLeave,
|
||||
|
@ -99,7 +104,10 @@ export async function mountApp({
|
|||
indexPatterns: dataStart.indexPatterns,
|
||||
savedQueryService: dataStart.query.savedQueries,
|
||||
savedObjectsClient: coreStart.savedObjects.client,
|
||||
dashboardPanelStorage: new DashboardPanelStorage(core.notifications.toasts),
|
||||
dashboardPanelStorage: new DashboardPanelStorage(
|
||||
core.notifications.toasts,
|
||||
activeSpaceId || 'default'
|
||||
),
|
||||
savedDashboards: dashboardStart.getSavedDashboardLoader(),
|
||||
savedObjectsTagging: savedObjectsTaggingOss?.getTaggingApi(),
|
||||
allowByValueEmbeddables: initializerContext.config.get<DashboardFeatureFlagConfig>()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { set } from '@elastic/safer-lodash-set';
|
||||
import { Storage } from '../../services/kibana_utils';
|
||||
import { NotificationsStart } from '../../services/core';
|
||||
import { panelStorageErrorStrings } from '../../dashboard_strings';
|
||||
|
@ -17,16 +18,17 @@ const DASHBOARD_PANELS_SESSION_KEY = 'dashboardStateManagerPanels';
|
|||
export class DashboardPanelStorage {
|
||||
private sessionStorage: Storage;
|
||||
|
||||
constructor(private toasts: NotificationsStart['toasts']) {
|
||||
constructor(private toasts: NotificationsStart['toasts'], private activeSpaceId: string) {
|
||||
this.sessionStorage = new Storage(sessionStorage);
|
||||
}
|
||||
|
||||
public clearPanels(id = DASHBOARD_PANELS_UNSAVED_ID) {
|
||||
try {
|
||||
const sessionStoragePanels = this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY) || {};
|
||||
if (sessionStoragePanels[id]) {
|
||||
delete sessionStoragePanels[id];
|
||||
this.sessionStorage.set(DASHBOARD_PANELS_SESSION_KEY, sessionStoragePanels);
|
||||
const sessionStorage = this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY);
|
||||
const sessionStorageForSpace = sessionStorage?.[this.activeSpaceId] || {};
|
||||
if (sessionStorageForSpace[id]) {
|
||||
delete sessionStorageForSpace[id];
|
||||
this.sessionStorage.set(DASHBOARD_PANELS_SESSION_KEY, sessionStorage);
|
||||
}
|
||||
} catch (e) {
|
||||
this.toasts.addDanger({
|
||||
|
@ -38,7 +40,7 @@ export class DashboardPanelStorage {
|
|||
|
||||
public getPanels(id = DASHBOARD_PANELS_UNSAVED_ID): SavedDashboardPanel[] | undefined {
|
||||
try {
|
||||
return this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY)?.[id];
|
||||
return this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY)?.[this.activeSpaceId]?.[id];
|
||||
} catch (e) {
|
||||
this.toasts.addDanger({
|
||||
title: panelStorageErrorStrings.getPanelsGetError(e.message),
|
||||
|
@ -50,7 +52,7 @@ export class DashboardPanelStorage {
|
|||
public setPanels(id = DASHBOARD_PANELS_UNSAVED_ID, newPanels: SavedDashboardPanel[]) {
|
||||
try {
|
||||
const sessionStoragePanels = this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY) || {};
|
||||
sessionStoragePanels[id] = newPanels;
|
||||
set(sessionStoragePanels, [this.activeSpaceId, id], newPanels);
|
||||
this.sessionStorage.set(DASHBOARD_PANELS_SESSION_KEY, sessionStoragePanels);
|
||||
} catch (e) {
|
||||
this.toasts.addDanger({
|
||||
|
@ -62,7 +64,9 @@ export class DashboardPanelStorage {
|
|||
|
||||
public getDashboardIdsWithUnsavedChanges() {
|
||||
try {
|
||||
return Object.keys(this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY) || {});
|
||||
return Object.keys(
|
||||
this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY)?.[this.activeSpaceId] || {}
|
||||
);
|
||||
} catch (e) {
|
||||
this.toasts.addDanger({
|
||||
title: panelStorageErrorStrings.getPanelsGetError(e.message),
|
||||
|
|
|
@ -76,6 +76,7 @@ import { UrlGeneratorState } from '../../share/public';
|
|||
import { ExportCSVAction } from './application/actions/export_csv_action';
|
||||
import { dashboardFeatureCatalog } from './dashboard_strings';
|
||||
import { replaceUrlHashQuery } from '../../kibana_utils/public';
|
||||
import { SpacesOssPluginStart } from './services/spaces';
|
||||
|
||||
declare module '../../share/public' {
|
||||
export interface UrlGeneratorStateMapping {
|
||||
|
@ -113,6 +114,7 @@ export interface DashboardStartDependencies {
|
|||
savedObjects: SavedObjectsStart;
|
||||
presentationUtil: PresentationUtilPluginStart;
|
||||
savedObjectsTaggingOss?: SavedObjectTaggingOssPluginStart;
|
||||
spacesOss?: SpacesOssPluginStart;
|
||||
}
|
||||
|
||||
export type DashboardSetup = void;
|
||||
|
|
9
src/plugins/dashboard/public/services/spaces.ts
Normal file
9
src/plugins/dashboard/public/services/spaces.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
export { SpacesOssPluginStart } from '../../../spaces_oss/public';
|
|
@ -31,5 +31,6 @@
|
|||
{ "path": "../saved_objects_tagging_oss/tsconfig.json" },
|
||||
{ "path": "../saved_objects/tsconfig.json" },
|
||||
{ "path": "../ui_actions/tsconfig.json" },
|
||||
{ "path": "../spaces_oss/tsconfig.json" },
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue