33 * License: MS-RSL – see LICENSE.md for details
44 */
55
6+ // cspell:ignore Questionmark
7+
68declare let DEBUG ;
79
810import { Alert , Button , Form , Modal , Popconfirm , Switch , Table } from "antd" ;
@@ -13,12 +15,14 @@ import { Col, Row } from "@cocalc/frontend/antd-bootstrap";
1315import { CSS , ProjectActions , redux } from "@cocalc/frontend/app-framework" ;
1416import { A , Loading , Tip } from "@cocalc/frontend/components" ;
1517import { SiteName } from "@cocalc/frontend/customize" ;
18+ import { field_cmp , seconds2hms } from "@cocalc/util/misc" ;
19+ import { COLORS } from "@cocalc/util/theme" ;
1620import {
1721 Process ,
1822 ProjectInfo as ProjectInfoType ,
1923} from "@cocalc/util/types/project-info/types" ;
20- import { field_cmp , seconds2hms } from "@cocalc/util/misc " ;
21- import { COLORS } from "@cocalc/util/theme " ;
24+ import { useProjectContext } from "../context " ;
25+ import { ROOT_STYLE } from "../servers/consts " ;
2226import { RestartProject } from "../settings/restart-project" ;
2327import {
2428 AboutContent ,
@@ -30,7 +34,6 @@ import {
3034} from "./components" ;
3135import { CGroupInfo , DUState , PTStats , ProcessRow } from "./types" ;
3236import { DETAILS_BTN_TEXT , SSH_KEYS_DOC } from "./utils" ;
33- import { ROOT_STYLE } from "../servers/consts" ;
3437
3538interface Props {
3639 any_alerts : ( ) => boolean ;
@@ -91,46 +94,41 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
9194 onCellProps,
9295 } = props ;
9396
97+ const { contentSize } = useProjectContext ( ) ;
98+
9499 const problemsRef = useRef < HTMLDivElement > ( null ) ;
95100 const cgroupRef = useRef < HTMLDivElement > ( null ) ;
96101 const headerRef = useRef < HTMLDivElement > ( null ) ;
97102 const explanationRef = useRef < HTMLDivElement > ( null ) ;
98- const tableContainerRef = useRef < HTMLDivElement > ( null ) ;
103+ const generalStatusRef = useRef < HTMLDivElement > ( null ) ;
99104 const [ tableHeight , setTableHeight ] = useState < number > ( 400 ) ;
100105
101106 useEffect ( ( ) => {
102107 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+ const parentHeight = contentSize . height ;
109+ if ( parentHeight === 0 ) return ; // Wait until contentSize is measured
108110
109- const parentHeight = parentContainer . getBoundingClientRect ( ) . height ;
110111 let usedHeight = 0 ;
111112
112113 // Add height of ProjectProblems component
113- if ( problemsRef . current ) {
114- usedHeight += problemsRef . current . offsetHeight ;
115- }
114+ usedHeight += problemsRef . current ?. offsetHeight ?? 0 ;
116115
117116 // Add height of CGroup component
118- if ( cgroupRef . current ) {
119- usedHeight += cgroupRef . current . offsetHeight ;
120- }
117+ usedHeight += cgroupRef . current ?. offsetHeight ?? 0 ;
121118
122119 // Add height of header row
123- if ( headerRef . current ) {
124- usedHeight += headerRef . current . offsetHeight ;
125- }
120+ usedHeight += headerRef . current ?. offsetHeight ?? 0 ;
126121
127122 // Add height of explanation row if visible
128- if ( explanationRef . current ) {
129- usedHeight += explanationRef . current . offsetHeight ;
123+ usedHeight += explanationRef . current ?. offsetHeight ?? 0 ;
124+
125+ // Add height of general status row if DEBUG is enabled
126+ if ( DEBUG ) {
127+ usedHeight += generalStatusRef . current ?. offsetHeight ?? 0 ;
130128 }
131129
132130 // Add more buffer for table header, margins, and other spacing
133- usedHeight += 120 ;
131+ usedHeight += 100 ;
134132
135133 const availableHeight = Math . max ( 300 , parentHeight - usedHeight ) ;
136134 setTableHeight ( availableHeight ) ;
@@ -141,7 +139,7 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
141139 // Recalculate on window resize
142140 window . addEventListener ( "resize" , calculateTableHeight ) ;
143141 return ( ) => window . removeEventListener ( "resize" , calculateTableHeight ) ;
144- } , [ show_explanation , ptree ] ) ;
142+ } , [ show_explanation , ptree , contentSize . height , contentSize . width ] ) ;
145143
146144 function render_help ( ) {
147145 return (
@@ -376,6 +374,7 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
376374 < Row ref = { explanationRef } > { render_explanation ( ) } </ Row >
377375 < Row >
378376 < Table < ProcessRow >
377+ key = { `table-${ contentSize . width } -${ contentSize . height } ` }
379378 dataSource = { ptree }
380379 size = { "small" }
381380 pagination = { false }
@@ -498,7 +497,7 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
498497 </ div >
499498 ) ;
500499 return (
501- < Col lg = { 8 } lgOffset = { 2 } md = { 12 } mdOffset = { 0 } >
500+ < Col md = { 12 } mdOffset = { 0 } >
502501 < Alert
503502 message = { msg }
504503 style = { { margin : "10px 0" } }
@@ -516,14 +515,16 @@ export function Full(props: Readonly<Props>): React.JSX.Element {
516515
517516 function render_general_status ( ) {
518517 return (
519- < Col md = { 12 } style = { { color : COLORS . GRAY } } >
520- Timestamp:{ " " }
521- { info ?. timestamp != null ? (
522- < code > { new Date ( info . timestamp ) . toISOString ( ) } </ code >
523- ) : (
524- "no timestamp"
525- ) } { " " }
526- | Status: < code > { status } </ code >
518+ < Col md = { 12 } >
519+ < div ref = { generalStatusRef } style = { { color : COLORS . GRAY } } >
520+ Timestamp:{ " " }
521+ { info ?. timestamp != null ? (
522+ < code > { new Date ( info . timestamp ) . toISOString ( ) } </ code >
523+ ) : (
524+ "no timestamp"
525+ ) } { " " }
526+ | Status: < code > { status } </ code >
527+ </ div >
527528 </ Col >
528529 ) ;
529530 }
0 commit comments