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 from 'sentry/components/panels/panel'; import PanelBody from 'sentry/components/panels/panelBody'; import PanelHeader from 'sentry/components/panels/panelHeader'; import SearchBar from 'sentry/components/searchBar'; import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle'; import {TeamRoleColumnLabel} from 'sentry/components/teamRoleUtils'; 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 {useTeams} from 'sentry/utils/useTeams'; import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader'; import {RoleOverwritePanelAlert} from 'sentry/views/settings/organizationTeams/roleOverwriteWarning'; import AllTeamsList from './allTeamsList'; import {GRID_TEMPLATE} from './allTeamsRow'; import OrganizationAccessRequests from './organizationAccessRequests'; type Props = { access: Set; features: Set; onRemoveAccessRequest: (id: string, isApproved: boolean) => void; organization: Organization; requestList: AccessRequest[]; } & RouteComponentProps<{}, {}>; function OrganizationTeams({ organization, access, features, 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 title = t('Teams'); const debouncedSearch = debounce(onSearch, DEFAULT_DEBOUNCE_DURATION); function handleSearch(query: string) { setTeamQuery(query); debouncedSearch(query); } const {slug: orgSlug, orgRole, orgRoleList, teamRoleList} = organization; 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 StyledPanelHeader = styled(PanelHeader)` ${GRID_TEMPLATE} `; const LoadMoreWrapper = styled('div')` display: grid; gap: ${space(2)}; align-items: center; justify-content: end; grid-auto-flow: column; `; export default OrganizationTeams;