Allow to disable column sorting

Summary: Project: https://docs.google.com/document/d/1SbFrpvfIShX5npANNa1AkgHliR1M-VMLW5Q9RhREt94/edit#

Reviewed By: antonk52

Differential Revision: D45394048

fbshipit-source-id: 4255777d477f8240f52b5f82c28e922ef1011989
This commit is contained in:
Andrey Goncharov
2023-04-28 12:19:45 -07:00
committed by Facebook GitHub Bot
parent a819c77f18
commit 9d2de05723
2 changed files with 32 additions and 24 deletions

View File

@@ -121,6 +121,7 @@ export type DataTableColumn<T = any> = {
predefined?: boolean; predefined?: boolean;
}[]; }[];
inversed?: boolean; inversed?: boolean;
sortable?: boolean;
}; };
export interface TableRowRenderContext<T = any> { export interface TableRowRenderContext<T = any> {

View File

@@ -13,7 +13,7 @@ import {
Percentage, Percentage,
Width, Width,
} from '../../utils/widthUtils'; } from '../../utils/widthUtils';
import {memo, useRef} from 'react'; import {HTMLAttributes, memo, useRef} from 'react';
import {Interactive, InteractiveProps} from '../Interactive'; import {Interactive, InteractiveProps} from '../Interactive';
import styled from '@emotion/styled'; import styled from '@emotion/styled';
import React from 'react'; import React from 'react';
@@ -174,25 +174,26 @@ function TableHeadColumn({
}); });
}; };
let children = ( let divProps: HTMLAttributes<HTMLDivElement> = {};
<Layout.Right center> if (column.sortable) {
<div divProps = {
onClick={(e) => { onClick: (e) => {
e.stopPropagation(); e.stopPropagation();
const newDirection = const newDirection =
sorted === undefined sorted === undefined ? 'asc' : sorted === 'asc' ? 'desc' : undefined;
? 'asc'
: sorted === 'asc'
? 'desc'
: undefined;
dispatch({ dispatch({
type: 'sortColumn', type: 'sortColumn',
column: column.key, column: column.key,
direction: newDirection, direction: newDirection,
}); });
}} },
role="button" role: 'button',
tabIndex={0}> tabIndex: 0,
};
}
let children = (
<Layout.Right center>
<div {...divProps}>
<Text type="secondary"> <Text type="secondary">
{column.title === undefined ? ( {column.title === undefined ? (
toFirstUpper(column.key) toFirstUpper(column.key)
@@ -201,12 +202,18 @@ function TableHeadColumn({
) : ( ) : (
column.title column.title
)} )}
{column.sortable ? (
<SortIcons <SortIcons
direction={sorted} direction={sorted}
onSort={(dir) => onSort={(dir) =>
dispatch({type: 'sortColumn', column: column.key, direction: dir}) dispatch({
type: 'sortColumn',
column: column.key,
direction: dir,
})
} }
/> />
) : null}
</Text> </Text>
</div> </div>
<FilterIcon column={column} dispatch={dispatch} /> <FilterIcon column={column} dispatch={dispatch} />