Skip to content

Commit 6f4caf8

Browse files
committed
allow null values in session storage backups.
1 parent 88c6c3d commit 6f4caf8

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

examples/embeddable_examples/public/react_embeddables/saved_book/saved_book_react_embeddable.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
const bookSerializedStateIsByReference = (
3636
state?: BookSerializedState
3737
): state is BookByReferenceSerializedState => {
38-
return Boolean(state && (state as BookByReferenceSerializedState).savedBookId !== undefined);
38+
return Boolean(state && (state as BookByReferenceSerializedState).savedBookId);
3939
};
4040

4141
export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
@@ -86,7 +86,7 @@ export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
8686
defaultMessage: 'book',
8787
}),
8888
serializeState: async () => {
89-
if (savedBookId$.value === undefined) {
89+
if (!Boolean(savedBookId$.value)) {
9090
// if this book is currently by value, we serialize the entire state.
9191
const bookByValueState: BookByValueSerializedState = {
9292
attributes: serializeBookAttributes(bookAttributesManager),
@@ -97,7 +97,7 @@ export const getSavedBookEmbeddableFactory = (core: CoreStart) => {
9797

9898
// if this book is currently by reference, we serialize the reference and write to the external store.
9999
const bookByReferenceState: BookByReferenceSerializedState = {
100-
savedBookId: savedBookId$.value,
100+
savedBookId: savedBookId$.value!,
101101
...serializeTitles(),
102102
};
103103

src/plugins/dashboard/public/dashboard_actions/unlink_from_library_action.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class UnlinkFromLibraryAction implements Action<EmbeddableApiContext> {
7777
return api.canUnlinkFromLibrary();
7878
} else if (apiHasInPlaceLibraryTransforms(api)) {
7979
const canUnLink = api.canUnlinkFromLibrary ? await api.canUnlinkFromLibrary() : true;
80-
return canUnLink && api.libraryId$.value !== undefined;
80+
return canUnLink && Boolean(api.libraryId$.value);
8181
}
8282
throw new IncompatibleActionError();
8383
}

src/plugins/dashboard/public/services/dashboard_backup/dashboard_backup_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class DashboardBackupService implements DashboardBackupServiceType {
133133

134134
const panelsStorage = this.sessionStorage.get(DASHBOARD_PANELS_SESSION_KEY) ?? {};
135135
set(panelsStorage, [this.activeSpaceId, id], unsavedPanels);
136-
this.sessionStorage.set(DASHBOARD_PANELS_SESSION_KEY, panelsStorage);
136+
this.sessionStorage.set(DASHBOARD_PANELS_SESSION_KEY, panelsStorage, true);
137137
} catch (e) {
138138
this.notifications.toasts.addDanger({
139139
title: backupServiceStrings.getPanelsSetError(e.message),

src/plugins/kibana_utils/public/storage/storage.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ export class Storage implements IStorageWrapper {
3232
}
3333
};
3434

35-
public set = (key: string, value: any) => {
35+
public set = (key: string, value: any, includeUndefined: boolean = false) => {
36+
const replacer = includeUndefined
37+
? (_: string, currentValue: any) =>
38+
typeof currentValue === 'undefined' ? null : currentValue
39+
: undefined;
3640
try {
37-
return this.store.setItem(key, JSON.stringify(value));
41+
return this.store.setItem(key, JSON.stringify(value, replacer));
3842
} catch (e) {
3943
return false;
4044
}

0 commit comments

Comments
 (0)