Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix case sensitive for cell values #721

Merged
merged 5 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Not released


- Fix: table widget was not showing data due to case sensitive [#721](https://github.com/CartoDB/carto-react/pull/721)

## 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