Skip to content

Commit 646abdd

Browse files
authored
Merge pull request #3650 from ClickHouse/fix_nyc_chart
fix wrap on buttons
2 parents ec375c5 + 0d945e2 commit 646abdd

File tree

1 file changed

+44
-23
lines changed

1 file changed

+44
-23
lines changed

src/components/CodeViewer/CodeInterpreter.tsx

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { formatBytes, formatReadableRows, roundToDynamicPrecision } from './util
1515
import { getGoogleAnalyticsUserIdFromBrowserCookie } from '../../lib/google/google'
1616

1717

18+
1819
interface Props {
1920
queryString: string
2021
runnable: boolean
@@ -55,6 +56,21 @@ function CodeInterpreter({
5556
}
5657
})
5758

59+
function useWindowWidth(): number {
60+
const [width, setWidth] = useState(typeof window !== 'undefined' ? window.innerWidth : 0)
61+
62+
useEffect(() => {
63+
function handleResize() {
64+
setWidth(window.innerWidth)
65+
}
66+
67+
window.addEventListener('resize', handleResize)
68+
return () => window.removeEventListener('resize', handleResize)
69+
}, [])
70+
71+
return width
72+
}
73+
5874
function generateId(): string {
5975
return short.generate().toUpperCase().slice(0, 27)
6076
}
@@ -197,28 +213,29 @@ function CodeInterpreter({
197213
)
198214

199215
return (
200-
<div className={`flex items-end whitespace-pre-wrap ${chart && 'w-[180px] h-[28px]'}`}>
216+
<div className={`flex items-end whitespace-pre-wrap flex-nowrap ${chart && 'w-[180px] h-[28px]'}`}>
201217
{show_results}
202218
{chart && (
203-
<div className=''>
204-
<RadioGroup
205-
orientation='vertical'
206-
value={currentView}>
207-
<RadioGroup.Item
208-
label='Table'
209-
onClick={(): void => {
210-
setCurrentView(DefaultView.Table)
211-
}}
212-
value={DefaultView.Table}
213-
/>
214-
<RadioGroup.Item
215-
label='Chart'
216-
onClick={(): void => {
217-
setCurrentView(DefaultView.Chart)
218-
}}
219-
value={DefaultView.Chart}
220-
/>
221-
</RadioGroup>
219+
<div className='flex-nowrap'>
220+
<RadioGroup
221+
orientation='horizontal'
222+
style={{'flexWrap': 'nowrap'}}
223+
value={currentView}>
224+
<RadioGroup.Item
225+
label='Table'
226+
onClick={(): void => {
227+
setCurrentView(DefaultView.Table)
228+
}}
229+
value={DefaultView.Table}
230+
/>
231+
<RadioGroup.Item
232+
label='Chart'
233+
onClick={(): void => {
234+
setCurrentView(DefaultView.Chart)
235+
}}
236+
value={DefaultView.Chart}
237+
/>
238+
</RadioGroup>
222239
</div>
223240
)}
224241

@@ -227,16 +244,20 @@ function CodeInterpreter({
227244
}
228245
}
229246

247+
const windowWidth = useWindowWidth()
248+
230249
const runButton = () => {
250+
231251
if (runnable) {
232252
return (
233253
<div className='flex justify-between'>
234-
<div className='flex items-center'>
254+
<div className='flex items-center flex-nowrap'>
235255
<div className='flex items-center'>{hideTableResultButton()}</div>
236256
<div className='flex items-end min-h-[28px]'>
237257
{show_statistics && results?.response?.statistics && (
238-
<div className={`whitespace-pre-wrap text-[12px] mx-auto italic ${chart ? 'ml-[8px]' : ''}`}>
239-
{`Read ${formatReadableRows(results.response.statistics.rows_read)} rows and ${formatBytes(results.response.statistics.bytes_read)} in ${roundToDynamicPrecision(results.response.statistics.elapsed)} secs`}
258+
<div className={`whitespace-pre-wrap text-[${windowWidth > 600 ? '12': '10'}px] mx-auto italic ${chart ? 'ml-[8px]' : ''}`}>
259+
{ windowWidth > 600 ? `Read ${formatReadableRows(results.response.statistics.rows_read)} rows and ${formatBytes(results.response.statistics.bytes_read)} in ${roundToDynamicPrecision(results.response.statistics.elapsed)} secs` :
260+
`Read ${formatReadableRows(results.response.statistics.rows_read)} rows in ${roundToDynamicPrecision(results.response.statistics.elapsed)} secs` }
240261
</div>
241262
)}
242263
</div>

0 commit comments

Comments
 (0)