Skip to content

Commit e10cc84

Browse files
authored
Refactor table header and filter row keys in EnhancedTable and TaskAnalysisTable (#2651)
* Refactor table header and filter row keys in EnhancedTable and TaskAnalysisTable * setup some overflow ellipsis * format
1 parent df66ab2 commit e10cc84

2 files changed

Lines changed: 62 additions & 29 deletions

File tree

src/components/TableShared/EnhancedTable.jsx

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ export const SearchFilter = ({ value, onChange, placeholder, inputClassName = ""
6161
export const renderTableHeader = (headerGroups) => {
6262
return (
6363
<>
64-
{headerGroups.map((headerGroup) => (
65-
<tr {...headerGroup.getHeaderGroupProps()} key={headerGroup.id}>
64+
{headerGroups.map((headerGroup, index) => (
65+
<tr {...headerGroup.getHeaderGroupProps()} key={`header-row-${headerGroup.id || index}`}>
6666
{headerGroup.headers.map((column) => {
6767
const headerProps = column.getHeaderProps();
6868
const sortByProps = column.getSortByToggleProps ? column.getSortByToggleProps() : {};
@@ -76,15 +76,14 @@ export const renderTableHeader = (headerGroups) => {
7676

7777
return (
7878
<th
79-
key={column.id}
79+
key={`header-cell-${column.id}`}
8080
className={`${headerStyles} ${!column.disableSortBy ? sortableHeaderStyles : ""}`}
8181
{...headerProps}
8282
onClick={onHeaderClick}
8383
style={{
8484
...headerProps.style,
8585
width: column.width,
8686
minWidth: column.minWidth,
87-
maxWidth: column.width,
8887
position: "relative",
8988
}}
9089
>
@@ -130,15 +129,14 @@ export const renderTableHeader = (headerGroups) => {
130129
))}
131130

132131
{/* Add a separate row for filters */}
133-
{headerGroups.map((headerGroup) => (
134-
<tr key={`filter-${headerGroup.id}`}>
132+
{headerGroups.map((headerGroup, index) => (
133+
<tr key={`filter-row-${headerGroup.id}-${index}`}>
135134
{headerGroup.headers.map((column) => (
136135
<td
137-
key={`filter-${column.id}`}
136+
key={`filter-cell-${column.id}`}
138137
style={{
139138
width: column.width,
140139
minWidth: column.minWidth,
141-
maxWidth: column.width,
142140
}}
143141
>
144142
{column.canFilter && (
@@ -172,3 +170,37 @@ export const TableWrapper = ({ children, className = "" }) => (
172170
<div className="mr-inline-block mr-min-w-full">{children}</div>
173171
</div>
174172
);
173+
174+
/**
175+
* Renders a table cell with nowrap styling
176+
* @param {Object} cell - The react-table cell object
177+
* @param {Object} options - Additional styling options
178+
* @returns {JSX.Element} - The rendered table cell
179+
*/
180+
export const renderTableCell = (cell, options = {}) => {
181+
return (
182+
<td
183+
{...cell.getCellProps()}
184+
style={{
185+
...cell.getCellProps().style,
186+
whiteSpace: "nowrap !important",
187+
overflow: "hidden !important",
188+
textOverflow: "ellipsis !important",
189+
minWidth: cell.column.minWidth,
190+
...options,
191+
}}
192+
>
193+
<div
194+
style={{
195+
overflow: "hidden !important",
196+
textOverflow: "ellipsis !important",
197+
whiteSpace: "nowrap !important",
198+
width: "100%",
199+
display: "block",
200+
}}
201+
>
202+
{cell.render("Cell")}
203+
</div>
204+
</td>
205+
);
206+
};

src/components/TaskAnalysisTable/TaskAnalysisTable.jsx

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ import WithLoadedTask from "../HOCs/WithLoadedTask/WithLoadedTask";
3333
import IntlDatePicker from "../IntlDatePicker/IntlDatePicker";
3434
import PaginationControl from "../PaginationControl/PaginationControl";
3535
import SvgSymbol from "../SvgSymbol/SvgSymbol";
36-
import { SearchFilter, TableWrapper, renderTableHeader } from "../TableShared/EnhancedTable";
37-
import { cellStyles, inputStyles, rowStyles, tableStyles } from "../TableShared/TableStyles";
36+
import {
37+
SearchFilter,
38+
TableWrapper,
39+
renderTableCell,
40+
renderTableHeader,
41+
} from "../TableShared/EnhancedTable";
42+
import { inputStyles, rowStyles, tableStyles } from "../TableShared/TableStyles";
3843
import ViewTask from "../ViewTask/ViewTask";
3944
import messages from "./Messages";
4045
import TaskAnalysisTableHeader from "./TaskAnalysisTableHeader";
@@ -285,27 +290,12 @@ export const TaskAnalysisTableInternal = (props) => {
285290
className={`${row.isExpanded ? "mr-bg-black-10" : ""} ${rowStyles}`}
286291
>
287292
{row.cells.map((cell) => {
288-
return (
289-
<td
290-
key={cell.column.id}
291-
{...cell.getCellProps()}
292-
className={cellStyles}
293-
style={{
294-
...cell.getCellProps().style,
295-
maxWidth: cell.column.width,
296-
minWidth: cell.column.minWidth,
297-
overflow: "hidden",
298-
height: "40px",
299-
}}
300-
>
301-
<div className="mr-cell-content">{cell.render("Cell")}</div>
302-
</td>
303-
);
293+
return renderTableCell(cell);
304294
})}
305295
</tr>
306296

307297
{row.isExpanded ? (
308-
<tr>
298+
<tr key={`expanded-${row.original.id}`}>
309299
<td colSpan={columns.length}>
310300
<ViewTaskSubComponent taskId={row.original.id} />
311301
</td>
@@ -389,7 +379,18 @@ const setupColumnTypes = (props, taskBaseRoute, manager, openComments) => {
389379
id: "featureId",
390380
Header: props.intl.formatMessage(messages.featureIdLabel),
391381
accessor: (t) => t.name || t.title,
392-
Cell: ({ value }) => value || "",
382+
Cell: ({ value }) => (
383+
<div
384+
style={{
385+
overflow: "hidden",
386+
whiteSpace: "nowrap",
387+
textOverflow: "ellipsis",
388+
width: "100%",
389+
}}
390+
>
391+
{value || ""}
392+
</div>
393+
),
393394
Filter: ({ column: { filterValue, setFilter } }) => (
394395
<div className="mr-flex mr-items-center" onClick={(e) => e.stopPropagation()}>
395396
<SearchFilter
@@ -486,6 +487,7 @@ const setupColumnTypes = (props, taskBaseRoute, manager, openComments) => {
486487
)}
487488
</div>
488489
),
490+
width: 40,
489491
};
490492

491493
columns.status = {
@@ -937,7 +939,6 @@ const setupColumnTypes = (props, taskBaseRoute, manager, openComments) => {
937939
accessor: "commentID",
938940
Cell: ({ row }) => <ViewCommentsButton onClick={() => openComments(row.original.id)} />,
939941
width: 110,
940-
941942
disableSortBy: true,
942943
};
943944

0 commit comments

Comments
 (0)