55
66declare let DEBUG ;
77
8- import { InfoCircleOutlined , ScheduleOutlined } from "@ant-design/icons" ;
98import { Alert , Button , Form , Modal , Popconfirm , Switch , Table } from "antd" ;
9+ import { useEffect , useRef , useState } from "react" ;
10+
11+ import { InfoCircleOutlined , ScheduleOutlined } from "@ant-design/icons" ;
1012import { Col , Row } from "@cocalc/frontend/antd-bootstrap" ;
1113import { CSS , ProjectActions , redux } from "@cocalc/frontend/app-framework" ;
1214import { A , Loading , Tip } from "@cocalc/frontend/components" ;
@@ -89,6 +91,58 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
8991 onCellProps,
9092 } = props ;
9193
94+ const problemsRef = useRef < HTMLDivElement > ( null ) ;
95+ const cgroupRef = useRef < HTMLDivElement > ( null ) ;
96+ const headerRef = useRef < HTMLDivElement > ( null ) ;
97+ const explanationRef = useRef < HTMLDivElement > ( null ) ;
98+ const tableContainerRef = useRef < HTMLDivElement > ( null ) ;
99+ const [ tableHeight , setTableHeight ] = useState < number > ( 400 ) ;
100+
101+ useEffect ( ( ) => {
102+ const calculateTableHeight = ( ) => {
103+ // Find the parent container with class "smc-vfill"
104+ let parentContainer = headerRef . current ?. closest (
105+ ".smc-vfill" ,
106+ ) as HTMLElement ;
107+ if ( ! parentContainer ) return ;
108+
109+ const parentHeight = parentContainer . getBoundingClientRect ( ) . height ;
110+ let usedHeight = 0 ;
111+
112+ // Add height of ProjectProblems component
113+ if ( problemsRef . current ) {
114+ usedHeight += problemsRef . current . offsetHeight ;
115+ }
116+
117+ // Add height of CGroup component
118+ if ( cgroupRef . current ) {
119+ usedHeight += cgroupRef . current . offsetHeight ;
120+ }
121+
122+ // Add height of header row
123+ if ( headerRef . current ) {
124+ usedHeight += headerRef . current . offsetHeight ;
125+ }
126+
127+ // Add height of explanation row if visible
128+ if ( explanationRef . current ) {
129+ usedHeight += explanationRef . current . offsetHeight ;
130+ }
131+
132+ // Add more buffer for table header, margins, and other spacing
133+ usedHeight += 120 ;
134+
135+ const availableHeight = Math . max ( 300 , parentHeight - usedHeight ) ;
136+ setTableHeight ( availableHeight ) ;
137+ } ;
138+
139+ calculateTableHeight ( ) ;
140+
141+ // Recalculate on window resize
142+ window . addEventListener ( "resize" , calculateTableHeight ) ;
143+ return ( ) => window . removeEventListener ( "resize" , calculateTableHeight ) ;
144+ } , [ show_explanation , ptree ] ) ;
145+
92146 function render_help ( ) {
93147 return (
94148 < Form . Item label = "Help:" >
@@ -295,11 +349,16 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
295349 </ Tip >
296350 ) ;
297351
298- const table_style : CSS = { marginBottom : "2rem" } ;
352+ const table_style : CSS = {
353+ marginBottom : "2rem" ,
354+ } ;
299355
300356 return (
301357 < >
302- < Row style = { { marginBottom : "10px" , marginTop : "20px" } } >
358+ < Row
359+ ref = { headerRef }
360+ style = { { marginBottom : "10px" , marginTop : "20px" } }
361+ >
303362 < Col md = { 9 } >
304363 < Form layout = "inline" >
305364 < Form . Item label = "Table of Processes" />
@@ -314,13 +373,13 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
314373 </ Form >
315374 </ Col >
316375 </ Row >
317- < Row > { render_explanation ( ) } </ Row >
376+ < Row ref = { explanationRef } > { render_explanation ( ) } </ Row >
318377 < Row >
319378 < Table < ProcessRow >
320379 dataSource = { ptree }
321380 size = { "small" }
322381 pagination = { false }
323- scroll = { { y : "65vh" } }
382+ scroll = { { y : tableHeight } }
324383 style = { table_style }
325384 expandable = { expandable }
326385 rowSelection = { rowSelection }
@@ -472,15 +531,19 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
472531 function render_body ( ) {
473532 return (
474533 < >
475- < ProjectProblems project_status = { project_status } />
476- < CGroup
477- have_cgroup = { info ?. cgroup != null }
478- cg_info = { cg_info }
479- disk_usage = { disk_usage }
480- pt_stats = { pt_stats }
481- start_ts = { start_ts }
482- project_status = { project_status }
483- />
534+ < div ref = { problemsRef } >
535+ < ProjectProblems project_status = { project_status } />
536+ </ div >
537+ < div ref = { cgroupRef } >
538+ < CGroup
539+ have_cgroup = { info ?. cgroup != null }
540+ cg_info = { cg_info }
541+ disk_usage = { disk_usage }
542+ pt_stats = { pt_stats }
543+ start_ts = { start_ts }
544+ project_status = { project_status }
545+ />
546+ </ div >
484547 { render_top ( ) }
485548 { render_modals ( ) }
486549 { DEBUG && render_general_status ( ) }
0 commit comments