Skip to content

Commit 93d5c33

Browse files
fix: time ranger picker dropdown resize according to query builder height (#4699)
1 parent 562b3ff commit 93d5c33

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/shared/components/TimeRangeDropdown.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface Props {
4040
timeZone: TimeZone
4141
onSetTimeRange: (timeRange: TimeRange) => void
4242
width?: number
43+
maxHeight?: number
4344
}
4445

4546
interface State {
@@ -58,6 +59,8 @@ class TimeRangeDropdown extends PureComponent<Props, State> {
5859
public render() {
5960
const timeRange = this.timeRange
6061
const timeRangeLabel = getTimeRangeLabel(timeRange, this.props.timeZone)
62+
const {maxHeight} = this.props
63+
6164
return (
6265
<>
6366
<Popover
@@ -98,6 +101,7 @@ class TimeRangeDropdown extends PureComponent<Props, State> {
98101
<Dropdown.Menu
99102
onCollapse={onCollapse}
100103
style={{width: `${this.dropdownWidth}px`}}
104+
maxHeight={maxHeight}
101105
>
102106
<Dropdown.Divider
103107
key="Time Range"

src/timeMachine/components/Queries.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@ type RouterProps = RouteComponentProps<{
4747
dashboardID: string
4848
orgID: string
4949
}>
50-
type Props = ReduxProps & RouterProps
50+
51+
type OwnProps = {
52+
maxHeight: number
53+
}
54+
55+
type Props = ReduxProps & RouterProps & OwnProps
5156

5257
class TimeMachineQueries extends PureComponent<Props> {
5358
public render() {
54-
const {timeRange, isInCheckOverlay, activeQuery} = this.props
59+
const {timeRange, isInCheckOverlay, activeQuery, maxHeight} = this.props
60+
const dropdownMaxHeight = maxHeight * 0.5
5561

5662
return (
5763
<div className="time-machine-queries">
@@ -72,6 +78,7 @@ class TimeMachineQueries extends PureComponent<Props> {
7278
<TimeRangeDropdown
7379
timeRange={timeRange}
7480
onSetTimeRange={this.handleSetTimeRange}
81+
maxHeight={dropdownMaxHeight}
7582
/>
7683
<TimeMachineQueriesSwitcher />
7784
</>

src/timeMachine/components/TimeMachine.tsx

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {useState, FunctionComponent} from 'react'
2+
import React, {useState, FunctionComponent, useRef} from 'react'
33
import {useSelector} from 'react-redux'
44
import classnames from 'classnames'
55

@@ -26,11 +26,15 @@ const TimeMachine: FunctionComponent = () => {
2626
'time-machine--split': isViewingVisOptions,
2727
})
2828

29-
let bottomContents: JSX.Element = null
30-
if (activeTab === 'alerting') {
31-
bottomContents = <TimeMachineAlerting />
32-
} else if (activeTab === 'queries') {
33-
bottomContents = <TimeMachineQueries />
29+
const bottomContentRef = useRef(null)
30+
31+
const bottomContents = (): JSX.Element => {
32+
if (activeTab === 'alerting') {
33+
return <TimeMachineAlerting />
34+
} else if (activeTab === 'queries') {
35+
const bottomContentsMaxHeight = bottomContentRef.current?.clientHeight
36+
return <TimeMachineQueries maxHeight={bottomContentsMaxHeight} />
37+
}
3438
}
3539

3640
return (
@@ -53,8 +57,11 @@ const TimeMachine: FunctionComponent = () => {
5357
className="time-machine--bottom"
5458
data-testid="time-machine--bottom"
5559
>
56-
<div className="time-machine--bottom-contents">
57-
{bottomContents}
60+
<div
61+
className="time-machine--bottom-contents"
62+
ref={bottomContentRef}
63+
>
64+
{bottomContents()}
5865
</div>
5966
</div>
6067
</ErrorBoundary>

0 commit comments

Comments
 (0)