@@ -21,7 +21,7 @@ import {
21
21
useTableColumnSizing_unstable ,
22
22
useTableFeatures ,
23
23
} from "@fluentui/react-components" ;
24
- import { useContext , useRef , useState } from "react" ;
24
+ import { useContext , useEffect , useRef , useState } from "react" ;
25
25
import { OpenFilled } from "@fluentui/react-icons" ;
26
26
import { QueryResultContext } from "./queryResultStateProvider" ;
27
27
import * as qr from "../../../sharedInterfaces/queryResult" ;
@@ -106,6 +106,33 @@ export const QueryResultPane = () => {
106
106
renderHeaderCell : ( ) => < > { MESSAGE } </ > ,
107
107
} ) ,
108
108
] ;
109
+ const gridParentRef = useRef < HTMLDivElement > ( null ) ;
110
+ const ribbonRef = useRef < HTMLDivElement > ( null ) ;
111
+ // Resize grid when parent element resizes
112
+ useEffect ( ( ) => {
113
+ const gridParent = gridParentRef . current ;
114
+ if ( ! gridParent ) {
115
+ return ;
116
+ }
117
+ const observer = new ResizeObserver ( ( ) => {
118
+ if ( ! gridRef . current ) {
119
+ return ;
120
+ }
121
+ if ( ! ribbonRef . current ) {
122
+ return ;
123
+ }
124
+ if ( gridParent . clientWidth && gridParent . clientHeight ) {
125
+ gridRef . current . resizeGrid (
126
+ gridParent . clientWidth ,
127
+ gridParent . clientHeight -
128
+ ribbonRef . current . clientHeight -
129
+ 5 ,
130
+ ) ;
131
+ }
132
+ } ) ;
133
+ observer . observe ( gridParent ) ;
134
+ return ( ) => observer . disconnect ( ) ;
135
+ } , [ ] ) ;
109
136
const [ columns ] =
110
137
useState < TableColumnDefinition < qr . IMessage > [ ] > ( columnsDef ) ;
111
138
const items = metadata ?. messages ?? [ ] ;
@@ -145,8 +172,8 @@ export const QueryResultPane = () => {
145
172
const gridRef = useRef < SlickGridHandle > ( null ) ;
146
173
147
174
return (
148
- < div className = { classes . root } >
149
- < div className = { classes . ribbon } >
175
+ < div className = { classes . root } ref = { gridParentRef } >
176
+ < div className = { classes . ribbon } ref = { ribbonRef } >
150
177
< TabList
151
178
size = "medium"
152
179
selectedValue = { metadata . tabStates ! . resultPaneTab }
0 commit comments