|
@@ -1,41 +1,69 @@
|
|
-import styled from '@emotion/styled';
|
|
|
|
import clamp from 'lodash/clamp';
|
|
import clamp from 'lodash/clamp';
|
|
|
|
|
|
|
|
+import ExternalLink from 'sentry/components/links/externalLink';
|
|
import {Tooltip} from 'sentry/components/tooltip';
|
|
import {Tooltip} from 'sentry/components/tooltip';
|
|
-import {tct} from 'sentry/locale';
|
|
|
|
|
|
+import {t, tct} from 'sentry/locale';
|
|
import {defined} from 'sentry/utils';
|
|
import {defined} from 'sentry/utils';
|
|
|
|
+import {NumberContainer} from 'sentry/utils/discover/styles';
|
|
import {formatPercentage, getDuration} from 'sentry/utils/formatters';
|
|
import {formatPercentage, getDuration} from 'sentry/utils/formatters';
|
|
-import {TextAlignRight} from 'sentry/views/starfish/components/textAlign';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
|
+ containerProps?: React.DetailedHTMLProps<
|
|
|
|
+ React.HTMLAttributes<HTMLDivElement>,
|
|
|
|
+ HTMLDivElement
|
|
|
|
+ >;
|
|
|
|
+ op?: string;
|
|
percentage?: number;
|
|
percentage?: number;
|
|
total?: number;
|
|
total?: number;
|
|
}
|
|
}
|
|
|
|
|
|
-export function TimeSpentCell({percentage, total}: Props) {
|
|
|
|
|
|
+export function TimeSpentCell({percentage, total, op, containerProps}: Props) {
|
|
const formattedPercentage = formatPercentage(clamp(percentage ?? 0, 0, 1));
|
|
const formattedPercentage = formatPercentage(clamp(percentage ?? 0, 0, 1));
|
|
const formattedTotal = getDuration((total ?? 0) / 1000, 2, true);
|
|
const formattedTotal = getDuration((total ?? 0) / 1000, 2, true);
|
|
const tooltip = tct(
|
|
const tooltip = tct(
|
|
- 'The application spent [percentage] of its total time on this span.',
|
|
|
|
|
|
+ 'The application spent [percentage] of its total time on this [span]. Read more about Time Spent in our [documentation:documentation].',
|
|
{
|
|
{
|
|
percentage: formattedPercentage,
|
|
percentage: formattedPercentage,
|
|
|
|
+ span: getSpanOperationDescription(op),
|
|
|
|
+ documentation: (
|
|
|
|
+ <ExternalLink href="https://docs.sentry.io/product/performance/queries/#what-is-time-spent" />
|
|
|
|
+ ),
|
|
}
|
|
}
|
|
);
|
|
);
|
|
|
|
|
|
return (
|
|
return (
|
|
- <TextAlignRight>
|
|
|
|
|
|
+ <NumberContainer {...containerProps}>
|
|
<Tooltip isHoverable title={tooltip} showUnderline>
|
|
<Tooltip isHoverable title={tooltip} showUnderline>
|
|
{defined(total) ? formattedTotal : '--'}
|
|
{defined(total) ? formattedTotal : '--'}
|
|
- <Deemphasized>
|
|
|
|
- {' ('}
|
|
|
|
- {defined(percentage) ? formattedPercentage : '--%'}
|
|
|
|
- {')'}
|
|
|
|
- </Deemphasized>
|
|
|
|
</Tooltip>
|
|
</Tooltip>
|
|
- </TextAlignRight>
|
|
|
|
|
|
+ </NumberContainer>
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
-const Deemphasized = styled('span')`
|
|
|
|
- color: ${p => p.theme.gray300};
|
|
|
|
-`;
|
|
|
|
|
|
+// TODO: This should use `getSpanOperationDescription` but it uppercases the
|
|
|
|
+// names. We should update `getSpanOperationDescription` to not uppercase the
|
|
|
|
+// descriptions needlessly, and use it here. Also, the names here are a little
|
|
|
|
+// shorter, which is friendlier
|
|
|
|
+function getSpanOperationDescription(spanOp?: string) {
|
|
|
|
+ if (spanOp?.startsWith('http')) {
|
|
|
|
+ return t('request');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (spanOp?.startsWith('db')) {
|
|
|
|
+ return t('query');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (spanOp?.startsWith('task')) {
|
|
|
|
+ return t('task');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (spanOp?.startsWith('serialize')) {
|
|
|
|
+ return t('serializer');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (spanOp?.startsWith('middleware')) {
|
|
|
|
+ return t('middleware');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return t('span');
|
|
|
|
+}
|