import {useState} from 'react'; import {RouteComponentProps} from 'react-router'; import styled from '@emotion/styled'; import debounce from 'lodash/debounce'; import partition from 'lodash/partition'; import {openCreateTeamModal} from 'sentry/actionCreators/modal'; import Button from 'sentry/components/button'; import LoadingIndicator from 'sentry/components/loadingIndicator'; import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels'; import SearchBar from 'sentry/components/searchBar'; import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle'; import {DEFAULT_DEBOUNCE_DURATION} from 'sentry/constants'; import {IconAdd} from 'sentry/icons'; import {t} from 'sentry/locale'; import space from 'sentry/styles/space'; import {AccessRequest, Organization} from 'sentry/types'; import recreateRoute from 'sentry/utils/recreateRoute'; import useTeams from 'sentry/utils/useTeams'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; import AllTeamsList from './allTeamsList'; import OrganizationAccessRequests from './organizationAccessRequests'; type Props = { access: Set; features: Set; onRemoveAccessRequest: (id: string, isApproved: boolean) => void; organization: Organization; requestList: AccessRequest[]; } & RouteComponentProps<{orgId: string}, {}>; function OrganizationTeams({ organization, access, features, routes, params, requestList, onRemoveAccessRequest, }: Props) { const [teamQuery, setTeamQuery] = useState(''); const {initiallyLoaded} = useTeams({provideUserTeams: true}); const {teams, onSearch, loadMore, hasMore, fetching} = useTeams(); if (!organization) { return null; } const canCreateTeams = access.has('project:admin'); const action = ( ); const teamRoute = routes.find(({path}) => path === 'teams/'); const urlPrefix = teamRoute ? recreateRoute(teamRoute, {routes, params, stepBack: -2}) : ''; const title = t('Teams'); const debouncedSearch = debounce(onSearch, DEFAULT_DEBOUNCE_DURATION); function handleSearch(query: string) { setTeamQuery(query); debouncedSearch(query); } const filteredTeams = teams.filter(team => `#${team.slug}`.toLowerCase().includes(teamQuery.toLowerCase()) ); const [userTeams, otherTeams] = partition(filteredTeams, team => team.isMember); return (
{t('Your Teams')} {initiallyLoaded ? ( team.slug.includes(teamQuery))} access={access} openMembership={false} /> ) : ( )} {t('Other Teams')} {hasMore && ( {fetching && } )}
); } const StyledSearchBar = styled(SearchBar)` margin-bottom: ${space(2)}; `; const LoadMoreWrapper = styled('div')` display: grid; gap: ${space(2)}; align-items: center; justify-content: end; grid-auto-flow: column; `; export default OrganizationTeams;