mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-10-30 14:49:14 +00:00
68 lines
1.9 KiB
TypeScript
68 lines
1.9 KiB
TypeScript
import type {RouteComponentProps} from 'react-router';
|
|
import {browserHistory} from 'react-router';
|
|
import debounce from 'lodash/debounce';
|
|
|
|
import IdBadge from 'sentry/components/idBadge';
|
|
import {DEFAULT_DEBOUNCE_DURATION} from 'sentry/constants';
|
|
import recreateRoute from 'sentry/utils/recreateRoute';
|
|
import {useParams} from 'sentry/utils/useParams';
|
|
import {useTeams} from 'sentry/utils/useTeams';
|
|
import BreadcrumbDropdown from 'sentry/views/settings/components/settingsBreadcrumb/breadcrumbDropdown';
|
|
import MenuItem from 'sentry/views/settings/components/settingsBreadcrumb/menuItem';
|
|
|
|
import {CrumbLink} from '.';
|
|
|
|
type Props = RouteComponentProps<{teamId: string}, {}>;
|
|
|
|
function TeamCrumb({routes, route, ...props}: Props) {
|
|
const {teams, onSearch, fetching} = useTeams();
|
|
const params = useParams();
|
|
|
|
const team = teams.find(({slug}) => slug === params.teamId);
|
|
const hasMenu = teams.length > 1;
|
|
|
|
const handleSearchChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
onSearch(e.target.value);
|
|
};
|
|
const debouncedHandleSearch = debounce(handleSearchChange, DEFAULT_DEBOUNCE_DURATION);
|
|
|
|
if (!team) {
|
|
return null;
|
|
}
|
|
const teamUrl = `/settings/${params.orgId}/teams/${team.slug}/`;
|
|
|
|
return (
|
|
<BreadcrumbDropdown
|
|
name={
|
|
<CrumbLink to={teamUrl}>
|
|
<IdBadge avatarSize={18} team={team} />
|
|
</CrumbLink>
|
|
}
|
|
onSelect={item => {
|
|
browserHistory.push(
|
|
recreateRoute('', {
|
|
routes,
|
|
params: {...params, teamId: item.value},
|
|
})
|
|
);
|
|
}}
|
|
hasMenu={hasMenu}
|
|
route={route}
|
|
items={teams.map((teamItem, index) => ({
|
|
index,
|
|
value: teamItem.slug,
|
|
label: (
|
|
<MenuItem>
|
|
<IdBadge team={teamItem} />
|
|
</MenuItem>
|
|
),
|
|
}))}
|
|
onChange={debouncedHandleSearch}
|
|
busyItemsStillVisible={fetching}
|
|
{...props}
|
|
/>
|
|
);
|
|
}
|
|
|
|
export default TeamCrumb;
|