import * as React from 'react' import ChartPanel from '../ChartPanel' import ReactSplitPane from 'react-split-pane' import Tree from '../Tree/Tree' import { AppState } from '../../reducers' import { ChartParameters } from '../../reducers/Charts' import { connect } from 'react-redux' import { List } from 'immutable' import { Sidebar } from '../Sidebar' import ReactResizeDetector from 'react-resize-detector' interface Props { heightProperty: any paneDefaults: any connectionId?: string chartPanelItems: List } function ContentView(props: Props) { const [height, setHeight] = React.useState('100%') const [detectedHeight, setDetectedHeight] = React.useState(0) const detectSize = React.useCallback((width, newHeight) => { setDetectedHeight(newHeight) }, []) const closeDrawerCompletelyIfItSitsOnTheEdge = React.useCallback(() => { if (detectedHeight < 30) { setHeight('100%') } }, [detectedHeight]) // Open chart panel on start and when a new chart is added but the panel is closed React.useEffect(() => { const almostClosed = !isNaN(height as any) && detectedHeight < 30 if ((!height || height === '100%' || almostClosed) && props.chartPanelItems.count() > 0) { setHeight('calc(100% - 250px)') } if (props.chartPanelItems.count() === 0) { setHeight('100%') } }, [props.chartPanelItems]) return (
{/** Passing height constraints via flex options down */}
{/** Resize detector must not be in the scroll zone, it needs to detect actual available size */}
) } const mapStateToProps = (state: AppState) => { return { chartPanelItems: state.charts.get('charts'), } } export default connect(mapStateToProps)(ContentView)