import styled from '@emotion/styled';
import {Location} from 'history';
import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
import {Body, Hovercard} from 'sentry/components/hovercard';
import LoadingIndicator from 'sentry/components/loadingIndicator';
import Version from 'sentry/components/version';
import {t} from 'sentry/locale';
import {space} from 'sentry/styles/space';
import {Organization, Project} from 'sentry/types';
import {trackAnalytics} from 'sentry/utils/analytics';
import EventView, {EventData} from 'sentry/utils/discover/eventView';
import {getShortEventId} from 'sentry/utils/events';
import {useLocation} from 'sentry/utils/useLocation';
import EventContext from './eventContext';
import IssueContext from './issueContext';
import ReleaseContext from './releaseContext';
import {NoContextWrapper} from './styles';
import {ContextType} from './utils';
const HOVER_DELAY: number = 400;
type NoContextProps = {
isLoading: boolean;
};
export function NoContext({isLoading}: NoContextProps) {
return isLoading ? (
) : (
{t('Failed to load context for column.')}
);
}
function getHoverBody(
dataRow: EventData,
contextType: ContextType,
organization: Organization,
location?: Location,
projects?: Project[],
eventView?: EventView
) {
switch (contextType) {
case ContextType.ISSUE:
return ;
case ContextType.RELEASE:
return ;
case ContextType.EVENT:
return (
);
default:
return {t('There is no context available.')};
}
}
// NOTE: Will be adding switch cases as more contexts require headers.
function getHoverHeader(
dataRow: EventData,
contextType: ContextType,
organization: Organization
) {
switch (contextType) {
case ContextType.RELEASE:
return (
}
copyContent={dataRow.release}
/>
);
case ContextType.ISSUE:
return (
);
case ContextType.EVENT:
return (
dataRow.id && (
)
);
default:
return null;
}
}
type HoverHeaderProps = {
organization: Organization;
title: string;
copyContent?: string;
copyLabel?: React.ReactNode;
hideCopy?: boolean;
};
function HoverHeader({
title,
hideCopy = false,
copyLabel,
copyContent,
organization,
}: HoverHeaderProps) {
return (
{title}
{copyLabel}
{!hideCopy && copyContent && (
{
trackAnalytics('discover_v2.quick_context_header_copy', {
organization,
clipBoardTitle: title,
});
}}
size="zero"
text={copyContent}
/>
)}
);
}
type ContextProps = {
children: React.ReactNode;
contextType: ContextType;
dataRow: EventData;
organization: Organization;
eventView?: EventView;
projects?: Project[];
};
export function QuickContextHoverWrapper(props: ContextProps) {
const location = useLocation();
const {dataRow, contextType, organization, projects, eventView} = props;
return (
{props.children}
);
}
const StyledHovercard = styled(Hovercard)`
${Body} {
padding: 0;
}
min-width: max-content;
`;
const HoverWrapper = styled('div')`
display: flex;
align-items: center;
gap: ${space(0.75)};
`;
const HoverHeaderWrapper = styled('div')`
display: flex;
align-items: center;
justify-content: space-between;
`;
const HoverHeaderContent = styled('div')`
display: flex;
flex: 1;
align-items: center;
justify-content: flex-end;
gap: ${space(0.5)};
`;
const StyledVersion = styled(Version)`
max-width: 190px;
`;