Skip to content

Commit 59e1db8

Browse files
committed
refactor(connection): remove unused definitionTabs and enhance query options with exact filter
1 parent 8c11f14 commit 59e1db8

5 files changed

Lines changed: 34 additions & 35 deletions

File tree

apps/desktop/src/entities/connection/store/index.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ const tabType = type({
1111
preview: 'boolean',
1212
})
1313

14-
const definitionTabType = type({
15-
type: '"enums" | "constraints" | "indexes"',
16-
})
17-
1814
const queryToRunType = type({
1915
startLineNumber: 'number',
2016
endLineNumber: 'number',
@@ -30,7 +26,6 @@ const layoutSettingsType = type({
3026
export const connectionStoreType = type({
3127
lastOpenedPage: 'string | null' as type.cast<(Extract<keyof FileRoutesById, `/_protected/database/$id/${string}`> | null)>,
3228
lastOpenedChatId: 'string | null',
33-
definitionTabs: definitionTabType.array(),
3429
lastOpenedTable: type({
3530
schema: 'string',
3631
table: 'string',
@@ -60,7 +55,6 @@ export const connectionStoreType = type({
6055
const defaultState: typeof connectionStoreType.infer = {
6156
lastOpenedPage: null,
6257
lastOpenedChatId: null,
63-
definitionTabs: [],
6458
lastOpenedTable: null,
6559
sql: [
6660
'-- Write your SQL query here based on your database schema',
@@ -139,7 +133,6 @@ export function connectionStore(id: string) {
139133
lastOpenedPage: currentVal.lastOpenedPage,
140134
lastOpenedChatId: currentVal.lastOpenedChatId,
141135
lastOpenedTable: currentVal.lastOpenedTable,
142-
definitionTabs: currentVal.definitionTabs,
143136
sql: currentVal.sql,
144137
selectedLines: currentVal.selectedLines,
145138
loggerOpened: currentVal.loggerOpened,

apps/desktop/src/entities/connection/utils/fetching.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ export async function prefetchConnectionTableCore({ connection, schema, table, q
2727
query: {
2828
filters: ActiveFilter[]
2929
orderBy: Record<string, 'ASC' | 'DESC'>
30+
exact: boolean
3031
}
3132
}) {
3233
await Promise.all([
3334
queryClient.prefetchInfiniteQuery(connectionRowsQuery({ connection, table, schema, query })),
34-
queryClient.prefetchQuery(connectionTableTotalQuery({ connection, table, schema, query: { filters: query.filters, exact: false } })),
35+
queryClient.prefetchQuery(connectionTableTotalQuery({ connection, table, schema, query })),
3536
queryClient.prefetchQuery(connectionTableColumnsQuery({ connection, table, schema })),
3637
])
3738
}

apps/desktop/src/routes/_protected/database/$id/table/-components/header/header.tsx

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@conar
33
import { cn } from '@conar/ui/lib/utils'
44
import NumberFlow from '@number-flow/react'
55
import { useStore } from '@tanstack/react-store'
6-
import { useState } from 'react'
76
import { useConnectionTableTotal } from '~/entities/connection/queries'
87
import { Route } from '../..'
98
import { useTableColumns } from '../../-queries/use-columns-query'
@@ -16,11 +15,10 @@ export function Header({ table, schema }: { table: string, schema: string }) {
1615
const columns = useTableColumns({ connection, table, schema })
1716
const store = usePageStoreContext()
1817
const filters = useStore(store, state => state.filters)
19-
const [exact, setExact] = useState(false)
18+
const exact = useStore(store, state => state.exact)
2019
const { data: total, isLoading } = useConnectionTableTotal({ connection, table, schema, query: { filters, exact } })
2120

2221
const columnsCount = columns?.length ?? 0
23-
const count = Number(total?.count)
2422

2523
return (
2624
<div className="flex w-full items-center justify-between gap-6">
@@ -43,31 +41,35 @@ export function Header({ table, schema }: { table: string, schema: string }) {
4341
{columnsCount === 1 ? '' : 's'}
4442
</span>
4543
<Separator orientation="vertical" className="h-3!" />
46-
<TooltipProvider>
47-
<Tooltip>
48-
<TooltipTrigger
49-
className={cn('inline-flex items-center gap-1', !exact && total?.isEstimated && `
50-
cursor-pointer
51-
`)}
52-
onClick={() => setExact(true)}
53-
>
54-
<NumberFlow
55-
value={count}
56-
format={{ notation: 'compact', compactDisplay: 'short', maximumFractionDigits: 1 }}
57-
className={cn('text-muted-foreground tabular-nums', isLoading && `
58-
animate-pulse
59-
`)}
60-
prefix={total?.isEstimated ? '~' : ''}
61-
suffix={count === 1 ? ' row' : ' rows'}
62-
/>
63-
</TooltipTrigger>
64-
{!exact && total?.isEstimated && (
65-
<TooltipContent side="bottom">
66-
Click to get the exact count.
67-
</TooltipContent>
44+
{total?.count === undefined
45+
? <>...</>
46+
: (
47+
<TooltipProvider>
48+
<Tooltip>
49+
<TooltipTrigger
50+
className={cn('inline-flex items-center gap-1', !exact && total.isEstimated && `
51+
cursor-pointer
52+
`)}
53+
onClick={() => store.setState(state => ({ ...state, exact: true } satisfies typeof state))}
54+
>
55+
<NumberFlow
56+
value={total.count}
57+
format={{ notation: 'compact', compactDisplay: 'short', maximumFractionDigits: 1 }}
58+
className={cn('text-muted-foreground tabular-nums', isLoading && `
59+
animate-pulse text-muted-foreground/50
60+
`)}
61+
prefix={total.isEstimated ? '~' : ''}
62+
suffix={total.count === 1 ? ' row' : ' rows'}
63+
/>
64+
</TooltipTrigger>
65+
{!exact && total.isEstimated && (
66+
<TooltipContent side="bottom">
67+
Click to get the exact count.
68+
</TooltipContent>
69+
)}
70+
</Tooltip>
71+
</TooltipProvider>
6872
)}
69-
</Tooltip>
70-
</TooltipProvider>
7173
</div>
7274
</div>
7375
<Separator orientation="vertical" className="h-6!" />

apps/desktop/src/routes/_protected/database/$id/table/-components/tabs.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,14 @@ function getQueryOpts(connection: typeof connections.$inferSelect, schema: strin
5959
return {
6060
filters: state.filters,
6161
orderBy: state.orderBy,
62+
exact: state.exact,
6263
}
6364
}
6465

6566
return {
6667
filters: [],
6768
orderBy: {},
69+
exact: false,
6870
}
6971
}
7072

apps/desktop/src/routes/_protected/database/$id/table/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export const Route = createFileRoute(
4444
query: {
4545
filters: store.state.filters,
4646
orderBy: store.state.orderBy,
47+
exact: store.state.exact,
4748
},
4849
})
4950
}

0 commit comments

Comments
 (0)