1- import {
2- AnalyticsParams ,
3- AnalyticsFilter ,
4- SearchQueryEvent ,
5- } from "shared/types" ;
6- import { createQuery , useQueryClient } from "@tanstack/solid-query" ;
7- import { createEffect , createSignal , on , Show , useContext } from "solid-js" ;
8- import { getLowConfidenceQueries } from "../../api/analytics" ;
9- import { DatasetContext } from "../../layouts/TopBarLayout" ;
10- import { usePagination } from "../../hooks/usePagination" ;
11- import { PaginationButtons } from "../PaginationButtons" ;
12- import { FullScreenModal , Table , Td , Th , Tr } from "shared/ui" ;
1+ import { AnalyticsParams , SearchQueryEvent } from "shared/types" ;
2+ import { createSignal , Show } from "solid-js" ;
3+ import { FullScreenModal , SortableColumnDef , TanStackTable } from "shared/ui" ;
134import { SearchQueryEventModal } from "../../pages/TrendExplorer" ;
145import { IoOpenOutline } from "solid-icons/io" ;
156import { Card } from "./Card" ;
16- import { BiRegularExpand } from "solid-icons/bi" ;
177import { useBetterNav } from "../../utils/useBetterNav" ;
18- import { QueryStringDisplay } from "../QueryStringDisplay" ;
8+ import { useLowConfidenceQueries } from "../../hooks/data/useLowConfidenceQueries" ;
9+ import { createSolidTable , getCoreRowModel } from "@tanstack/solid-table" ;
1910
2011interface LowConfidenceQueriesProps {
2112 params : AnalyticsParams ;
2213}
2314
24- const parseThreshold = ( text : string ) : number | undefined => {
25- const num = parseFloat ( text ) ;
26- if ( isNaN ( num ) ) {
27- return undefined ;
28- }
29- return num ;
30- } ;
15+ const columns : SortableColumnDef < SearchQueryEvent > [ ] = [
16+ {
17+ accessorKey : "query" ,
18+ header : "Query" ,
19+ } ,
20+ {
21+ accessorKey : "top_score" ,
22+ header : "Score" ,
23+ cell ( props ) {
24+ return props . getValue < number > ( ) . toFixed ( 5 ) ;
25+ } ,
26+ } ,
27+ ] ;
3128
3229export const LowConfidenceQueries = ( props : LowConfidenceQueriesProps ) => {
33- const dataset = useContext ( DatasetContext ) ;
34-
35- const pages = usePagination ( ) ;
36- const queryClient = useQueryClient ( ) ;
37-
3830 const [ thresholdText , setThresholdText ] = createSignal ( "" ) ;
39-
40- createEffect (
41- on (
42- ( ) => [ props . params , dataset ( ) . dataset . id , thresholdText ( ) ] ,
43- ( ) => {
44- pages . resetMaxPageDiscovered ( ) ;
45- } ,
46- ) ,
47- ) ;
48-
49- createEffect ( ( ) => {
50- // Preload the next page
51- const params = props . params ;
52- const datasetId = dataset ( ) . dataset . id ;
53- const curPage = pages . page ( ) ;
54- void queryClient . prefetchQuery ( {
55- queryKey : [
56- "low-confidence-queries" ,
57- {
58- params : params ,
59- page : curPage + 1 ,
60- threshold : parseThreshold ( thresholdText ( ) ) || 0 ,
61- } ,
62- ] ,
63- queryFn : async ( ) => {
64- const results = await getLowConfidenceQueries (
65- params . filter ,
66- datasetId ,
67- curPage + 1 ,
68- parseThreshold ( thresholdText ( ) ) ,
69- ) ;
70- if ( results . length === 0 ) {
71- pages . setMaxPageDiscovered ( curPage ) ;
72- }
73- return results ;
74- } ,
75- } ) ;
31+ const [ open , setOpen ] = createSignal ( false ) ;
32+ const [ current , setCurrent ] = createSignal < SearchQueryEvent | null > ( null ) ;
33+ const navigate = useBetterNav ( ) ;
34+ const { pages, lowConfidenceQueriesQuery } = useLowConfidenceQueries ( {
35+ params : props . params ,
36+ thresholdText : thresholdText ,
7637 } ) ;
7738
78- const lowConfidenceQueriesQuery = createQuery ( ( ) => ( {
79- queryKey : [
80- "low-confidence-queries" ,
81- {
82- params : props . params ,
83- page : pages . page ( ) ,
84- threshold : parseThreshold ( thresholdText ( ) ) || 0 ,
39+ const table = createSolidTable ( {
40+ get data ( ) {
41+ return lowConfidenceQueriesQuery . data || [ ] ;
42+ } ,
43+ state : {
44+ pagination : {
45+ pageIndex : pages . page ( ) ,
46+ pageSize : 10 ,
8547 } ,
86- ] ,
87- queryFn : ( ) => {
88- return getLowConfidenceQueries (
89- props . params . filter ,
90- dataset ( ) . dataset . id ,
91- pages . page ( ) ,
92- parseThreshold ( thresholdText ( ) ) ,
93- ) ;
9448 } ,
95- } ) ) ;
49+ columns,
50+ getCoreRowModel : getCoreRowModel ( ) ,
51+ manualPagination : true ,
52+ } ) ;
9653
9754 return (
9855 < Card
@@ -114,77 +71,39 @@ export const LowConfidenceQueries = (props: LowConfidenceQueriesProps) => {
11471 fallback = { < div class = "py-8" > Loading...</ div > }
11572 when = { lowConfidenceQueriesQuery . data }
11673 >
117- { ( data ) => (
118- < Table
119- fallback = { < div class = "py-8 text-center" > No Data</ div > }
120- class = "my-4"
121- data = { data ( ) }
122- headers = {
123- < Tr >
124- < Th > Query</ Th >
125- < Th class = "text-right" > Score</ Th >
126- < Th class = "text-right" />
127- </ Tr >
128- }
129- >
130- { ( row ) => < QueryCard query = { row } /> }
131- </ Table >
132- ) }
74+ < Show when = { current ( ) } >
75+ { ( data ) => (
76+ < FullScreenModal
77+ title = { data ( ) . query }
78+ show = { open }
79+ setShow = { setOpen }
80+ icon = {
81+ < button
82+ type = "button"
83+ class = "hover:text-fuchsia-500"
84+ onClick = { ( ) => {
85+ navigate ( "/query/" + data ( ) . id ) ;
86+ } }
87+ >
88+ < IoOpenOutline />
89+ </ button >
90+ }
91+ >
92+ < SearchQueryEventModal searchEvent = { data ( ) } />
93+ </ FullScreenModal >
94+ ) }
95+ </ Show >
96+ < TanStackTable
97+ small
98+ pages = { pages }
99+ perPage = { 10 }
100+ table = { table }
101+ onRowClick = { ( row ) => {
102+ setCurrent ( row ) ;
103+ setOpen ( true ) ;
104+ } }
105+ />
133106 </ Show >
134- < div class = "flex justify-end pt-2" >
135- < PaginationButtons size = { 18 } pages = { pages } />
136- </ div >
137107 </ Card >
138108 ) ;
139109} ;
140-
141- export interface QueryCardProps {
142- query : SearchQueryEvent ;
143- filters ?: AnalyticsFilter ;
144- }
145- export const QueryCard = ( props : QueryCardProps ) => {
146- const [ open , setOpen ] = createSignal ( false ) ;
147- const navigate = useBetterNav ( ) ;
148-
149- return (
150- < >
151- < Tr
152- onClick = { ( ) => {
153- setOpen ( true ) ;
154- } }
155- style = { {
156- cursor : "pointer" ,
157- } }
158- class = "cursor-pointer odd:bg-white even:bg-neutral-100 hover:underline hover:odd:bg-neutral-100/80 hover:even:bg-neutral-200/80"
159- >
160- < Td class = "truncate" >
161- < QueryStringDisplay > { props . query . query } </ QueryStringDisplay >
162- </ Td >
163- < Td class = "truncate text-right" > { props . query . top_score . toFixed ( 5 ) } </ Td >
164- < Td >
165- < span class = "hover:text-fuchsia-500" >
166- < BiRegularExpand />
167- </ span >
168- </ Td >
169- </ Tr >
170- < FullScreenModal
171- title = { props . query . query }
172- show = { open }
173- setShow = { setOpen }
174- icon = {
175- < button
176- type = "button"
177- class = "hover:text-fuchsia-500"
178- onClick = { ( ) => {
179- navigate ( "/query/" + props . query . id ) ;
180- } }
181- >
182- < IoOpenOutline />
183- </ button >
184- }
185- >
186- < SearchQueryEventModal searchEvent = { props . query } />
187- </ FullScreenModal >
188- </ >
189- ) ;
190- } ;
0 commit comments