From a6407c0f82c2578c01454113d33ca9cd4d108e2f Mon Sep 17 00:00:00 2001 From: Alex Rybchenko Date: Tue, 19 Jul 2022 16:10:43 +0200 Subject: [PATCH] rename method Signed-off-by: Alex Rybchenko --- .changeset/violet-trees-play.md | 4 ++-- plugins/shortcuts/api-report.md | 6 +++--- plugins/shortcuts/src/Shortcuts.tsx | 5 +---- plugins/shortcuts/src/api/LocalStoredShortcuts.ts | 8 ++++---- plugins/shortcuts/src/api/ShortcutApi.ts | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/.changeset/violet-trees-play.md b/.changeset/violet-trees-play.md index c44c75e98d..c56635633c 100644 --- a/.changeset/violet-trees-play.md +++ b/.changeset/violet-trees-play.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-shortcuts': patch +'@backstage/plugin-shortcuts': minor --- -fixed shortcuts initialization when using firestore +Fixed shortcuts initialization when using firestore diff --git a/plugins/shortcuts/api-report.md b/plugins/shortcuts/api-report.md index a58245e0fe..35c37bf536 100644 --- a/plugins/shortcuts/api-report.md +++ b/plugins/shortcuts/api-report.md @@ -20,14 +20,14 @@ export class LocalStoredShortcuts implements ShortcutApi { // (undocumented) add(shortcut: Omit): Promise; // (undocumented) + get(): Shortcut[]; + // (undocumented) getColor(url: string): string; // (undocumented) remove(id: string): Promise; // (undocumented) shortcut$(): Observable_2; // (undocumented) - snapshot(): Shortcut[]; - // (undocumented) update(shortcut: Shortcut): Promise; } @@ -45,10 +45,10 @@ export type Shortcut = { // @public (undocumented) export interface ShortcutApi { add(shortcut: Omit): Promise; + get(): Shortcut[]; getColor(url: string): string; remove(id: string): Promise; shortcut$(): Observable; - snapshot(): Shortcut[]; update(shortcut: Shortcut): Promise; } diff --git a/plugins/shortcuts/src/Shortcuts.tsx b/plugins/shortcuts/src/Shortcuts.tsx index 75baf5fd96..28aa33e8f2 100644 --- a/plugins/shortcuts/src/Shortcuts.tsx +++ b/plugins/shortcuts/src/Shortcuts.tsx @@ -39,10 +39,7 @@ export interface ShortcutsProps { export const Shortcuts = (props: ShortcutsProps) => { const shortcutApi = useApi(shortcutsApiRef); - const shortcuts = useObservable( - shortcutApi.shortcut$(), - shortcutApi.snapshot(), - ); + const shortcuts = useObservable(shortcutApi.shortcut$(), shortcutApi.get()); const [anchorEl, setAnchorEl] = React.useState(); const loading = Boolean(!shortcuts); diff --git a/plugins/shortcuts/src/api/LocalStoredShortcuts.ts b/plugins/shortcuts/src/api/LocalStoredShortcuts.ts index ba3722da66..82f4b7dd1a 100644 --- a/plugins/shortcuts/src/api/LocalStoredShortcuts.ts +++ b/plugins/shortcuts/src/api/LocalStoredShortcuts.ts @@ -33,27 +33,27 @@ export class LocalStoredShortcuts implements ShortcutApi { ); } - snapshot() { + get() { return Array.from( this.storageApi.snapshot('items').value ?? [], ).sort((a, b) => (a.title >= b.title ? 1 : -1)); } async add(shortcut: Omit) { - const shortcuts = this.snapshot(); + const shortcuts = this.get(); shortcuts.push({ ...shortcut, id: uuid() }); await this.storageApi.set('items', shortcuts); } async remove(id: string) { - const shortcuts = this.snapshot().filter(s => s.id !== id); + const shortcuts = this.get().filter(s => s.id !== id); await this.storageApi.set('items', shortcuts); } async update(shortcut: Shortcut) { - const shortcuts = this.snapshot().filter(s => s.id !== shortcut.id); + const shortcuts = this.get().filter(s => s.id !== shortcut.id); shortcuts.push(shortcut); await this.storageApi.set('items', shortcuts); diff --git a/plugins/shortcuts/src/api/ShortcutApi.ts b/plugins/shortcuts/src/api/ShortcutApi.ts index 542e77bac8..1f93baa66c 100644 --- a/plugins/shortcuts/src/api/ShortcutApi.ts +++ b/plugins/shortcuts/src/api/ShortcutApi.ts @@ -31,7 +31,7 @@ export interface ShortcutApi { /** * Returns an immediate snapshot of shortcuts, sorted by title */ - snapshot(): Shortcut[]; + get(): Shortcut[]; /** * Generates a unique id for the shortcut and then saves it.