Use entity refs as a storage format instead of the custom one

Signed-off-by: Dominik Henneke <dominik.henneke@sda-se.com>
This commit is contained in:
Dominik Henneke
2021-10-12 11:02:30 +02:00
parent 56f0ef983e
commit 615f668d31
5 changed files with 15 additions and 15 deletions
+2
View File
@@ -5,3 +5,5 @@
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.
+1 -3
View File
@@ -133,9 +133,7 @@ export type DefaultEntityFilters = {
text?: EntityTextFilter;
};
// Warning: (ae-missing-release-tag) "DefaultStarredEntitiesApi" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
// @public
export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
constructor(opts: { storageApi: StorageApi });
// (undocumented)
@@ -53,7 +53,7 @@ describe('DefaultStarredEntitiesApi', () => {
it('should unstar starred entity', async () => {
const bucket = mockStorage.forBucket('settings');
await bucket.set('starredEntities', ['entity:Component:default:mock']);
await bucket.set('starredEntities', ['component:default/mock']);
expect(starredEntitiesApi.isStarred(mockEntity)).toBe(true);
@@ -79,7 +79,7 @@ describe('DefaultStarredEntitiesApi', () => {
});
const bucket = mockStorage.forBucket('settings');
bucket.set('starredEntities', ['entity:Component:default:mock']).then();
bucket.set('starredEntities', ['component:default/mock']).then();
});
});
@@ -90,7 +90,7 @@ describe('DefaultStarredEntitiesApi', () => {
isStarred: expect.any(Function),
});
expect(handler).toBeCalledWith({
starredEntities: new Set(['entity:Component:default:mock']),
starredEntities: new Set(['component:default/mock']),
isStarred: expect.any(Function),
});
});
@@ -14,7 +14,7 @@
* limitations under the License.
*/
import { Entity } from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
import { Observable, StorageApi } from '@backstage/core-plugin-api';
import ObservableImpl from 'zen-observable';
import {
@@ -22,11 +22,11 @@ import {
StarredEntitiesApiObservable,
} from './StarredEntitiesApi';
const buildEntityKey = (component: Entity) =>
`entity:${component.kind}:${component.metadata.namespace ?? 'default'}:${
component.metadata.name
}`;
/**
* Default implementation of the StarredEntitiesApi that is backed by the StorageApi.
*
* @public
*/
export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
private readonly settingsStore: StorageApi;
private starredEntities: Set<string>;
@@ -47,7 +47,7 @@ export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
}
async toggleStarred(entity: Entity): Promise<void> {
const entityKey = buildEntityKey(entity);
const entityKey = stringifyEntityRef(entity);
if (this.starredEntities.has(entityKey)) {
this.starredEntities.delete(entityKey);
@@ -66,7 +66,7 @@ export class DefaultStarredEntitiesApi implements StarredEntitiesApi {
}
isStarred(entity: Entity): boolean {
const entityKey = buildEntityKey(entity);
const entityKey = stringifyEntityRef(entity);
return this.starredEntities.has(entityKey);
}
@@ -23,7 +23,7 @@ export const starredEntitiesApiRef: ApiRef<StarredEntitiesApi> = createApiRef({
export type StarredEntitiesApiObservable = {
/**
* A set of starred entities
* A set of entity references that are starred
*/
starredEntities: Set<string>;