From 469d7f0e143f77c75b658455ed109c9d9a4b6513 Mon Sep 17 00:00:00 2001 From: arunvjn <32433245+arunvjn@users.noreply.github.com> Date: Tue, 22 Jun 2021 09:23:53 +0530 Subject: [PATCH] Fix to enable scroll in sql query results. (#5091) * Dynamically adjust table virtualizer's height according to resizer --- .../Debugger/Resizer/index.tsx | 7 +++++++ app/client/src/constants/DefaultTheme.tsx | 2 ++ .../Editor/QueryEditor/EditorJSONtoForm.tsx | 12 +++++++++-- .../src/pages/Editor/QueryEditor/Table.tsx | 21 ++++++++++++++----- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/client/src/components/editorComponents/Debugger/Resizer/index.tsx b/app/client/src/components/editorComponents/Debugger/Resizer/index.tsx index 853cb5ec72..98ed9f4cb8 100644 --- a/app/client/src/components/editorComponents/Debugger/Resizer/index.tsx +++ b/app/client/src/components/editorComponents/Debugger/Resizer/index.tsx @@ -20,6 +20,7 @@ const Top = styled.div` type ResizerProps = { panelRef: RefObject; + setContainerDimensions?: (height: number) => void; }; function Resizer(props: ResizerProps) { @@ -41,9 +42,15 @@ function Resizer(props: ResizerProps) { updatedHeight > minHeight ) { panel.style.height = `${height - movementY}px`; + props.setContainerDimensions && + props.setContainerDimensions(height - movementY); } }; + useEffect(() => { + handleResize(0); + }, []); + useEffect(() => { const handleMouseMove = (e: MouseEvent) => { e.preventDefault(); diff --git a/app/client/src/constants/DefaultTheme.tsx b/app/client/src/constants/DefaultTheme.tsx index f647e9200b..7d1b9972ed 100644 --- a/app/client/src/constants/DefaultTheme.tsx +++ b/app/client/src/constants/DefaultTheme.tsx @@ -361,6 +361,7 @@ export type Theme = { }; }; pageContentWidth: number; + tabPanelHeight: number; alert: Record; lightningMenu: { [Skin.DARK]: { @@ -2388,6 +2389,7 @@ export const theme: Theme = { }, }, pageContentWidth: 1224, + tabPanelHeight: 34, alert: { info: { color: Colors.AZURE_RADIANCE, diff --git a/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx b/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx index 004f287434..da19839a2d 100644 --- a/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx +++ b/app/client/src/pages/Editor/QueryEditor/EditorJSONtoForm.tsx @@ -386,6 +386,9 @@ export function EditorJSONtoForm(props: Props) { let hintMessages: Array = []; const panelRef: RefObject = useRef(null); const [selectedIndex, setSelectedIndex] = useState(0); + const [tableBodyHeight, setTableBodyHeightHeight] = useState( + window.innerHeight, + ); if (executedQueryData) { if (!executedQueryData.isExecutionSuccess) { @@ -529,7 +532,7 @@ export function EditorJSONtoForm(props: Props) { )} {output && (isTableResponse ? ( - +
) : ( ))} @@ -688,7 +691,12 @@ export function EditorJSONtoForm(props: Props) { - + + setTableBodyHeightHeight(height) + } + /> {output && !!output.length && ( diff --git a/app/client/src/pages/Editor/QueryEditor/Table.tsx b/app/client/src/pages/Editor/QueryEditor/Table.tsx index eb599786c3..89c226ad84 100644 --- a/app/client/src/pages/Editor/QueryEditor/Table.tsx +++ b/app/client/src/pages/Editor/QueryEditor/Table.tsx @@ -1,5 +1,5 @@ import React from "react"; -import styled from "styled-components"; +import styled, { withTheme } from "styled-components"; import { FixedSizeList } from "react-window"; import { useTable, useBlockLayout } from "react-table"; @@ -9,9 +9,12 @@ import { getType, Types } from "utils/TypeHelpers"; import ErrorBoundary from "components/editorComponents/ErrorBoundry"; import { CellWrapper } from "components/designSystems/appsmith/TableComponent/TableStyledWrappers"; import AutoToolTipComponent from "components/designSystems/appsmith/TableComponent/AutoToolTipComponent"; +import { Theme } from "constants/DefaultTheme"; interface TableProps { data: Record[]; + tableBodyHeight?: number; + theme: Theme; } const TABLE_SIZES = { @@ -19,6 +22,7 @@ const TABLE_SIZES = { TABLE_HEADER_HEIGHT: 42, ROW_HEIGHT: 40, ROW_FONT_SIZE: 14, + SCROLL_SIZE: 20, }; export const TableWrapper = styled.div` @@ -44,13 +48,13 @@ export const TableWrapper = styled.div` background: ${Colors.ATHENS_GRAY_DARKER}; display: table; width: 100%; + height: 100%; .thead, .tbody { overflow: hidden; } .tbody { - overflow-y: scroll; - height: 100%; + height: calc(100% - ${TABLE_SIZES.COLUMN_HEADER_HEIGHT}px); .tr { width: 100%; } @@ -201,6 +205,13 @@ function Table(props: TableProps) { return []; }, [data]); + const tableBodyHeightComputed = + (props.tableBodyHeight || window.innerHeight) - + TABLE_SIZES.COLUMN_HEADER_HEIGHT - + props.theme.tabPanelHeight - + TABLE_SIZES.SCROLL_SIZE - + 2 * props.theme.spaces[5]; //top and bottom padding + const defaultColumn = React.useMemo( () => ({ width: 170, @@ -292,7 +303,7 @@ function Table(props: TableProps) {