123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- import DateTime from 'sentry/components/dateTime';
- import Duration from 'sentry/components/duration';
- import GridEditable, {GridColumnHeader} from 'sentry/components/gridEditable';
- import Link from 'sentry/components/links/link';
- import EventView from 'sentry/utils/discover/eventView';
- import {
- DiscoverQueryProps,
- useGenericDiscoverQuery,
- } from 'sentry/utils/discover/genericDiscoverQuery';
- import {useLocation} from 'sentry/utils/useLocation';
- import useOrganization from 'sentry/utils/useOrganization';
- import {TextAlignLeft} from 'sentry/views/starfish/modules/APIModule/endpointTable';
- type Props = {
- eventView: EventView;
- };
- type DataRow = {
- id: string;
- profile_id: string;
- timestamp: string;
- 'transaction.duration': number;
- };
- type Keys = 'id' | 'profile_id' | 'transaction.duration' | 'timestamp';
- type TableColumnHeader = GridColumnHeader<Keys>;
- const COLUMN_ORDER: TableColumnHeader[] = [
- {
- key: 'id',
- name: 'Event ID',
- width: 300,
- },
- {
- key: 'profile_id',
- name: 'Profile ID',
- width: 300,
- },
- {
- key: 'transaction.duration',
- name: 'Duration',
- width: -1,
- },
- {
- key: 'timestamp',
- name: 'Timestamp',
- width: -1,
- },
- ];
- export function SampleEvents({eventView}: Props) {
- const location = useLocation();
- const organization = useOrganization();
- const sampleEventsEventView = eventView
- .clone()
- .withColumns([
- {
- field: 'transaction.duration',
- kind: 'field',
- },
- {
- field: 'profile_id',
- kind: 'field',
- },
- {
- field: 'timestamp',
- kind: 'field',
- },
- ])
- .withSorts([
- {
- field: 'transaction.duration',
- kind: 'desc',
- },
- ]);
- function renderBodyCell(column: TableColumnHeader, row: DataRow): React.ReactNode {
- if (column.key === 'id') {
- return (
- <Link to={`/performance/${row['project.name']}:${row.id}`}>
- {row.id.slice(0, 8)}
- </Link>
- );
- }
- if (column.key === 'profile_id') {
- return row.profile_id ? (
- <Link
- to={`/profiling/profile/${row['project.name']}/${row.profile_id}/flamechart/`}
- >
- {row.profile_id.slice(0, 8)}
- </Link>
- ) : (
- '(no value)'
- );
- }
- if (column.key === 'timestamp') {
- return <DateTime date={row.timestamp} year timeZone seconds />;
- }
- if (column.key === 'transaction.duration') {
- return (
- <Duration
- seconds={row['transaction.duration'] / 1000}
- fixedDigits={2}
- abbreviation
- />
- );
- }
- return <TextAlignLeft>{row[column.key]}</TextAlignLeft>;
- }
- const {isLoading, data} = useGenericDiscoverQuery<any, DiscoverQueryProps>({
- route: 'events',
- eventView: sampleEventsEventView,
- referrer: 'starfish-transaction-summary-sample-events',
- limit: 5,
- location,
- orgSlug: organization.slug,
- getRequestPayload: () => ({
- ...sampleEventsEventView.getEventsAPIPayload(location),
- }),
- });
- return (
- <GridEditable
- isLoading={isLoading}
- data={data?.data}
- columnOrder={COLUMN_ORDER}
- columnSortBy={[]}
- location={location}
- grid={{
- renderBodyCell,
- }}
- />
- );
- }
|