Skip to content

Commit 7d0dac2

Browse files
authored
Merge pull request #2529 from cfpb/2244-react-tables
2244-react-tables
2 parents f504228 + 2a232e6 commit 7d0dac2

File tree

8 files changed

+63
-34
lines changed

8 files changed

+63
-34
lines changed

cypress/e2e/tools/olarft.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ onlyOn(!isBeta(HOST), () => {
4747
cy.get('.filters > :nth-child(2) > .clear').click()
4848
// Now testing "Search TS" functionality
4949
cy.get('.filters > :nth-child(1) > input').click().type(yearToBeTested)
50-
cy.get('.row-container > :nth-child(2) > .custom-cell-content').should(
50+
cy.get('.rft-row > :nth-child(2) > .custom-cell-content').should(
5151
'have.text',
5252
yearToBeTested,
5353
)
@@ -69,7 +69,7 @@ onlyOn(!isBeta(HOST), () => {
6969
cy.get('#saved-lars > h3.clickable > .filters > :nth-child(1) > input')
7070
.click()
7171
.type('1')
72-
cy.get('#saved-lars .row-container #row-1').should('have.text', '1')
72+
cy.get('#saved-lars .rft-row #row-1').should('have.text', '1')
7373
// Clear "Search LAR" input
7474
cy.get(':nth-child(1) > .clear').click()
7575
// "Filter columns" functionality

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"react-app-polyfill": "2.0.0",
5353
"react-dom": "18.3.1",
5454
"react-dropzone": "10.2.2",
55-
"react-fluid-table": "0.5.1",
55+
"react-fluid-table": "^1.4.3",
5656
"react-helmet": "5.2.1",
5757
"react-highlight-words": "0.20.0",
5858
"react-paginate": "8.2.0",

src/tools/larft/components/saved-rows/RowID.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ export const HeaderRowID = (props) => (
1414
</div>
1515
)
1616

17-
export const ContentRowID = (props) => (
18-
<div className='custom-cell-content' style={{ width: '55px' }}>
17+
export const ContentRowID = ({ onClick, ...props }) => (
18+
<div
19+
className='custom-cell-content'
20+
style={{ width: '55px' }}
21+
onClick={onClick}
22+
>
1923
{props?.row?.rowId}
2024
</div>
2125
)

src/tools/larft/components/saved-rows/SavedSection.jsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { NoMatches, NoRecords } from './EmptyStates'
1010
import { Filters, SearchBox } from './Filters'
1111
import { ContentRowID, HeaderRowID } from './RowID'
1212
import { SectionTitle } from './SectionTitle'
13+
import "react-fluid-table/dist/index.css"
14+
import "./rft.css"
1315

1416
/**
1517
* Provides a searchable/filterable table of LAR/TS content.
@@ -35,7 +37,7 @@ export const SavedSection = ({ id, title = 'Section Title', rows }) => {
3537
const highlightSelected = (r) => {
3638
if (!selectedRowID || !r) return {}
3739
const highlighted = selectedRowID === r.id
38-
return highlighted ? { background: 'lightblue' } : {}
40+
return highlighted ? { backgroundColor: 'lightblue' } : {}
3941
}
4042

4143
const filteredRows = applyRowFilter({
@@ -59,11 +61,11 @@ export const SavedSection = ({ id, title = 'Section Title', rows }) => {
5961
if (!columns) return <NoRecords />
6062
else {
6163
columns.unshift({
62-
key: 'rowId',
63-
width: 'auto',
64-
header: (props) => <HeaderRowID {...props} />,
65-
content: (props) => <ContentRowID {...props} />,
66-
})
64+
key: 'rowId',
65+
width: 'auto',
66+
header: (props) => <HeaderRowID {...props} />,
67+
content: (props) => <ContentRowID {...props} onClick={() => dispatch(selectRow(props.row.id))} />,
68+
})
6769

6870
if (!filteredRows.length || columns.length === 1) {
6971
return <NoMatches />
@@ -74,10 +76,9 @@ export const SavedSection = ({ id, title = 'Section Title', rows }) => {
7476
columns={columns}
7577
tableHeight={calcTableHeight(filteredRows)}
7678
minColumnWidth={200}
77-
onRowClick={(_, { index }) =>
78-
dispatch(selectRow(filteredRows[index].id))
79-
}
80-
rowStyle={(i) => highlightSelected(filteredRows[i])}
79+
rowStyle={(data) => {
80+
return selectedRowID === data.row?.id ? { backgroundColor: 'lightblue' } : {};
81+
}}
8182
/>
8283
)
8384
}

src/tools/larft/components/saved-rows/buildColumns.jsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import { useDispatch } from 'react-redux'
3-
import { selectCol } from '../../data-store/store'
3+
import { selectCol, selectRow } from '../../data-store/store'
44
import { matchColumnFilter } from '../../utils/search'
55

66
/**
@@ -102,7 +102,10 @@ const ColumnContent = ({ row, field, searchFilter, selectedColName }) => {
102102

103103
const styles = { width: formatColWidth(field, -16) }
104104
const wrapperClasses = ['custom-cell-content']
105-
const clickHandler = () => dispatch(selectCol(fieldName))
105+
const clickHandler = () => {
106+
dispatch(selectCol(fieldName))
107+
dispatch(selectRow(row.id))
108+
}
106109

107110
if (isColumnSelected(selectedColName, field))
108111
wrapperClasses.push('col-selected')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.rft-cell {
2+
padding: 8px;
3+
}

src/tools/larft/index.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
white-space: nowrap;
197197
width: 100%;
198198
}
199-
.saved-rows .react-fluid-table-row:hover {
199+
.saved-rows .rft-row:hover {
200200
cursor: pointer;
201201
background-color: lightgrey;
202202
}

yarn.lock

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2832,13 +2832,32 @@ __metadata:
28322832
languageName: node
28332833
linkType: hard
28342834

2835+
"@tanstack/react-virtual@npm:^3.13.6":
2836+
version: 3.13.8
2837+
resolution: "@tanstack/react-virtual@npm:3.13.8"
2838+
dependencies:
2839+
"@tanstack/virtual-core": "npm:3.13.8"
2840+
peerDependencies:
2841+
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
2842+
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
2843+
checksum: 10c0/1604227dad2f1c8d3b8246f8afe9bc37998da8f97ed7ef1b5d703fe3417c8a54541592a9091e7c8e63521002672268292d347c5c17fe1e1e82b9d0b297ddd1b4
2844+
languageName: node
2845+
linkType: hard
2846+
28352847
"@tanstack/table-core@npm:8.20.5":
28362848
version: 8.20.5
28372849
resolution: "@tanstack/table-core@npm:8.20.5"
28382850
checksum: 10c0/3c27b5debd61b6bd9bfbb40bfc7c5d5af90873ae1a566b20e3bf2d2f4f2e9a78061c081aacc5259a00e256f8df506ec250eb5472f5c01ff04baf9918b554982b
28392851
languageName: node
28402852
linkType: hard
28412853

2854+
"@tanstack/virtual-core@npm:3.13.8":
2855+
version: 3.13.8
2856+
resolution: "@tanstack/virtual-core@npm:3.13.8"
2857+
checksum: 10c0/4b76b5d87fb26c928939a58d3887b9191574f029f60f9146eb05fd591f8b96a69bd3c7a1d64dd9d6cbfbfc85a0bd22b49a79fa4d3abab64eee595db9ad94f3ea
2858+
languageName: node
2859+
linkType: hard
2860+
28422861
"@testing-library/cypress@npm:10.0.2":
28432862
version: 10.0.2
28442863
resolution: "@testing-library/cypress@npm:10.0.2"
@@ -6787,7 +6806,7 @@ __metadata:
67876806
react-app-polyfill: "npm:2.0.0"
67886807
react-dom: "npm:18.3.1"
67896808
react-dropzone: "npm:10.2.2"
6790-
react-fluid-table: "npm:0.5.1"
6809+
react-fluid-table: "npm:^1.4.3"
67916810
react-helmet: "npm:5.2.1"
67926811
react-highlight-words: "npm:0.20.0"
67936812
react-icons: "npm:^4.4.0"
@@ -9853,16 +9872,16 @@ __metadata:
98539872
languageName: node
98549873
linkType: hard
98559874

9856-
"react-fluid-table@npm:0.5.1":
9857-
version: 0.5.1
9858-
resolution: "react-fluid-table@npm:0.5.1"
9875+
"react-fluid-table@npm:^1.4.3":
9876+
version: 1.4.3
9877+
resolution: "react-fluid-table@npm:1.4.3"
98599878
dependencies:
9860-
react-resize-detector: "npm:^9.1.0"
9861-
react-window: "npm:^1.8.9"
9879+
"@tanstack/react-virtual": "npm:^3.13.6"
9880+
react-resize-detector: "npm:^12.0.2"
98629881
peerDependencies:
9863-
react: ">=16.8.0"
9864-
react-dom: ">=16.8.0"
9865-
checksum: 10c0/84479518ca3d61996c2e9193d1378c247fa472a2411a963347c956d37c54459bdf19b83d7420db2cba4e5553c60129c16fce4eb91403421ca559f5f0d4008488
9882+
react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
9883+
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
9884+
checksum: 10c0/eabdc6cfa7f2dffad18c3f099f066f29743908cda9b0371ccd98a8ce170b2df3faf29999cb76e556945b805b020d0b50e3e9901a1d7a608df9b1cbdd219a6a36
98669885
languageName: node
98679886
linkType: hard
98689887

@@ -9973,15 +9992,14 @@ __metadata:
99739992
languageName: node
99749993
linkType: hard
99759994

9976-
"react-resize-detector@npm:^9.1.0":
9977-
version: 9.1.1
9978-
resolution: "react-resize-detector@npm:9.1.1"
9995+
"react-resize-detector@npm:^12.0.2":
9996+
version: 12.0.2
9997+
resolution: "react-resize-detector@npm:12.0.2"
99799998
dependencies:
99809999
lodash: "npm:^4.17.21"
998110000
peerDependencies:
9982-
react: ^16.0.0 || ^17.0.0 || ^18.0.0
9983-
react-dom: ^16.0.0 || ^17.0.0 || ^18.0.0
9984-
checksum: 10c0/6a85892fe46a12fc27b09b5bf5fcc1438f3196f70c75d4685b09eed2c68a2c853dd6eb792bf852038082505a3b4f05dba359055ee0baca3f8b59f022a85a368c
10001+
react: ^18.0.0 || ^19.0.0
10002+
checksum: 10c0/93c05569223a9a48a170e053f7c7fc54bb4e467fb85b6c66e9de5ed99d08b347ff927a8076986f39950d1b038d4944e365c2fc35853a89f0dbe98ae95bc0913b
998510003
languageName: node
998610004
linkType: hard
998710005

@@ -10093,7 +10111,7 @@ __metadata:
1009310111
languageName: node
1009410112
linkType: hard
1009510113

10096-
"react-window@npm:1.8.10, react-window@npm:^1.8.9":
10114+
"react-window@npm:1.8.10":
1009710115
version: 1.8.10
1009810116
resolution: "react-window@npm:1.8.10"
1009910117
dependencies:

0 commit comments

Comments
 (0)