import {Fragment} from 'react';
import * as qs from 'query-string';
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 {decodeScalar} from 'sentry/utils/queryString';
import {useLocation} from 'sentry/utils/useLocation';
import useOrganization from 'sentry/utils/useOrganization';
import {normalizeUrl} from 'sentry/utils/withDomainRequired';
import TopResultsIndicator from 'sentry/views/discover/table/topResultsIndicator';
import Breakdown from 'sentry/views/performance/mobile/appStarts/screens/breakdown';
import {COLD_START_TYPE} from 'sentry/views/performance/mobile/appStarts/screenSummary/startTypeSelector';
import {ScreensTable} from 'sentry/views/performance/mobile/components/screensTable';
import {TOP_SCREENS} from 'sentry/views/performance/mobile/constants';
import {COLD_START_COLOR, WARM_START_COLOR} from 'sentry/views/starfish/colors';
import {
PRIMARY_RELEASE_ALIAS,
SECONDARY_RELEASE_ALIAS,
} from 'sentry/views/starfish/components/releaseSelector';
import {useReleaseSelection} from 'sentry/views/starfish/queries/useReleases';
import {SpanMetricsField} from 'sentry/views/starfish/types';
type Props = {
data: TableData | undefined;
eventView: EventView;
isLoading: boolean;
pageLinks: string | undefined;
};
export function AppStartScreens({data, eventView, isLoading, pageLinks}: Props) {
const location = useLocation();
const organization = useOrganization();
const {primaryRelease, secondaryRelease} = useReleaseSelection();
const startType =
decodeScalar(location.query[SpanMetricsField.APP_START_TYPE]) ?? COLD_START_TYPE;
const columnNameMap = {
transaction: t('Screen'),
[`avg_if(measurements.app_start_cold,release,${primaryRelease})`]: t(
'Cold Start (%s)',
PRIMARY_RELEASE_ALIAS
),
[`avg_if(measurements.app_start_cold,release,${secondaryRelease})`]: t(
'Cold Start (%s)',
SECONDARY_RELEASE_ALIAS
),
[`avg_if(measurements.app_start_warm,release,${primaryRelease})`]: t(
'Warm Start (%s)',
PRIMARY_RELEASE_ALIAS
),
[`avg_if(measurements.app_start_warm,release,${secondaryRelease})`]: t(
'Warm Start (%s)',
SECONDARY_RELEASE_ALIAS
),
[`avg_compare(measurements.app_start_cold,release,${primaryRelease},${secondaryRelease})`]:
t('Change'),
[`avg_compare(measurements.app_start_warm,release,${primaryRelease},${secondaryRelease})`]:
t('Change'),
app_start_breakdown: t('Type Breakdown'),
'count_starts(measurements.app_start_cold)': t('Count'),
'count_starts(measurements.app_start_warm)': t('Count'),
};
function renderBodyCell(column, row): React.ReactNode {
if (!data) {
return null;
}
const index = data.data.indexOf(row);
const field = String(column.key);
if (field === 'transaction') {
return (
{row.transaction}
);
}
if (field === 'app_start_breakdown') {
return (
);
}
return null;
}
return (
);
}