123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- import {Fragment} from 'react';
- import * as qs from 'query-string';
- import Duration from 'sentry/components/duration';
- import Link from 'sentry/components/links/link';
- import {t} from 'sentry/locale';
- import type {TableData} from 'sentry/utils/discover/discoverQuery';
- import type EventView from 'sentry/utils/discover/eventView';
- import {NumberContainer} from 'sentry/utils/discover/styles';
- import {useLocation} from 'sentry/utils/useLocation';
- import TopResultsIndicator from 'sentry/views/discover/table/topResultsIndicator';
- import {
- PRIMARY_RELEASE_ALIAS,
- SECONDARY_RELEASE_ALIAS,
- } from 'sentry/views/insights/common/components/releaseSelector';
- import {useReleaseSelection} from 'sentry/views/insights/common/queries/useReleases';
- import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
- import {ScreensTable} from 'sentry/views/insights/mobile/common/components/tables/screensTable';
- import {TOP_SCREENS} from 'sentry/views/insights/mobile/constants';
- import {ModuleName} from 'sentry/views/insights/types';
- type Props = {
- data: TableData | undefined;
- eventView: EventView;
- isLoading: boolean;
- pageLinks: string | undefined;
- };
- export function UIScreensTable({data, eventView, isLoading, pageLinks}: Props) {
- const moduleURL = useModuleURL('mobile-ui');
- const location = useLocation();
- const {primaryRelease, secondaryRelease} = useReleaseSelection();
- const columnNameMap = {
- transaction: t('Screen'),
- [`division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`]: t(
- 'Slow (%s)',
- PRIMARY_RELEASE_ALIAS
- ),
- [`division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`]:
- t('Slow (%s)', SECONDARY_RELEASE_ALIAS),
- [`division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`]:
- t('Frozen (%s)', PRIMARY_RELEASE_ALIAS),
- [`division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`]:
- t('Frozen (%s)', SECONDARY_RELEASE_ALIAS),
- [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
- 'Delay (%s)',
- PRIMARY_RELEASE_ALIAS
- ),
- [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
- 'Delay (%s)',
- SECONDARY_RELEASE_ALIAS
- ),
- [`avg_compare(mobile.slow_frames,release,${primaryRelease},${secondaryRelease})`]:
- t('Change'),
- [`avg_compare(mobile.frozen_frames,release,${primaryRelease},${secondaryRelease})`]:
- t('Change'),
- [`avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`]:
- t('Change'),
- // TODO: Counts
- };
- const columnTooltipMap = {
- [`division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`]: t(
- 'The number of slow frames divided by total frames (%s)',
- PRIMARY_RELEASE_ALIAS
- ),
- [`division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`]:
- t(
- 'The number of slow frames divided by total frames (%s)',
- SECONDARY_RELEASE_ALIAS
- ),
- [`division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`]:
- t(
- 'The number of frozen frames divided by total frames (%s)',
- PRIMARY_RELEASE_ALIAS
- ),
- [`division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`]:
- t(
- 'The number of frozen frames divided by total frames (%s)',
- SECONDARY_RELEASE_ALIAS
- ),
- [`avg_if(mobile.frames_delay,release,${primaryRelease})`]: t(
- 'The average frame delay (%s)',
- PRIMARY_RELEASE_ALIAS
- ),
- [`avg_if(mobile.frames_delay,release,${secondaryRelease})`]: t(
- 'The average frame delay (%s)',
- SECONDARY_RELEASE_ALIAS
- ),
- };
- function renderBodyCell(column, row): React.ReactNode | null {
- if (!data) {
- return null;
- }
- const index = data.data.indexOf(row);
- const field = String(column.key);
- if (field === 'transaction') {
- return (
- <Fragment>
- <TopResultsIndicator count={TOP_SCREENS} index={index} />
- <Link
- to={`${moduleURL}/spans/?${qs.stringify({
- ...location.query,
- project: row['project.id'],
- transaction: row.transaction,
- primaryRelease,
- secondaryRelease,
- })}`}
- style={{display: `block`, width: `100%`}}
- >
- {row.transaction}
- </Link>
- </Fragment>
- );
- }
- if (field.startsWith('avg_if(mobile.frames_delay')) {
- return (
- <NumberContainer>
- {row[field] ? (
- <Duration seconds={row[field]} fixedDigits={2} abbreviation />
- ) : (
- '-'
- )}
- </NumberContainer>
- );
- }
- return null;
- }
- return (
- <ScreensTable
- columnNameMap={columnNameMap}
- columnTooltipMap={columnTooltipMap}
- data={data}
- eventView={eventView}
- isLoading={isLoading}
- pageLinks={pageLinks}
- columnOrder={[
- 'transaction',
- `division_if(mobile.slow_frames,mobile.total_frames,release,${primaryRelease})`,
- `division_if(mobile.slow_frames,mobile.total_frames,release,${secondaryRelease})`,
- `division_if(mobile.frozen_frames,mobile.total_frames,release,${primaryRelease})`,
- `division_if(mobile.frozen_frames,mobile.total_frames,release,${secondaryRelease})`,
- `avg_if(mobile.frames_delay,release,${primaryRelease})`,
- `avg_if(mobile.frames_delay,release,${secondaryRelease})`,
- `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
- ]}
- // TODO: Add default sort on count column
- defaultSort={[
- {
- key: `avg_compare(mobile.frames_delay,release,${primaryRelease},${secondaryRelease})`,
- order: 'desc',
- },
- ]}
- customBodyCellRenderer={renderBodyCell}
- moduleName={ModuleName.MOBILE_UI}
- />
- );
- }
|