diff --git a/.changeset/modern-buses-protect.md b/.changeset/modern-buses-protect.md new file mode 100644 index 0000000000..d943d6c06a --- /dev/null +++ b/.changeset/modern-buses-protect.md @@ -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 diff --git a/plugins/catalog-react/src/components/UserListPicker/UserListPicker.tsx b/plugins/catalog-react/src/components/UserListPicker/UserListPicker.tsx index f861355762..e5658feec9 100644 --- a/plugins/catalog-react/src/components/UserListPicker/UserListPicker.tsx +++ b/plugins/catalog-react/src/components/UserListPicker/UserListPicker.tsx @@ -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 ( {filterGroups.map(group => (