Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
Add header cell stats control toggle (#2004)
Igor Dykhta920659fff5ba
diff --git a/src/components/src/common/data-table/cell-size.ts b/src/components/src/common/data-table/cell-size.tsindex 07d5baacb..67c3a9337 100644--- a/src/components/src/common/data-table/cell-size.ts+++ b/src/components/src/common/data-table/cell-size.ts@@ -60,7 +60,7 @@ export function renderedSize({maxCellSize = 500,maxHeaderSize = 500,minCellSize = MIN_CELL_SIZE,- optionsButton = 30+ optionsButton = 44}: RenderSizeParam): {row: number; header: number} {if (!document) {return {diff --git a/src/components/src/common/data-table/header-cell.tsx b/src/components/src/common/data-table/header-cell.tsxindex 9309fd0a9..ade98f189 100644--- a/src/components/src/common/data-table/header-cell.tsx+++ b/src/components/src/common/data-table/header-cell.tsx@@ -1,4 +1,4 @@-import React, {CSSProperties} from 'react';+import React, {CSSProperties, useCallback} from 'react';import styled from 'styled-components';import classnames from 'classnames';import Button from './button';@@ -48,6 +48,7 @@ const StyledHeaderCell = styled.div`display: flex;align-items: center;overflow: hidden;+svg {margin-left: 6px;}@@ -55,6 +56,7 @@ const StyledHeaderCell = styled.div`.col-name__name {overflow: hidden;white-space: nowrap;+ text-overflow: ellipsis;}}}@@ -80,6 +82,7 @@ type HeaderCellProps = {cellInfo: CellInfo;columns: DataTableProps['columns'];isPinned?: boolean;+ showStats?: boolean;props: DataTableProps;toggleMoreOptions: (moreOptionsColumn: string) => void;moreOptionsColumn: null | string;@@ -101,6 +104,13 @@ const HeaderCellFactory = (FieldToken: React.FC<FieldTokenProps>) => {const isGhost = column.ghost;const isSorted = sortColumn[column];const firstCell = columnIndex === 0;+ const onSortTable = useCallback(() => sortTableColumn(column), [sortTableColumn, column]);+ const onToggleOptionMenu = useCallback(() => toggleMoreOptions(column), [+ toggleMoreOptions,+ column+ ]);+ const onPin = useCallback(() => pinTableColumn(column), [pinTableColumn, column]);+ const onCopy = useCallback(() => copyTableColumn(column), [copyTableColumn, column]);return (<StyledHeaderCellclassName={classnames('header-cell', {@@ -113,7 +123,7 @@ const HeaderCellFactory = (FieldToken: React.FC<FieldTokenProps>) => {onClick={e => {e.shiftKey ? sortTableColumn(column) : null;}}- onDoubleClick={() => sortTableColumn(column)}+ onDoubleClick={onSortTable}title={column}>{isGhost ? (@@ -124,7 +134,7 @@ const HeaderCellFactory = (FieldToken: React.FC<FieldTokenProps>) => {<div className="col-name"><div className="col-name__left"><div className="col-name__name">{colMeta[column].name}</div>- <Button className="col-name__sort" onClick={() => sortTableColumn(column)}>+ <Button className="col-name__sort" onClick={onSortTable}>{isSorted ? (isSorted === SORT_ORDER.ASCENDING ? (<ArrowUp height="14px" />@@ -134,7 +144,7 @@ const HeaderCellFactory = (FieldToken: React.FC<FieldTokenProps>) => {) : null}</Button></div>- <Button className="more" onClick={() => toggleMoreOptions(column)}>+ <Button className="more" onClick={onToggleOptionMenu}><VertThreeDots height="14px" /></Button></div>@@ -147,8 +157,8 @@ const HeaderCellFactory = (FieldToken: React.FC<FieldTokenProps>) => {column={column}toggleMoreOptions={toggleMoreOptions}sortTableColumn={mode => sortTableColumn(column, mode)}- pinTableColumn={() => pinTableColumn(column)}- copyTableColumn={() => copyTableColumn(column)}+ pinTableColumn={onPin}+ copyTableColumn={onCopy}/></section></>diff --git a/src/components/src/common/data-table/index.tsx b/src/components/src/common/data-table/index.tsxindex d0a40e4a6..97c5c561e 100644--- a/src/components/src/common/data-table/index.tsx+++ b/src/components/src/common/data-table/index.tsx@@ -25,6 +25,7 @@ import classnames from 'classnames';import {createSelector} from 'reselect';import get from 'lodash.get';import debounce from 'lodash.debounce';+import {ArrowDown} from '../icons';import {CellSizeCache} from './cell-size';@@ -37,6 +38,7 @@ import {adjustCellsToContainer} from './cell-size';import {ALL_FIELD_TYPES} from '@kepler.gl/constants';const defaultHeaderRowHeight = 55;+const defaultHeaderStatsControlHeight = 40;const defaultRowHeight = 32;const overscanColumnCount = 10;const overscanRowCount = 10;@@ -51,7 +53,7 @@ export const Container = styled.div`flex-grow: 1;color: ${props => props.theme.dataTableTextColor};width: 100%;-+ position: relative;.ReactVirtualized__Grid:focus,.ReactVirtualized__Grid:active {outline: 0;@@ -105,11 +107,6 @@ export const Container = styled.div`top: 0;border-right: 2px solid ${props => props.theme.pinnedGridBorderColor};}-- .header-grid {- overflow: hidden !important;- }-.even-row {background-color: ${props => props.theme.evenRowBackground};}@@ -215,6 +212,49 @@ const getRowCell = ({return parseFieldValue(value, type);};+type StatsControlProps = {+ top: number;+ showStats: boolean;+};++const StyledStatsControl = styled.div<StatsControlProps>`+ height: ${props => props.theme.headerStatsControlHeight}px;+ width: 100%;+ display: flex;+ justify-content: center;+ align-items: stretch;+ position: absolute;+ top: ${props => props.top}px;+ font-family: ${props => props.theme.fontFamilyMedium}px;+ font-size: 12px;+ color: ${props => props.theme.activeColor};+ background-color: ${props => props.theme.headerCellStatsControlBackground};+ :hover {+ cursor: pointer;+ }++ > div {+ padding: 0px 24px;+ display: flex;+ align-items: center;++ svg {+ margin-left: 12px;+ transition: transform 0.5s ease;+ transform: rotate(${props => (props.showStats ? 180 : 0)}deg);+ }+ }+`;++const StatsControl = ({top, showStats, toggleShowStats}) => (+ <StyledStatsControl top={top} showStats={showStats}>+ <div onClick={toggleShowStats}>+ {showStats ? 'Hide Column Stats' : 'Show Column Stats'}+ <ArrowDown height="18px" />+ </div>+ </StyledStatsControl>+);+interface TableSectionProps {classList?: {header: string;@@ -286,6 +326,7 @@ export const TableSection = ({className={isPinned ? 'pinned-grid' : 'body-grid'}height={dataGridHeight - headerGridProps.height}onScroll={onScroll}+ scrollLeft={scrollLeft}scrollTop={scrollTop}setGridRef={setGridRef}/>@@ -318,6 +359,7 @@ interface DataTableState {cellSizeCache?: CellSizeCache;moreOptionsColumn?;ghost?;+ showStats?: boolean;}DataTableFactory.deps = [HeaderCellFactory];@@ -331,13 +373,16 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {sortColumn: {},fixedWidth: null,fixedHeight: null,- theme: {},- showStats: false+ theme: {}};+ pinnedGrid = false;+ unpinnedGrid = false;+state: DataTableState = {cellSizeCache: {},- moreOptionsColumn: null+ moreOptionsColumn: null,+ showStats: true};componentDidMount() {@@ -374,7 +419,7 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {moreOptionsColumn:this.state.moreOptionsColumn === moreOptionsColumn ? null : moreOptionsColumn});-+ toggleShowStats = () => this.setState({showStats: !this.state.showStats});getCellSizeCache = () => {const {cellSizeCache: propsCache = {}, fixedWidth, pinnedColumns = []} = this.props;const unpinnedColumns = this.unpinnedColumns(this.props);@@ -449,6 +494,7 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {key={cellInfo.columnIndex}columns={columns}isPinned={isPinned}+ showStats={this.state.showStats}props={props}toggleMoreOptions={toggleMoreOptions}moreOptionsColumn={moreOptionsColumn}@@ -461,12 +507,11 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {pinnedColumns = [],theme = {},fixedWidth,- fixedHeight = 0,- showStats+ fixedHeight = 0} = this.props;const unpinnedColumns = this.unpinnedColumns(this.props);- const {cellSizeCache = {}, moreOptionsColumn, ghost} = this.state;+ const {cellSizeCache = {}, moreOptionsColumn, ghost, showStats} = this.state;const unpinnedColumnsGhost = ghost? [...unpinnedColumns, {ghost: true} as string & {ghost: boolean}]: unpinnedColumns;@@ -478,6 +523,7 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {const hasPinnedColumns = Boolean(pinnedColumns.length);const {headerRowHeight = defaultHeaderRowHeight,+ headerStatsControlHeight = defaultHeaderStatsControlHeight,headerRowWStatsHeight = defaultHeaderRowHeight,rowHeight = defaultRowHeight} = theme;@@ -485,9 +531,9 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {const headerGridProps = {cellSizeCache,className: 'header-grid',- height: showStats ? headerRowWStatsHeight : headerRowHeight,+ height: showStats ? headerRowWStatsHeight : headerRowHeight + headerStatsControlHeight,rowCount: 1,- rowHeight: showStats ? headerRowWStatsHeight : headerRowHeight+ rowHeight: showStats ? headerRowWStatsHeight : headerRowHeight + headerStatsControlHeight};const dataGridProps = {@@ -501,80 +547,89 @@ function DataTableFactory(HeaderCell: ReturnType<typeof HeaderCellFactory>) {return (<Container className="data-table-container" ref={this.root}>{Object.keys(cellSizeCache).length ? (- <ScrollSync>- {({onScroll, scrollLeft, scrollTop}) => {- return (- <div className="results-table-wrapper">- {hasPinnedColumns && (- <div key="pinned-columns" className="pinned-columns grid-row">+ <>+ <ScrollSync>+ {({onScroll, scrollLeft, scrollTop}) => {+ return (+ <div className="results-table-wrapper">+ {hasPinnedColumns && (+ <div key="pinned-columns" className="pinned-columns grid-row">+ <TableSection+ classList={{+ header: 'pinned-columns--header pinned-grid-container',+ rows: 'pinned-columns--rows pinned-grid-container'+ }}+ isPinned+ columns={pinnedColumns}+ headerGridProps={headerGridProps}+ fixedWidth={pinnedColumnsWidth}+ onScroll={args => onScroll({...args, scrollLeft})}+ scrollTop={scrollTop}+ dataGridProps={dataGridProps}+ setGridRef={pinnedGrid => (this.pinnedGrid = pinnedGrid)}+ columnWidth={columnWidthFunction(pinnedColumns, cellSizeCache)}+ headerCellRender={this.renderHeaderCell(+ pinnedColumns,+ true,+ this.props,+ this.toggleMoreOptions,+ moreOptionsColumn+ )}+ dataCellRender={this.renderDataCell(pinnedColumns, true, this.props)}+ />+ </div>+ )}+ <div+ key="unpinned-columns"+ style={{+ marginLeft: `${hasPinnedColumns ? `${pinnedColumnsWidth}px` : '0'}`+ }}+ className="unpinned-columns grid-column"+ ><TableSectionclassList={{- header: 'pinned-columns--header pinned-grid-container',- rows: 'pinned-columns--rows pinned-grid-container'+ header: 'unpinned-columns--header unpinned-grid-container',+ rows: 'unpinned-columns--rows unpinned-grid-container'}}- isPinned- columns={pinnedColumns}+ isPinned={false}+ columns={unpinnedColumnsGhost}headerGridProps={headerGridProps}- fixedWidth={pinnedColumnsWidth}- onScroll={args => onScroll({...args, scrollLeft})}+ fixedWidth={fixedWidth}+ fixedHeight={fixedHeight}+ onScroll={onScroll}scrollTop={scrollTop}+ scrollLeft={scrollLeft}dataGridProps={dataGridProps}- columnWidth={columnWidthFunction(pinnedColumns, cellSizeCache)}+ setGridRef={unpinnedGrid => (this.unpinnedGrid = unpinnedGrid)}+ columnWidth={columnWidthFunction(+ unpinnedColumnsGhost,+ cellSizeCache,+ ghost+ )}headerCellRender={this.renderHeaderCell(- pinnedColumns,- true,+ unpinnedColumnsGhost,+ false,this.props,this.toggleMoreOptions,moreOptionsColumn)}- dataCellRender={this.renderDataCell(pinnedColumns, true, this.props)}+ dataCellRender={this.renderDataCell(+ unpinnedColumnsGhost,+ false,+ this.props+ )}/></div>- )}- <div- key="unpinned-columns"- style={{- marginLeft: `${hasPinnedColumns ? `${pinnedColumnsWidth}px` : '0'}`- }}- className="unpinned-columns grid-column"- >- <TableSection- classList={{- header: 'unpinned-columns--header unpinned-grid-container',- rows: 'unpinned-columns--rows unpinned-grid-container'- }}- isPinned={false}- columns={unpinnedColumnsGhost}- headerGridProps={headerGridProps}- fixedWidth={fixedWidth}- fixedHeight={fixedHeight}- onScroll={onScroll}- scrollTop={scrollTop}- scrollLeft={scrollLeft}- dataGridProps={dataGridProps}- columnWidth={columnWidthFunction(- unpinnedColumnsGhost,- cellSizeCache,- ghost- )}- headerCellRender={this.renderHeaderCell(- unpinnedColumnsGhost,- false,- this.props,- this.toggleMoreOptions,- moreOptionsColumn- )}- dataCellRender={this.renderDataCell(- unpinnedColumnsGhost,- false,- this.props- )}- /></div>- </div>- );- }}- </ScrollSync>+ );+ }}+ </ScrollSync>+ <StatsControl+ top={headerRowHeight}+ showStats={showStats}+ toggleShowStats={this.toggleShowStats}+ />+ </>) : null}</Container>);diff --git a/src/styles/src/base.ts b/src/styles/src/base.tsindex da92cab1e..53f845345 100644--- a/src/styles/src/base.ts+++ b/src/styles/src/base.ts@@ -389,6 +389,8 @@ export const notificationPanelItemHeight = 60;// Data Tableconst headerRowHeight = 70;+const headerStatsControlHeight = 32;+const headerRowWStatsHeight = 364;const rowHeight = 32;const headerPaddingTop = 6;const headerPaddingBottom = 8;@@ -398,6 +400,8 @@ const cellFontSize = 10;const gridPaddingSide = 24;const headerCellBackground = '#FFFFFF';const headerCellBorderColor = '#E0E0E0';+const headerCellStatsBackground = '#F8FAFF';+const headerCellStatsControlBackground = '#EAF0FF';const headerCellIconColor = '#666666';const cellBorderColor = '#E0E0E0';const evenRowBackground = '#FFFFFF';@@ -545,12 +549,12 @@ const inputLT = css`background-color: ${props => props.theme.selectBackgroundLT};border: 1px solid- ${props =>- props.active- ? props.theme.selectActiveBorderColor- : props.error- ? props.theme.errorColor- : props.theme.selectBorderColorLT};+ ${props =>+ props.active+ ? props.theme.selectActiveBorderColor+ : props.error+ ? props.theme.errorColor+ : props.theme.selectBorderColorLT};color: ${props => props.theme.selectColorLT};caret-color: ${props => props.theme.inputBorderActiveColorLT};@@ -1451,6 +1455,8 @@ export const theme = {// Data TableheaderRowHeight,+ headerRowWStatsHeight,+ headerStatsControlHeight,rowHeight,headerPaddingTop,headerPaddingBottom,@@ -1461,6 +1467,8 @@ export const theme = {optionButtonColor,headerCellBackground,headerCellBorderColor,+ headerCellStatsBackground,+ headerCellStatsControlBackground,headerCellIconColor,cellBorderColor,evenRowBackground,diff --git a/test/browser/components/modals/data-table-modal-test.js b/test/browser/components/modals/data-table-modal-test.jsindex e0329ec92..f091770a7 100644--- a/test/browser/components/modals/data-table-modal-test.js+++ b/test/browser/components/modals/data-table-modal-test.js@@ -541,9 +541,9 @@ test('Components -> cellSize -> renderedSize', t => {.props();const expected = {- _geojson: {row: 500, header: 192},- 'income level of people over 65': {row: 182, header: 209},- engagement: {row: 182, header: 192}+ _geojson: {row: 500, header: 206},+ 'income level of people over 65': {row: 182, header: 223},+ engagement: {row: 182, header: 206}};t.deepEqual(