From b98aef53fddd86d9fab98629333b6e29d4fa1924 Mon Sep 17 00:00:00 2001 From: Baptiste Arnaud Date: Fri, 10 Feb 2023 16:33:18 +0100 Subject: [PATCH] :children_crossing: (results) Remove useless scrollbars and make header sticky Closes #297 --- .../results/components/ResultsTable/Cell.tsx | 4 +- .../ResultsTable/ColumnsSettingsButton.tsx | 114 +++++++++--------- .../components/ResultsTable/HeaderRow.tsx | 18 ++- .../components/ResultsTable/ResultsTable.tsx | 19 +-- .../results/components/ResultsTable/Row.tsx | 1 + .../results/components/ResultsTable/index.tsx | 2 +- .../components/ResultsTableContainer.tsx | 13 +- 7 files changed, 90 insertions(+), 81 deletions(-) diff --git a/apps/builder/src/features/results/components/ResultsTable/Cell.tsx b/apps/builder/src/features/results/components/ResultsTable/Cell.tsx index 6e9609a8e..11da707c5 100644 --- a/apps/builder/src/features/results/components/ResultsTable/Cell.tsx +++ b/apps/builder/src/features/results/components/ResultsTable/Cell.tsx @@ -8,6 +8,7 @@ type Props = { cell: CellProps size: number isExpandButtonVisible: boolean + rowIndex: number cellIndex: number isSelected: boolean onExpandButtonClick: () => void @@ -17,6 +18,7 @@ const Cell = ({ cell, size, isExpandButtonVisible, + rowIndex, cellIndex, onExpandButtonClick, }: Props) => { @@ -25,7 +27,7 @@ const Cell = ({ key={cell.id} px="4" py="2" - border="1px" + borderWidth={rowIndex === 0 ? '0 1px 1px 1px' : '1px'} borderColor={useColorModeValue('gray.200', 'gray.700')} whiteSpace="nowrap" wordBreak="normal" diff --git a/apps/builder/src/features/results/components/ResultsTable/ColumnsSettingsButton.tsx b/apps/builder/src/features/results/components/ResultsTable/ColumnsSettingsButton.tsx index 50a0bebde..25dae657d 100644 --- a/apps/builder/src/features/results/components/ResultsTable/ColumnsSettingsButton.tsx +++ b/apps/builder/src/features/results/components/ResultsTable/ColumnsSettingsButton.tsx @@ -96,66 +96,68 @@ export const ColumnSettingsButton = ({ - - - - - Shown in table: - - - - {visibleHeaders.map((header) => ( - - ))} - - - - {draggingColumnId ? : null} - - - - - {hiddenHeaders.length > 0 && ( + + + - Hidden in table: + Shown in table: - {hiddenHeaders.map((header) => ( - - - - {header.label} - - } - size="sm" - aria-label={'Hide column'} - onClick={onEyeClick(header.id)} - /> - - ))} + + + {visibleHeaders.map((header) => ( + + ))} + + + + {draggingColumnId ? : null} + + + - )} - - + {hiddenHeaders.length > 0 && ( + + + Hidden in table: + + {hiddenHeaders.map((header) => ( + + + + {header.label} + + } + size="sm" + aria-label={'Hide column'} + onClick={onEyeClick(header.id)} + /> + + ))} + + )} + + + ) } diff --git a/apps/builder/src/features/results/components/ResultsTable/HeaderRow.tsx b/apps/builder/src/features/results/components/ResultsTable/HeaderRow.tsx index ee3337f19..c908ff95f 100644 --- a/apps/builder/src/features/results/components/ResultsTable/HeaderRow.tsx +++ b/apps/builder/src/features/results/components/ResultsTable/HeaderRow.tsx @@ -1,3 +1,4 @@ +import { colors } from '@/lib/theme' import { Box, BoxProps, chakra, useColorModeValue } from '@chakra-ui/react' import { flexRender, HeaderGroup } from '@tanstack/react-table' import React from 'react' @@ -5,10 +6,13 @@ import { TableData } from '../../types' type Props = { headerGroup: HeaderGroup + isTableScrolled: boolean } -export const HeaderRow = ({ headerGroup }: Props) => { - const borderColor = useColorModeValue('gray.200', 'gray.700') +export const HeaderRow = ({ headerGroup, isTableScrolled }: Props) => { + const borderColor = useColorModeValue(colors.gray[200], colors.gray[700]) + const backgroundColor = useColorModeValue('white', colors.gray[900]) + return ( {headerGroup.headers.map((header) => { @@ -16,14 +20,18 @@ export const HeaderRow = ({ headerGroup }: Props) => { >({}) + const [isTableScrolled, setIsTableScrolled] = useState(false) const bottomElement = useRef(null) const tableWrapper = useRef(null) @@ -197,13 +198,7 @@ export const ResultsTable = ({ } return ( - + + setIsTableScrolled((e.target as HTMLElement).scrollTop > 0) + } > {instance.getHeaderGroups().map((headerGroup) => ( - + ))} diff --git a/apps/builder/src/features/results/components/ResultsTable/Row.tsx b/apps/builder/src/features/results/components/ResultsTable/Row.tsx index 393c2b8b8..c5075a9e8 100644 --- a/apps/builder/src/features/results/components/ResultsTable/Row.tsx +++ b/apps/builder/src/features/results/components/ResultsTable/Row.tsx @@ -38,6 +38,7 @@ export const Row = ({ cell={cell} size={cell.column.getSize()} isExpandButtonVisible={isExpandButtonVisible} + rowIndex={row.index} cellIndex={cellIndex} onExpandButtonClick={onExpandButtonClick} isSelected={isSelected} diff --git a/apps/builder/src/features/results/components/ResultsTable/index.tsx b/apps/builder/src/features/results/components/ResultsTable/index.tsx index 256ba146b..e1a3eb1f4 100644 --- a/apps/builder/src/features/results/components/ResultsTable/index.tsx +++ b/apps/builder/src/features/results/components/ResultsTable/index.tsx @@ -1 +1 @@ -export { ResultsTable as SubmissionsTable } from './ResultsTable' +export { ResultsTable } from './ResultsTable' diff --git a/apps/builder/src/features/results/components/ResultsTableContainer.tsx b/apps/builder/src/features/results/components/ResultsTableContainer.tsx index d8075de42..22a261d36 100644 --- a/apps/builder/src/features/results/components/ResultsTableContainer.tsx +++ b/apps/builder/src/features/results/components/ResultsTableContainer.tsx @@ -4,7 +4,7 @@ import { LogsModal } from './LogsModal' import { useTypebot } from '@/features/editor' import { useResults } from '../ResultsProvider' import { ResultModal } from './ResultModal' -import { SubmissionsTable } from './ResultsTable' +import { ResultsTable } from './ResultsTable' export const ResultsTableContainer = () => { const { @@ -35,14 +35,7 @@ export const ResultsTableContainer = () => { setExpandedResultIndex(index) return ( - + {publishedTypebot && ( { /> {typebot && ( -