import {Fragment} from 'react'; import styled from '@emotion/styled'; import isObject from 'lodash/isObject'; import type {OnAssignCallback} from 'sentry/components/assigneeSelectorDropdown'; import AvatarList from 'sentry/components/avatar/avatarList'; import DateTime from 'sentry/components/dateTime'; import ErrorBoundary from 'sentry/components/errorBoundary'; import AssignedTo from 'sentry/components/group/assignedTo'; import ExternalIssueList from 'sentry/components/group/externalIssuesList'; import GroupReleaseStats from 'sentry/components/group/releaseStats'; import TagFacets, { BACKEND_TAGS, DEFAULT_TAGS, FRONTEND_TAGS, MOBILE_TAGS, TAGS_FORMATTER, } from 'sentry/components/group/tagFacets'; import QuestionTooltip from 'sentry/components/questionTooltip'; import * as SidebarSection from 'sentry/components/sidebarSection'; import {backend, frontend} from 'sentry/data/platformCategories'; import {t} from 'sentry/locale'; import ConfigStore from 'sentry/stores/configStore'; import {space} from 'sentry/styles/space'; import { AvatarUser, CurrentRelease, Group, IssueType, Organization, OrganizationSummary, Project, } from 'sentry/types'; import {Event} from 'sentry/types/event'; import {trackAnalytics} from 'sentry/utils/analytics'; import {getUtcDateString} from 'sentry/utils/dates'; import {getAnalyticsDataForGroup} from 'sentry/utils/events'; import {userDisplayName} from 'sentry/utils/formatters'; import {isMobilePlatform} from 'sentry/utils/platform'; import {useApiQuery} from 'sentry/utils/queryClient'; import {useLocation} from 'sentry/utils/useLocation'; import {getGroupDetailsQueryData} from 'sentry/views/issueDetails/utils'; type Props = { environments: string[]; group: Group; organization: Organization; project: Project; event?: Event; }; function useFetchAllEnvsGroupData(organization: OrganizationSummary, group: Group) { return useApiQuery( [ `/organizations/${organization.slug}/issues/${group.id}/`, {query: getGroupDetailsQueryData()}, ], { staleTime: 30000, cacheTime: 30000, } ); } function useFetchCurrentRelease(organization: OrganizationSummary, group: Group) { return useApiQuery( [`/organizations/${organization.slug}/issues/${group.id}/current-release/`], { staleTime: 30000, cacheTime: 30000, } ); } export default function GroupSidebar({ event, group, project, organization, environments, }: Props) { const {data: allEnvironmentsGroupData} = useFetchAllEnvsGroupData(organization, group); const {data: currentRelease} = useFetchCurrentRelease(organization, group); const location = useLocation(); const trackAssign: OnAssignCallback = (type, _assignee, suggestedAssignee) => { const {alert_date, alert_rule_id, alert_type} = location.query; trackAnalytics('issue_details.action_clicked', { organization, project_id: parseInt(project.id, 10), action_type: 'assign', assigned_type: type, assigned_suggestion_reason: suggestedAssignee?.suggestedReason, alert_date: typeof alert_date === 'string' ? getUtcDateString(Number(alert_date)) : undefined, alert_rule_id: typeof alert_rule_id === 'string' ? alert_rule_id : undefined, alert_type: typeof alert_type === 'string' ? alert_type : undefined, ...getAnalyticsDataForGroup(group), }); }; const renderPluginIssue = () => { const issues: React.ReactNode[] = []; (group.pluginIssues || []).forEach(plugin => { const issue = plugin.issue; // # TODO(dcramer): remove plugin.title check in Sentry 8.22+ if (issue) { issues.push( {`${plugin.shortName || plugin.name || plugin.title}: `} {isObject(issue.label) ? issue.label.id : issue.label} ); } }); if (!issues.length) { return null; } return ( {t('External Issues')} {issues} ); }; const renderParticipantData = () => { const {participants} = group; if (!participants.length) { return null; } return ( {t('Participants (%s)', participants.length)} ); }; const renderSeenByList = () => { const {seenBy} = group; const activeUser = ConfigStore.get('user'); const displayUsers = seenBy.filter(user => activeUser.id !== user.id); if (!displayUsers.length) { return null; } return ( {t('Viewers (%s)', displayUsers.length)}{' '} ( {userDisplayName(user)}
)} />
); }; return ( {group.issueType !== IssueType.PERFORMANCE_DURATION_REGRESSION && ( )} {event && ( )} {renderPluginIssue()} tag !== 'device.class') : MOBILE_TAGS : frontend.some(val => val === project?.platform) ? FRONTEND_TAGS : backend.some(val => val === project?.platform) ? BACKEND_TAGS : DEFAULT_TAGS } event={event} tagFormatter={TAGS_FORMATTER} project={project} /> {renderParticipantData()} {renderSeenByList()} ); } const Container = styled('div')` font-size: ${p => p.theme.fontSizeMedium}; `; const ExternalIssues = styled('div')` display: grid; grid-template-columns: auto max-content; gap: ${space(2)}; `; const StyledAvatarList = styled(AvatarList)` justify-content: flex-end; padding-left: ${space(0.75)}; `;