Skip to content

Commit

Permalink
Fix case sensitive for cell values (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Josmorsot authored Jun 23, 2023
1 parent 0a7e9c0 commit f82377e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Not released

- Fix: table widget was not showing data due to case sensitive [#721](https://github.com/CartoDB/carto-react/pull/721)
- Supporting for `client` parameter for Widgets API calls [#722](https://github.com/CartoDB/carto-react/pull/722)

## 2.1
Expand Down
13 changes: 13 additions & 0 deletions packages/react-ui/__tests__/widgets/TableWidgetUI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,17 @@ describe('TableWidgetUI', () => {
expect(mockOnSetSortDirection).toHaveBeenCalledWith('desc');
});
});

describe('case insensitive', () => {
test('should render rows properly', () => {
const keptFields = ['address', 'city'];
const filteredColumns = columns
.filter((col) => keptFields.includes(col.field))
.map((c) => ({ ...c, field: c.field.toUpperCase() }));
render(<Widget columns={filteredColumns} />);

const row = rows[1];
expect(screen.queryByText(row.address)).toBeInTheDocument();
});
});
});
12 changes: 8 additions & 4 deletions packages/react-ui/src/widgets/TableWidgetUI/TableWidgetUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,18 +166,22 @@ function TableBodyComponent({ columns, rows, onRowClick }) {
hover={!!onRowClick}
onClick={() => onRowClick && onRowClick(row)}
>
{columns.map(
({ field, headerName, align, component }) =>
{columns.map(({ field, headerName, align, component }) => {
const cellValue = Object.entries(row).find(([key]) => {
return key.toUpperCase() === field.toUpperCase();
})?.[1];
return (
(headerName || field) && (
<TableCellStyled
key={`${rowKey}_${field}`}
scope='row'
align={align || 'left'}
>
{component ? component(row[field]) : row[field]}
{component ? component(cellValue) : cellValue}
</TableCellStyled>
)
)}
);
})}
</TableRowStyled>
);
})}
Expand Down

0 comments on commit f82377e

Please sign in to comment.