catalog-react: introduce UserOwnersFilter

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2023-05-25 12:00:07 +02:00
parent ae2f2dd18d
commit 8bae84e5f4
+46
View File
@@ -200,8 +200,54 @@ export class EntityNamespaceFilter implements EntityFilter {
}
}
/**
* @public
*/
export class UserOwnersFilter implements EntityFilter {
private constructor(
readonly value: UserListFilterKind,
readonly refs?: string[],
) {}
static owned(ownershipEntityRefs: string[]) {
return new UserOwnersFilter('owned', ownershipEntityRefs);
}
static all() {
return new UserOwnersFilter('all');
}
static starred(starredEntityRefs: string[]) {
return new UserOwnersFilter('starred', starredEntityRefs);
}
getCatalogFilters(): Record<string, string[]> {
if (this.value === 'owned') {
return { 'relations.ownedBy': this.refs ?? [] };
}
if (this.value === 'starred') {
return {
'metadata.name': this.refs?.map(e => parseEntityRef(e).name) ?? [],
};
}
return {};
}
filterEntity(entity: Entity) {
if (this.value === 'starred') {
return this.refs?.includes(stringifyEntityRef(entity)) ?? true;
}
return true;
}
toQueryValue(): string {
return this.value;
}
}
/**
* Filters entities based on whatever the user has starred or owns them.
* @deprecated use UserOwnersFilter
* @public
*/
export class UserListFilter implements EntityFilter {