From b4b6c214cbf13145333ce80c2cbca91c9c373065 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Sun, 16 Jun 2019 20:18:26 +0200 Subject: [PATCH] Open/close chart panel automatically --- app/src/components/Layout/ContentView.tsx | 86 ++++++++++++++----- .../Sidebar/CodeDiff/ChartPreview.tsx | 1 + 2 files changed, 67 insertions(+), 20 deletions(-) diff --git a/app/src/components/Layout/ContentView.tsx b/app/src/components/Layout/ContentView.tsx index 30d1152..c436dd3 100644 --- a/app/src/components/Layout/ContentView.tsx +++ b/app/src/components/Layout/ContentView.tsx @@ -1,17 +1,51 @@ import * as React from 'react' +import ChartPanel from '../ChartPanel' import ReactSplitPane from 'react-split-pane' 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 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 [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 (
- - -
- -
-
+ + + + + +
+ +
+
+
) } + +const mapStateToProps = (state: AppState) => { + return { + chartPanelItems: state.charts.get('charts'), + } +} + +export default connect(mapStateToProps)(ContentView) diff --git a/app/src/components/Sidebar/CodeDiff/ChartPreview.tsx b/app/src/components/Sidebar/CodeDiff/ChartPreview.tsx index bce0371..def73e9 100644 --- a/app/src/components/Sidebar/CodeDiff/ChartPreview.tsx +++ b/app/src/components/Sidebar/CodeDiff/ChartPreview.tsx @@ -26,6 +26,7 @@ function ChartPreview(props: Props) { topic: props.treeNode.path(), dotPath: props.literal.path, }) + setOpen(false) }, [props.literal.path, props.treeNode]) const mouseOver = React.useCallback(() => {