make data tables horizontally scrollable if needed

Summary:
Changelog: most data tables allow for horizontal scrolling now if they run out of space

This diff introduces support for horizontal scrolling in datatables. Originally thought about making this a view option, but doing automatically works actually quite fine. By default the columns resize as they did, but if either a column is made bigger or the window is so small no space is left, a horizontal scrollbar can be used.

This adresses several usability issues reported in GH / workplace

fixes https://github.com/facebook/flipper/issues/2608

Reviewed By: antonk52

Differential Revision: D33368216

fbshipit-source-id: 206c761a5873cf0396af091f2cbdedc3e638afac
This commit is contained in:
Michel Weststrate
2022-01-04 08:31:14 -08:00
committed by Facebook GitHub Bot
parent 9267a19c89
commit 80bb372920
5 changed files with 51 additions and 25 deletions

View File

@@ -204,6 +204,7 @@ export const DataList: (<T extends object>(
enableArrow: true, enableArrow: true,
enableContextMenu: false, enableContextMenu: false,
enableMultiSelect: false, enableMultiSelect: false,
enableHorizontalScroll: false,
idAttribute: 'id', idAttribute: 'id',
titleAttribute: 'title', titleAttribute: 'title',
descriptionAttribute: 'description', descriptionAttribute: 'description',

View File

@@ -10,13 +10,7 @@
import React, {CSSProperties, forwardRef} from 'react'; import React, {CSSProperties, forwardRef} from 'react';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import {Container} from './Container'; import {Container} from './Container';
import { import {PaddingProps, Spacing} from './theme';
normalizePadding,
normalizeSpace,
PaddingProps,
Spacing,
theme,
} from './theme';
import {renderSplitLayout} from './renderSplitLayout'; import {renderSplitLayout} from './renderSplitLayout';

View File

@@ -57,6 +57,7 @@ interface DataTableBaseProps<T = any> {
columns: DataTableColumn<T>[]; columns: DataTableColumn<T>[];
enableSearchbar?: boolean; enableSearchbar?: boolean;
enableAutoScroll?: boolean; enableAutoScroll?: boolean;
enableHorizontalScroll?: boolean;
enableColumnHeaders?: boolean; enableColumnHeaders?: boolean;
enableMultiSelect?: boolean; enableMultiSelect?: boolean;
enableContextMenu?: boolean; enableContextMenu?: boolean;
@@ -483,6 +484,10 @@ export function DataTable<T extends object>(
extraActions={props.extraActions} extraActions={props.extraActions}
/> />
)} )}
</Layout.Container>
);
const columnHeaders = (
<Layout.Container>
{props.enableColumnHeaders && ( {props.enableColumnHeaders && (
<TableHead <TableHead
visibleColumns={visibleColumns} visibleColumns={visibleColumns}
@@ -502,9 +507,9 @@ export function DataTable<T extends object>(
props.onRenderEmpty === undefined props.onRenderEmpty === undefined
? props.onRenderEmpty ? props.onRenderEmpty
: props.onRenderEmpty; : props.onRenderEmpty;
const mainSection = props.scrollable ? ( let mainSection: JSX.Element;
<Layout.Top> if (props.scrollable) {
{header} const dataSourceRenderer = (
<DataSourceRendererVirtual<T, TableRowRenderContext<T>> <DataSourceRendererVirtual<T, TableRowRenderContext<T>>
dataSource={dataSource} dataSource={dataSource}
autoScroll={tableState.autoScroll && !dragging.current} autoScroll={tableState.autoScroll && !dragging.current}
@@ -518,21 +523,44 @@ export function DataTable<T extends object>(
onUpdateAutoScroll={onUpdateAutoScroll} onUpdateAutoScroll={onUpdateAutoScroll}
emptyRenderer={emptyRenderer} emptyRenderer={emptyRenderer}
/> />
</Layout.Top> );
) : (
<Layout.Container> mainSection = props.enableHorizontalScroll ? (
{header} <Layout.Top>
<DataSourceRendererStatic<T, TableRowRenderContext<T>> {header}
dataSource={dataSource} <Layout.ScrollContainer horizontal vertical={false}>
useFixedRowHeight={!tableState.usesWrapping} <Layout.Top>
defaultRowHeight={DEFAULT_ROW_HEIGHT} {columnHeaders}
context={renderingConfig} {dataSourceRenderer}
itemRenderer={itemRenderer} </Layout.Top>
onKeyDown={onKeyDown} </Layout.ScrollContainer>
emptyRenderer={emptyRenderer} </Layout.Top>
/> ) : (
</Layout.Container> <Layout.Top>
); <div>
{header}
{columnHeaders}
</div>
{dataSourceRenderer}
</Layout.Top>
);
} else {
mainSection = (
<Layout.Container>
{header}
{columnHeaders}
<DataSourceRendererStatic<T, TableRowRenderContext<T>>
dataSource={dataSource}
useFixedRowHeight={!tableState.usesWrapping}
defaultRowHeight={DEFAULT_ROW_HEIGHT}
context={renderingConfig}
itemRenderer={itemRenderer}
onKeyDown={onKeyDown}
emptyRenderer={emptyRenderer}
/>
</Layout.Container>
);
}
return ( return (
<Layout.Container grow={props.scrollable}> <Layout.Container grow={props.scrollable}>
@@ -558,6 +586,7 @@ DataTable.defaultProps = {
scrollable: true, scrollable: true,
enableSearchbar: true, enableSearchbar: true,
enableAutoScroll: false, enableAutoScroll: false,
enableHorizontalScroll: true,
enableColumnHeaders: true, enableColumnHeaders: true,
enableMultiSelect: true, enableMultiSelect: true,
enableContextMenu: true, enableContextMenu: true,

View File

@@ -227,6 +227,7 @@ export function Component() {
columns={plugin.columns} columns={plugin.columns}
enableAutoScroll enableAutoScroll
onRowStyle={getRowStyle} onRowStyle={getRowStyle}
enableHorizontalScroll={false}
extraActions={ extraActions={
plugin.isConnected ? ( plugin.isConnected ? (
<> <>

View File

@@ -40,6 +40,7 @@ export function KeyValueTable({items}: {items: KeyValueItem[]}) {
records={items} records={items}
enableSearchbar={false} enableSearchbar={false}
scrollable={false} scrollable={false}
enableHorizontalScroll={false}
onCopyRows={handleCopyRows} onCopyRows={handleCopyRows}
/> />
); );