From 5b769fddb5d11be117aa9acdec765486d9e3a393 Mon Sep 17 00:00:00 2001 From: Alex Rybchenko Date: Mon, 11 Jul 2022 17:32:47 +0200 Subject: [PATCH] added initial storage api subscription Signed-off-by: Alex Rybchenko --- .changeset/violet-trees-play.md | 5 +++++ plugins/shortcuts/src/api/LocalStoredShortcuts.ts | 9 +++++---- 2 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 .changeset/violet-trees-play.md diff --git a/.changeset/violet-trees-play.md b/.changeset/violet-trees-play.md new file mode 100644 index 0000000000..c44c75e98d --- /dev/null +++ b/.changeset/violet-trees-play.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-shortcuts': patch +--- + +fixed shortcuts initialization when using firestore diff --git a/plugins/shortcuts/src/api/LocalStoredShortcuts.ts b/plugins/shortcuts/src/api/LocalStoredShortcuts.ts index ef54f68acd..884f561aaa 100644 --- a/plugins/shortcuts/src/api/LocalStoredShortcuts.ts +++ b/plugins/shortcuts/src/api/LocalStoredShortcuts.ts @@ -25,7 +25,11 @@ import { StorageApi } from '@backstage/core-plugin-api'; * Implementation of the ShortcutApi that uses the StorageApi to store shortcuts. */ export class LocalStoredShortcuts implements ShortcutApi { - constructor(private readonly storageApi: StorageApi) {} + constructor(private readonly storageApi: StorageApi) { + this.storageApi.observe$('items').subscribe({ + next: () => this.notify(), + }); + } shortcut$() { return this.observable; @@ -36,14 +40,12 @@ export class LocalStoredShortcuts implements ShortcutApi { shortcuts.push({ ...shortcut, id: uuid() }); await this.storageApi.set('items', shortcuts); - this.notify(); } async remove(id: string) { const shortcuts = this.get().filter(s => s.id !== id); await this.storageApi.set('items', shortcuts); - this.notify(); } async update(shortcut: Shortcut) { @@ -51,7 +53,6 @@ export class LocalStoredShortcuts implements ShortcutApi { shortcuts.push(shortcut); await this.storageApi.set('items', shortcuts); - this.notify(); } getColor(url: string) {