Skip to content
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

[Dashboard Usability] Filters in new tabs #194877

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
removeSearchSessionIdFromURL,
} from './url/search_sessions_integration';
import { loadAndRemoveDashboardState, startSyncingExpandedPanelState } from './url/url_utils';
import { getDashboardBackupService } from '../services/dashboard_backup_service';

export interface DashboardAppProps {
history: History;
Expand Down Expand Up @@ -122,6 +123,7 @@ export function DashboardApp({
const getInitialInput = () => {
const stateFromLocator = loadDashboardHistoryLocationState(getScopedHistory);
const initialUrlState = loadAndRemoveDashboardState(kbnUrlStateStorage);
const filters = getDashboardBackupService().getFilters();

// Override all state with URL + Locator input
return {
Expand All @@ -134,6 +136,7 @@ export function DashboardApp({
screenshotModeService.getScreenshotContext('layout') === 'print'
? { viewMode: ViewMode.PRINT }
: {}),
filters,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ export const backupServiceStrings = {
defaultMessage: 'Error encountered while backing up view mode: {message}',
values: { message },
}),
filtersStorageError: (message: string) =>
i18n.translate('dashboard.filtersBackup.error', {
defaultMessage: 'Error encountered while backing up filters: {message}',
values: { message },
}),
getPanelsGetError: (message: string) =>
i18n.translate('dashboard.panelStorageError.getError', {
defaultMessage: 'Error encountered while fetching unsaved changes: {message}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ViewMode } from '@kbn/embeddable-plugin/public';
import { Storage } from '@kbn/kibana-utils-plugin/public';
import { set } from '@kbn/safer-lodash-set';

import { Filter } from '@kbn/es-query';
import type { DashboardContainerInput } from '../../common';
import { backupServiceStrings } from '../dashboard_container/_dashboard_container_strings';
import { UnsavedPanelState } from '../dashboard_container/types';
Expand All @@ -24,6 +25,7 @@ export const DASHBOARD_PANELS_UNSAVED_ID = 'unsavedDashboard';
export const PANELS_CONTROL_GROUP_KEY = 'controlGroup';
const DASHBOARD_PANELS_SESSION_KEY = 'dashboardPanels';
const DASHBOARD_VIEWMODE_LOCAL_KEY = 'dashboardViewMode';
export const DASHBOARD_FILTERS_LOCAL_KEY = 'dashboardFilters';

// this key is named `panels` for BWC reasons, but actually contains the entire dashboard state
const DASHBOARD_STATE_SESSION_KEY = 'dashboardStateManagerPanels';
Expand Down Expand Up @@ -81,6 +83,21 @@ class DashboardBackupService implements DashboardBackupServiceType {
}
};

public getFilters = (): Filter[] => {
return this.localStorage.get(DASHBOARD_FILTERS_LOCAL_KEY);
};

public storeFilters = (filters: Filter[]) => {
try {
this.localStorage.set(DASHBOARD_FILTERS_LOCAL_KEY, filters);
} catch (e) {
coreServices.notifications.toasts.addDanger({
title: backupServiceStrings.filtersStorageError(e.message),
'data-test-subj': 'dashboardFiltersBackupFailure',
});
}
};

public clearState(id = DASHBOARD_PANELS_UNSAVED_ID) {
try {
const dashboardStateStorage =
Expand Down Expand Up @@ -117,7 +134,9 @@ class DashboardBackupService implements DashboardBackupServiceType {
id
] as UnsavedPanelState | undefined;

return { dashboardState, panels };
const filters = dashboardState?.filters;

return { dashboardState, panels, filters };
} catch (e) {
coreServices.notifications.toasts.addDanger({
title: backupServiceStrings.getPanelsGetError(e.message),
Expand All @@ -135,6 +154,7 @@ class DashboardBackupService implements DashboardBackupServiceType {
const dashboardStateStorage = this.sessionStorage.get(DASHBOARD_STATE_SESSION_KEY) ?? {};
set(dashboardStateStorage, [this.activeSpaceId, id], newState);
this.sessionStorage.set(DASHBOARD_STATE_SESSION_KEY, dashboardStateStorage);
this.storeFilters(dashboardStateStorage[this.activeSpaceId][id]?.filters ?? []);

const panelsStorage = this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY) ?? {};
set(panelsStorage, [this.activeSpaceId, id], unsavedPanels);
Expand Down