Skip to content

Commit

Permalink
feat(ResourceTable): Add default rowKey function
Browse files Browse the repository at this point in the history
Use `_links.self.href` by default to determine row key; may be overridden by specifying custom
`rowKey` prop on ResourceTable
  • Loading branch information
wms committed Sep 27, 2017
1 parent 83f0916 commit 3019617
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/ResourceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class ResourceTable extends React.PureComponent<Props, State> {

return (
<Table
rowKey={this._rowKey}
{...tableProps}
pagination={this.pagination()}
loading={loading}
Expand Down Expand Up @@ -186,4 +187,12 @@ export class ResourceTable extends React.PureComponent<Props, State> {

return params;
}

protected _rowKey = (resource: Resource) => {
if (resource.hasLink('self')) {
return resource.link('self').href;
}

return 'unknown';
}
}
2 changes: 1 addition & 1 deletion src/components/__snapshots__/ResourceTable.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ exports[`default behaviour renders an Ant Table 1`] = `
}
}
prefixCls="ant-table"
rowKey="key"
rowKey={[Function]}
rowSelection={null}
showHeader={true}
size="large"
Expand Down

0 comments on commit 3019617

Please sign in to comment.