1- import { Box , TableSortLabel , Theme } from "@mui/material" ;
1+ import { Box , TableSortLabel , Theme , Typography } from "@mui/material" ;
22import { makeStyles } from "@mui/styles" ;
33import clsx from "clsx" ;
44import { createContext , ReactNode , useContext , useMemo } from "react" ;
55import { HeaderGroup } from "react-table" ;
66
77import { SORTING_ARROW_WIDTH } from "@/charts/table/constants" ;
88import { ColumnMeta } from "@/charts/table/table-state" ;
9+ import { columnCanBeWidthLimited } from "@/charts/table/width-limit" ;
910import { Flex } from "@/components/flex" ;
1011import { OpenMetadataPanelWrapper } from "@/components/metadata-panel" ;
12+ import { OverflowTooltip } from "@/components/overflow-tooltip" ;
1113import { Observation } from "@/domain/data" ;
1214
1315/** Workaround because react-window can't pass props to inner element */
@@ -16,6 +18,7 @@ type TableContentProps = {
1618 tableColumnsMeta : Record < string , ColumnMeta > ;
1719 customSortCount : number ;
1820 totalColumnsWidth : number ;
21+ shouldApplyWidthLimits : boolean ;
1922} ;
2023
2124const TableContentContext = createContext < TableContentProps | undefined > (
@@ -27,6 +30,7 @@ export const TableContentProvider = ({
2730 tableColumnsMeta,
2831 customSortCount,
2932 totalColumnsWidth,
33+ shouldApplyWidthLimits,
3034 children,
3135} : TableContentProps & { children : ReactNode } ) => {
3236 const value = useMemo ( ( ) => {
@@ -35,8 +39,15 @@ export const TableContentProvider = ({
3539 tableColumnsMeta,
3640 customSortCount,
3741 totalColumnsWidth,
42+ shouldApplyWidthLimits,
3843 } ;
39- } , [ headerGroups , tableColumnsMeta , customSortCount , totalColumnsWidth ] ) ;
44+ } , [
45+ headerGroups ,
46+ tableColumnsMeta ,
47+ customSortCount ,
48+ totalColumnsWidth ,
49+ shouldApplyWidthLimits ,
50+ ] ) ;
4051
4152 return (
4253 < TableContentContext . Provider value = { value } >
@@ -75,8 +86,13 @@ export const TableContent = ({ children }: { children: ReactNode }) => {
7586 throw Error ( "Please wrap TableContent in TableContentProvider" ) ;
7687 }
7788
78- const { headerGroups, tableColumnsMeta, customSortCount, totalColumnsWidth } =
79- ctx ;
89+ const {
90+ headerGroups,
91+ tableColumnsMeta,
92+ customSortCount,
93+ totalColumnsWidth,
94+ shouldApplyWidthLimits,
95+ } = ctx ;
8096
8197 return (
8298 < >
@@ -87,10 +103,13 @@ export const TableContent = ({ children }: { children: ReactNode }) => {
87103 // eslint-disable-next-line react/jsx-key
88104 < Box { ...headerGroup . getHeaderGroupProps ( ) } >
89105 { headerGroup . headers . map ( ( column ) => {
90- const { dim, columnComponentType } =
106+ const { type , dim, columnComponentType } =
91107 tableColumnsMeta [ column . id ] ;
92108 // We assume that the customSortCount items are at the beginning of the sorted array, so any item with a lower index must be a custom sorted one
93109 const isCustomSorted = column . sortedIndex < customSortCount ;
110+ const hasWidthLimit =
111+ shouldApplyWidthLimits && columnCanBeWidthLimited ( type ) ;
112+ const headerText = `${ column . Header } ` ;
94113
95114 return (
96115 // eslint-disable-next-line react/jsx-key
@@ -102,6 +121,7 @@ export const TableContent = ({ children }: { children: ReactNode }) => {
102121 : undefined
103122 ) }
104123 { ...column . getHeaderProps ( column . getSortByToggleProps ( ) ) }
124+ title = { headerText }
105125 >
106126 < TableSortLabel
107127 active = { isCustomSorted }
@@ -110,12 +130,31 @@ export const TableContent = ({ children }: { children: ReactNode }) => {
110130 "& svg" : {
111131 opacity : isCustomSorted ? 1 : 0.5 ,
112132 } ,
133+ ...( hasWidthLimit && {
134+ minWidth : 0 ,
135+ } ) ,
113136 } }
114137 >
115138 < OpenMetadataPanelWrapper component = { dim } >
116- < span style = { { fontWeight : "bold" } } >
117- { column . render ( "Header" ) }
118- </ span >
139+ { hasWidthLimit ? (
140+ < OverflowTooltip arrow title = { headerText } >
141+ < Typography
142+ component = "span"
143+ variant = "inherit"
144+ noWrap
145+ sx = { { fontWeight : "bold" , lineHeight : 1.5 } }
146+ >
147+ { column . render ( "Header" ) }
148+ </ Typography >
149+ </ OverflowTooltip >
150+ ) : (
151+ < Box
152+ component = "span"
153+ sx = { { fontWeight : "bold" , lineHeight : 1.5 } }
154+ >
155+ { column . render ( "Header" ) }
156+ </ Box >
157+ ) }
119158 </ OpenMetadataPanelWrapper >
120159 </ TableSortLabel >
121160 </ Flex >
0 commit comments