feat: hide owned selector picker if user doesn't own an entity
Signed-off-by: djamaile <rdjamaile@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-catalog-react': patch
|
||||
---
|
||||
|
||||
when a user doesn't own any entity, the user won't get the option to select on owned
|
||||
@@ -176,12 +176,14 @@ export const UserListPicker = ({
|
||||
setEntitiesWithoutUserFilter(backendEntities.filter(filterFn));
|
||||
}, [filters, backendEntities]);
|
||||
|
||||
const totalOwnedUserEntities = entitiesWithoutUserFilter.filter(entity =>
|
||||
ownedFilter.filterEntity(entity),
|
||||
).length;
|
||||
|
||||
function getFilterCount(id: UserListFilterKind) {
|
||||
switch (id) {
|
||||
case 'owned':
|
||||
return entitiesWithoutUserFilter.filter(entity =>
|
||||
ownedFilter.filterEntity(entity),
|
||||
).length;
|
||||
return totalOwnedUserEntities;
|
||||
case 'starred':
|
||||
return entitiesWithoutUserFilter.filter(entity =>
|
||||
starredFilter.filterEntity(entity),
|
||||
@@ -191,6 +193,20 @@ export const UserListPicker = ({
|
||||
}
|
||||
}
|
||||
|
||||
function removeListItem(
|
||||
arr: ButtonGroup[],
|
||||
itemID: 'all' | 'owned' | 'starred',
|
||||
): ButtonGroup[] {
|
||||
const index = arr[0].items.map(item => item.id).indexOf(itemID);
|
||||
arr[0].items.splice(index, 1);
|
||||
return arr;
|
||||
}
|
||||
|
||||
// should we do the same for starred?
|
||||
if (totalOwnedUserEntities < 1) {
|
||||
removeListItem(filterGroups, 'owned');
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className={classes.root}>
|
||||
{filterGroups.map(group => (
|
||||
|
||||
Reference in New Issue
Block a user