diff --git a/.changeset/cool-deers-cough.md b/.changeset/cool-deers-cough.md index c2619d1fa2..0c07c91b96 100644 --- a/.changeset/cool-deers-cough.md +++ b/.changeset/cool-deers-cough.md @@ -6,4 +6,7 @@ Introduce a new `StarredEntitiesApi` that is used in the `useStarredEntities` hook. The `@backstage/plugin-catalog` installs a default implementation that is backed by the `StorageApi`, but one can also override the `starredEntitiesApiRef`. -**BREAKING** All previously stored entities get lost with this update, because the storage format has been migrated from a custom string to an entity reference. +**BREAKING** All previously stored entities get lost with this update, because: + +1. The storage format has been migrated from a custom string to an entity reference. +2. The storage key in the local storage has been changed. diff --git a/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.test.ts b/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.test.ts index eec484863f..95375aa0f6 100644 --- a/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.test.ts +++ b/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.test.ts @@ -52,8 +52,8 @@ describe('DefaultStarredEntitiesApi', () => { }); it('should unstar starred entity', async () => { - const bucket = mockStorage.forBucket('settings'); - await bucket.set('starredEntities', ['component:default/mock']); + const bucket = mockStorage.forBucket('starredEntities'); + await bucket.set('entityRefs', ['component:default/mock']); expect(starredEntitiesApi.isStarred(mockEntity)).toBe(true); @@ -78,8 +78,8 @@ describe('DefaultStarredEntitiesApi', () => { }, }); - const bucket = mockStorage.forBucket('settings'); - bucket.set('starredEntities', ['component:default/mock']).then(); + const bucket = mockStorage.forBucket('starredEntities'); + bucket.set('entityRefs', ['component:default/mock']).then(); }); }); diff --git a/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.ts b/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.ts index 5783954fbc..fa775679ca 100644 --- a/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.ts +++ b/plugins/catalog-react/src/apis/StarredEntitiesApi/DefaultStarredEntitiesApi.ts @@ -32,13 +32,13 @@ export class DefaultStarredEntitiesApi implements StarredEntitiesApi { private starredEntities: Set; constructor(opts: { storageApi: StorageApi }) { - this.settingsStore = opts.storageApi.forBucket('settings'); + this.settingsStore = opts.storageApi.forBucket('starredEntities'); this.starredEntities = new Set( - this.settingsStore.get('starredEntities') ?? [], + this.settingsStore.get('entityRefs') ?? [], ); - this.settingsStore.observe$('starredEntities').subscribe({ + this.settingsStore.observe$('entityRefs').subscribe({ next: next => { this.starredEntities = new Set(next.newValue ?? []); this.notifyChanges(); @@ -56,7 +56,7 @@ export class DefaultStarredEntitiesApi implements StarredEntitiesApi { } await this.settingsStore.set( - 'starredEntities', + 'entityRefs', Array.from(this.starredEntities), ); } diff --git a/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx b/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx index 0379e49351..4f41ef090f 100644 --- a/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx +++ b/plugins/catalog-react/src/hooks/useStarredEntities.test.tsx @@ -71,8 +71,8 @@ describe('useStarredEntities', () => { it('should return a set with the current items when there are items in storage', async () => { const expectedIds = ['i', 'am', 'some', 'test', 'ids']; - const store = mockStorage?.forBucket('settings'); - await store?.set('starredEntities', expectedIds); + const store = mockStorage?.forBucket('starredEntities'); + await store?.set('entityRefs', expectedIds); const { result, waitForNextUpdate } = renderHook( () => useStarredEntities(),