Skip to content

Commit aa12598

Browse files
authored
Merge pull request #1516 from supabase/master
[pull] master from supabase:master
2 parents 5a25c4b + ee87cc2 commit aa12598

File tree

5 files changed

+54
-21
lines changed

5 files changed

+54
-21
lines changed

apps/docs/features/docs/Reference.mdx.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import matter from 'gray-matter'
22
import { readFile } from 'node:fs/promises'
33
import { join } from 'node:path'
4-
4+
import { type ComponentProps } from 'react'
55
import CliGlobalFlagsHandler from '~/components/reference/enrichments/cli/CliGlobalFlagsHandler'
66
import { MDXRemoteBase } from '~/features/docs/MdxBase'
77
import { components } from '~/features/docs/MdxBase.shared'
88
import { RefSubLayout } from '~/features/docs/Reference.ui'
99
import { cache_fullProcess_withDevCacheBust } from '~/features/helpers.fs'
1010
import { REF_DOCS_DIRECTORY } from '~/lib/docs'
11+
import { CodeBlock } from '../ui/CodeBlock/CodeBlock'
1112

1213
async function getRefMarkdownInternal(relPath: string) {
1314
const fullPath = join(REF_DOCS_DIRECTORY, relPath + '.mdx')
@@ -42,7 +43,14 @@ interface MDXRemoteRefsProps {
4243
}
4344

4445
function MDXRemoteRefs({ source }: MDXRemoteRefsProps) {
45-
const refComponents = { ...components, RefSubLayout, CliGlobalFlagsHandler }
46+
const refComponents = {
47+
...components,
48+
// Override the CodeBlock used for normal guides to skip type generation
49+
// because it is too resource-intensive
50+
pre: (props: ComponentProps<typeof CodeBlock>) => <CodeBlock {...props} skipTypeGeneration />,
51+
RefSubLayout,
52+
CliGlobalFlagsHandler,
53+
}
4654

4755
return <MDXRemoteBase source={source} components={refComponents} />
4856
}

apps/docs/features/ui/CodeBlock/CodeBlock.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@ export async function CodeBlock({
2525
lineNumbers = true,
2626
contents,
2727
children,
28+
skipTypeGeneration,
2829
}: PropsWithChildren<{
2930
className?: string
3031
lang?: string
3132
lineNumbers?: boolean
3233
contents?: string
34+
skipTypeGeneration?: boolean
3335
}>) {
3436
let code = (contents || extractCode(children)).trim()
3537
const lang = tryToBundledLanguage(langSetting) || extractLang(children)
3638

3739
let twoslashed = null as null | Map<number, Map<number, Array<NodeHover>>>
38-
if (TWOSLASHABLE_LANGS.includes(lang)) {
40+
if (!skipTypeGeneration && TWOSLASHABLE_LANGS.includes(lang)) {
3941
try {
4042
const { code: editedCode, nodes } = twoslasher(code)
4143
const hoverNodes: Array<NodeHover> = nodes.filter((node) => node.type === 'hover')

apps/studio/components/ui/QueryBlock/QueryBlock.tsx

+30-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Code, Play } from 'lucide-react'
22
import { DragEvent, ReactNode, useEffect, useMemo, useState } from 'react'
3-
import { Bar, BarChart, CartesianGrid, XAxis } from 'recharts'
3+
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from 'recharts'
44
import { toast } from 'sonner'
55

66
import { useParams } from 'common'
@@ -9,6 +9,7 @@ import { ChartConfig } from 'components/interfaces/SQLEditor/UtilityPanel/ChartC
99
import Results from 'components/interfaces/SQLEditor/UtilityPanel/Results'
1010
import { usePrimaryDatabase } from 'data/read-replicas/replicas-query'
1111
import { QueryResponseError, useExecuteSqlMutation } from 'data/sql/execute-sql-mutation'
12+
import dayjs from 'dayjs'
1213
import { Parameter, parseParameters } from 'lib/sql-parameters'
1314
import { Dashboards } from 'types'
1415
import { ChartContainer, ChartTooltip, ChartTooltipContent, cn, CodeBlock, SQL_ICON } from 'ui'
@@ -133,9 +134,14 @@ export const QueryBlock = ({
133134
const formattedQueryResult = useMemo(() => {
134135
// Make sure Y axis values are numbers
135136
return queryResult?.map((row) => {
136-
return Object.fromEntries(Object.entries(row).map(([key, value]) => [key, Number(value)]))
137+
return Object.fromEntries(
138+
Object.entries(row).map(([key, value]) => {
139+
if (key === yKey) return [key, Number(value)]
140+
else return [key, value]
141+
})
142+
)
137143
})
138-
}, [queryResult])
144+
}, [queryResult, yKey])
139145

140146
const [parameterValues, setParameterValues] = useState<Record<string, string>>({})
141147
const [showWarning, setShowWarning] = useState<'hasWriteOperation' | 'hasUnknownFunctions'>()
@@ -151,6 +157,10 @@ export const QueryBlock = ({
151157
const postgresConnectionString = primaryDatabase?.connectionString
152158
const readOnlyConnectionString = primaryDatabase?.connection_string_read_only
153159

160+
const chartData = chartSettings.cumulative
161+
? getCumulativeResults({ rows: formattedQueryResult ?? [] }, chartSettings)
162+
: formattedQueryResult
163+
154164
const { mutate: execute, isLoading: isExecuting } = useExecuteSqlMutation({
155165
onSuccess: (data) => {
156166
onResults?.(data.result)
@@ -166,6 +176,14 @@ export const QueryBlock = ({
166176
},
167177
})
168178

179+
const getDateFormat = (key: any) => {
180+
const value = chartData?.[0]?.[key] || ''
181+
if (typeof value === 'number') return 'number'
182+
if (dayjs(value).isValid()) return 'date'
183+
return 'string'
184+
}
185+
const xKeyDateFormat = getDateFormat(xKey)
186+
169187
const handleExecute = () => {
170188
if (!sql || isLoading) return
171189

@@ -372,21 +390,22 @@ export const QueryBlock = ({
372390
>
373391
<BarChart
374392
accessibilityLayer
375-
margin={{ left: 0, right: 0 }}
376-
data={
377-
chartSettings.cumulative
378-
? getCumulativeResults({ rows: formattedQueryResult ?? [] }, chartSettings)
379-
: formattedQueryResult
380-
}
393+
margin={{ left: -20, right: 0, top: 10 }}
394+
data={chartData}
381395
>
382396
<CartesianGrid vertical={false} />
383397
<XAxis
398+
tickLine
384399
dataKey={xKey}
385-
tickLine={false}
386400
axisLine={false}
387-
tickMargin={8}
401+
interval="preserveStartEnd"
402+
tickMargin={4}
388403
minTickGap={32}
404+
tickFormatter={(value) =>
405+
xKeyDateFormat === 'date' ? dayjs(value).format('MMM D YYYY HH:mm') : value
406+
}
389407
/>
408+
<YAxis tickLine={false} axisLine={false} tickMargin={4} />
390409
<ChartTooltip content={<ChartTooltipContent className="w-[150px]" />} />
391410
<Bar dataKey={yKey} fill="var(--chart-1)" radius={4} />
392411
</BarChart>

apps/studio/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"react-inlinesvg": "^4.0.4",
108108
"react-intersection-observer": "^9.5.3",
109109
"react-markdown": "^8.0.3",
110+
"react-resizable": "3.0.5",
110111
"react-simple-maps": "4.0.0-beta.6",
111112
"react-use": "^17.5.0",
112113
"react-virtualized-auto-sizer": "^1.0.20",

pnpm-lock.yaml

+10-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)