Skip to content

Commit 5e97a96

Browse files
authored
Prevent duplicated columns in TableModel
1 parent 1796ec9 commit 5e97a96

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/react-widgets/__tests__/models/TableModel.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jest.mock('@carto/react-workers', () => ({
3131
}
3232
}));
3333

34+
afterEach(() => {
35+
jest.clearAllMocks();
36+
});
37+
3438
describe('getTable', () => {
3539
const tableParams = {
3640
source: {
@@ -94,5 +98,15 @@ describe('getTable', () => {
9498
hasData: true
9599
});
96100
});
101+
102+
test('prevents column duplicates', async () => {
103+
const data = await getTable({
104+
...tableParams,
105+
columns: ['any-column', 'any-column'],
106+
remoteCalculation: true
107+
});
108+
109+
expect(mockedExecuteModel.mock.calls[0][0].params.column).toEqual(['any-column']);
110+
});
97111
});
98112
});

packages/react-widgets/src/models/TableModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ function fromRemote(props) {
6161
spatialFilter,
6262
...(searchFilter && { searchFilter }),
6363
params: {
64-
column: columns,
64+
column: [...new Set(columns)],
6565
sortBy,
6666
sortDirection,
6767
limit: rowsPerPage,

0 commit comments

Comments
 (0)