Skip to content

Commit

Permalink
feat: hide owned selector picker if user doesn't own an entity
Browse files Browse the repository at this point in the history
Signed-off-by: djamaile <rdjamaile@gmail.com>
  • Loading branch information
djamaile committed Nov 23, 2021
1 parent 59dc704 commit c6fddde
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-buses-protect.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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 => (
Expand Down

0 comments on commit c6fddde

Please sign in to comment.