@@ -6,18 +6,23 @@ import {Container, Grid} from '@sentry/scraps/layout';
66import { Text } from '@sentry/scraps/text' ;
77import { Tooltip } from '@sentry/scraps/tooltip' ;
88
9+ import { useCaseInsensitivity } from 'sentry/components/searchQueryBuilder/hooks' ;
910import {
1011 COL_WIDTH_UNDEFINED ,
1112 type GridColumnOrder ,
1213} from 'sentry/components/tables/gridEditable' ;
1314import TimeSince from 'sentry/components/timeSince' ;
1415import { t } from 'sentry/locale' ;
16+ import type { NewQuery } from 'sentry/types/organization' ;
1517import { getTimeStampFromTableDateField } from 'sentry/utils/dates' ;
18+ import EventView from 'sentry/utils/discover/eventView' ;
1619import { getFieldRenderer } from 'sentry/utils/discover/fieldRenderers' ;
1720import type { Sort } from 'sentry/utils/discover/fields' ;
21+ import { DiscoverDatasets } from 'sentry/utils/discover/types' ;
1822import { getShortEventId } from 'sentry/utils/events' ;
1923import { useLocation } from 'sentry/utils/useLocation' ;
2024import useOrganization from 'sentry/utils/useOrganization' ;
25+ import usePageFilters from 'sentry/utils/usePageFilters' ;
2126import { useTraceViewDrawer } from 'sentry/views/insights/agents/components/drawer' ;
2227import {
2328 HeadSortCell ,
@@ -34,7 +39,7 @@ import {
3439import { Referrer } from 'sentry/views/insights/aiGenerations/views/utils/referrer' ;
3540import { useFieldsQueryParam } from 'sentry/views/insights/aiGenerations/views/utils/useFieldsQueryParam' ;
3641import { TextAlignRight } from 'sentry/views/insights/common/components/textAlign' ;
37- import { useSpans } from 'sentry/views/insights/common/queries/useDiscover ' ;
42+ import { useSpansQuery } from 'sentry/views/insights/common/queries/useSpansQuery ' ;
3843import { PlatformInsightsTable } from 'sentry/views/insights/pages/platform/shared/table' ;
3944import { SpanFields } from 'sentry/views/insights/types' ;
4045
@@ -87,6 +92,8 @@ export function GenerationsTable() {
8792 const location = useLocation ( ) ;
8893 const organization = useOrganization ( ) ;
8994 const theme = useTheme ( ) ;
95+ const { selection} = usePageFilters ( ) ;
96+ const [ caseInsensitive ] = useCaseInsensitivity ( ) ;
9097
9198 const fieldsToQuery = useMemo ( ( ) => {
9299 return [
@@ -97,36 +104,58 @@ export function GenerationsTable() {
97104 ] ;
98105 } , [ fields ] ) ;
99106
100- const { data, meta, isLoading, error, pageLinks, isPlaceholderData} = useSpans (
101- {
102- search : query ,
103- fields : [ ...REQUIRED_FIELDS , ...fieldsToQuery ] as any ,
104- cursor,
105- sorts : [ tableSort ] ,
106- keepPreviousData : true ,
107- limit : 20 ,
108- } ,
109- Referrer . GENERATIONS_TABLE
110- ) ;
107+ const eventView = useMemo ( ( ) => {
108+ const queryFields = [ ...REQUIRED_FIELDS , ...fieldsToQuery ] ;
109+
110+ const discoverQuery : NewQuery = {
111+ id : undefined ,
112+ name : 'AI Generations' ,
113+ fields : queryFields ,
114+ orderby : [ `${ tableSort . kind === 'desc' ? '-' : '' } ${ tableSort . field } ` ] ,
115+ query,
116+ version : 2 ,
117+ dataset : DiscoverDatasets . SPANS ,
118+ } ;
119+
120+ return EventView . fromNewQueryWithPageFilters ( discoverQuery , selection ) ;
121+ } , [ fieldsToQuery , query , selection , tableSort . field , tableSort . kind ] ) ;
122+
123+ const {
124+ data = [ ] ,
125+ meta,
126+ isLoading,
127+ error,
128+ pageLinks,
129+ isPlaceholderData,
130+ } = useSpansQuery < Array < Record < string , any > > > ( {
131+ eventView,
132+ cursor,
133+ limit : 20 ,
134+ referrer : Referrer . GENERATIONS_TABLE ,
135+ initialData : [ ] ,
136+ allowAggregateConditions : false ,
137+ trackResponseAnalytics : false ,
138+ queryExtras : { caseInsensitive} ,
139+ } ) ;
111140
112- type TableData = ( typeof data ) [ number ] ;
141+ type TableData = Record < string , any > ;
113142
114143 const renderBodyCell = useCallback (
115- ( column : GridColumnOrder < GenerationFields > , dataRow : TableData ) => {
144+ ( column : GridColumnOrder < string > , dataRow : TableData ) => {
116145 if ( column . key === SpanFields . ID ) {
117146 return (
118147 < div >
119148 < Button
120149 priority = "link"
121150 onClick = { ( ) => {
122151 openTraceViewDrawer (
123- dataRow . trace ! ,
152+ dataRow . trace ,
124153 dataRow . id ,
125154 getTimeStampFromTableDateField ( dataRow . timestamp )
126155 ) ;
127156 } }
128157 >
129- { getShortEventId ( dataRow . id ! ) }
158+ { getShortEventId ( dataRow . id ) }
130159 </ Button >
131160 </ div >
132161 ) ;
@@ -196,7 +225,7 @@ export function GenerationsTable() {
196225 if ( column . key === SpanFields . TIMESTAMP ) {
197226 return (
198227 < TextAlignRight >
199- < TimeSince unitStyle = "short" date = { new Date ( dataRow . timestamp ! ) } />
228+ < TimeSince unitStyle = "short" date = { new Date ( dataRow . timestamp ) } />
200229 </ TextAlignRight >
201230 ) ;
202231 }
@@ -212,7 +241,7 @@ export function GenerationsTable() {
212241 ) ;
213242
214243 const renderHeadCell = useCallback (
215- ( column : GridColumnOrder < keyof TableData > ) => {
244+ ( column : GridColumnOrder < string > ) => {
216245 return (
217246 < HeadSortCell
218247 align = { column . key === SpanFields . TIMESTAMP ? 'right' : 'left' }
@@ -236,7 +265,7 @@ export function GenerationsTable() {
236265 isLoading = { isLoading }
237266 error = { error }
238267 initialColumnOrder = { fields . map (
239- ( field ) : GridColumnOrder < GenerationFields > => ( {
268+ ( field ) : GridColumnOrder < string > => ( {
240269 key : field ,
241270 name : prettyFieldNames [ field ] ?? field ,
242271 width : columnWidths [ field ] ?? COL_WIDTH_UNDEFINED ,
0 commit comments