Skip to content

Commit

Permalink
when table columns are implicit, do not set the display name [#153234…
Browse files Browse the repository at this point in the history
…166]

Signed-off-by: Reid Mitchell <rmitchell@pivotal.io>
  • Loading branch information
Jonathan Berney authored and pivotal committed Nov 30, 2017
1 parent a9280d6 commit d2542d0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
6 changes: 3 additions & 3 deletions spec/pivotal-ui-react/table/table_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ describe('Table', () => {
});

it('renders the data keys as column headers', () => {
expect('table thead tr th:eq(0)').toHaveText('Attr1');
expect('table thead tr th:eq(1)').toHaveText('Attr2');
expect('table thead tr th:eq(2)').toHaveText('Attr3');
expect('table thead tr th:eq(0)').toHaveText('attr1');
expect('table thead tr th:eq(1)').toHaveText('attr2');
expect('table thead tr th:eq(2)').toHaveText('attr3');
});
});
});
11 changes: 3 additions & 8 deletions src/react/table/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,11 @@ export class Table extends TablePlugin {

let dataColumns;

if (!columns) {
const dataKeys = {};
data.forEach(row => Object.keys(row).forEach(attr => dataKeys[attr] = true));
dataColumns = Object.keys(dataKeys).map(dataKey => ({
attribute: dataKey,
displayName: dataKey[0].toUpperCase() + dataKey.slice(1)
}));
if (!columns && data.length > 0) {
dataColumns = Object.keys(data[0]).map(attribute => ({attribute}));
}

const renderedColumns = columns || dataColumns;
const renderedColumns = columns || dataColumns || [];

const headers = renderedColumns.map((column, key) => {
const Th = this.plugTag('th', 'th');
Expand Down

0 comments on commit d2542d0

Please sign in to comment.