Open/close chart panel automatically
This commit is contained in:
@@ -1,17 +1,51 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
|
import ChartPanel from '../ChartPanel'
|
||||||
import ReactSplitPane from 'react-split-pane'
|
import ReactSplitPane from 'react-split-pane'
|
||||||
import Tree from '../Tree/Tree'
|
import Tree from '../Tree/Tree'
|
||||||
import ChartPanel from '../ChartPanel'
|
import { AppState } from '../../reducers'
|
||||||
|
import { ChartParameters } from '../../reducers/Charts'
|
||||||
|
import { connect } from 'react-redux'
|
||||||
|
import { List } from 'immutable'
|
||||||
import { Sidebar } from '../Sidebar'
|
import { Sidebar } from '../Sidebar'
|
||||||
|
import ReactResizeDetector from 'react-resize-detector'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
heightProperty: any
|
||||||
|
paneDefaults: any
|
||||||
|
connectionId?: string
|
||||||
|
chartPanelItems: List<ChartParameters>
|
||||||
|
}
|
||||||
|
|
||||||
|
function ContentView(props: Props) {
|
||||||
|
const [height, setHeight] = React.useState<string | number>('100%')
|
||||||
|
const [detectedHeight, setDetectedHeight] = React.useState(0)
|
||||||
|
const [chatPanelItemCount, setChartPanelItemCount] = React.useState(props.chartPanelItems.count())
|
||||||
|
const detectSize = React.useCallback((width, height) => {
|
||||||
|
console.log(width, height)
|
||||||
|
setDetectedHeight(height)
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
// Open chart panel on start and when a new chart is added but the panel is closed
|
||||||
|
React.useEffect(() => {
|
||||||
|
const almostAtFullHeight = !isNaN(height as any) && Math.abs(detectedHeight - (height as number)) < 20
|
||||||
|
if ((!height || height === '100%' || almostAtFullHeight) && props.chartPanelItems.count() > 0) {
|
||||||
|
setHeight('calc(100% - 250px)')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (props.chartPanelItems.count() === 0) {
|
||||||
|
setHeight('100%')
|
||||||
|
}
|
||||||
|
|
||||||
|
setChartPanelItemCount(props.chartPanelItems.count())
|
||||||
|
}, [props.chartPanelItems])
|
||||||
|
|
||||||
export default function ContentView(props: { heightProperty: any; paneDefaults: any; connectionId: any }) {
|
|
||||||
const [height, setHeight] = React.useState(0)
|
|
||||||
return (
|
return (
|
||||||
<div className={props.paneDefaults}>
|
<div className={props.paneDefaults}>
|
||||||
<ReactSplitPane
|
<ReactSplitPane
|
||||||
step={10}
|
step={10}
|
||||||
split="horizontal"
|
split="horizontal"
|
||||||
minSize={0}
|
minSize={0}
|
||||||
|
size={height}
|
||||||
defaultSize={'100%'}
|
defaultSize={'100%'}
|
||||||
allowResize={true}
|
allowResize={true}
|
||||||
style={{ height: 'calc(100vh - 64px)' }}
|
style={{ height: 'calc(100vh - 64px)' }}
|
||||||
@@ -19,25 +53,37 @@ export default function ContentView(props: { heightProperty: any; paneDefaults:
|
|||||||
pane2Style={{ maxWidth: '100%', overflow: 'hidden auto' }}
|
pane2Style={{ maxWidth: '100%', overflow: 'hidden auto' }}
|
||||||
onChange={setHeight}
|
onChange={setHeight}
|
||||||
>
|
>
|
||||||
<ReactSplitPane
|
<span>
|
||||||
step={20}
|
<ReactResizeDetector handleHeight={true} onResize={detectSize} />
|
||||||
primary="second"
|
|
||||||
className={props.heightProperty}
|
<ReactSplitPane
|
||||||
split="vertical"
|
step={20}
|
||||||
minSize={250}
|
primary="second"
|
||||||
defaultSize={500}
|
className={props.heightProperty}
|
||||||
allowResize={true}
|
split="vertical"
|
||||||
style={{ height: '100%' }}
|
minSize={250}
|
||||||
pane1Style={{ overflowX: 'hidden' }}
|
defaultSize={500}
|
||||||
resizerStyle={{ height: '100%' }}
|
allowResize={true}
|
||||||
>
|
style={{ height: '100%' }}
|
||||||
<Tree />
|
pane1Style={{ overflowX: 'hidden' }}
|
||||||
<div className={props.paneDefaults} style={{ height: '100%', overflowY: 'auto', overflowX: 'hidden' }}>
|
resizerStyle={{ height: '100%' }}
|
||||||
<Sidebar connectionId={props.connectionId} />
|
>
|
||||||
</div>
|
<Tree />
|
||||||
</ReactSplitPane>
|
<div className={props.paneDefaults} style={{ height: '100%', overflowY: 'auto', overflowX: 'hidden' }}>
|
||||||
|
<Sidebar connectionId={props.connectionId} />
|
||||||
|
</div>
|
||||||
|
</ReactSplitPane>
|
||||||
|
</span>
|
||||||
<ChartPanel />
|
<ChartPanel />
|
||||||
</ReactSplitPane>
|
</ReactSplitPane>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state: AppState) => {
|
||||||
|
return {
|
||||||
|
chartPanelItems: state.charts.get('charts'),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(ContentView)
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ function ChartPreview(props: Props) {
|
|||||||
topic: props.treeNode.path(),
|
topic: props.treeNode.path(),
|
||||||
dotPath: props.literal.path,
|
dotPath: props.literal.path,
|
||||||
})
|
})
|
||||||
|
setOpen(false)
|
||||||
}, [props.literal.path, props.treeNode])
|
}, [props.literal.path, props.treeNode])
|
||||||
|
|
||||||
const mouseOver = React.useCallback(() => {
|
const mouseOver = React.useCallback(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user