Skip to content

Commit

Permalink
enhancement #387 - [Table ] Link enhancements
Browse files Browse the repository at this point in the history
Closes #387
  • Loading branch information
nancy-dassana committed Jul 16, 2021
1 parent b54f133 commit 3bb44af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dassana-io/web-components",
"version": "0.11.14",
"version": "0.11.15",
"publishConfig": {
"registry": "https://npm.pkg.github.com/dassana-io"
},
Expand Down
3 changes: 2 additions & 1 deletion src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ interface ComponentColoredDotType extends PartialComponentType {
}

interface RenderPropsLink extends Pick<SharedLinkProps, 'target'> {
buildHref: (record?: string) => string
buildHref: <T>(record?: string, data?: T) => string
isDisabled?: <T>(record?: string, data?: T) => boolean
}

interface ComponentLinkType extends PartialComponentType {
Expand Down
13 changes: 9 additions & 4 deletions src/components/Table/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,20 +483,25 @@ function applyRender<TableData extends DataId>(
}

case link: {
antDColumn.render = (record: string) => {
antDColumn.render = (record: string, data: TableData) => {
if (record === undefined) return ''

const {
target = '_blank',
buildHref = (r: string) => r
buildHref = (r: string, _data: TableData) => r,
isDisabled = (_r: string, _data: TableData) =>
false,
target = '_blank'
} = column.renderProps || {}

const linkProps: LinkProps = {
children: record,
href: buildHref(record),
href: buildHref(record, data),
target
}

if (isDisabled(record, data))
return <CellWithTooltip text={record} />

return <Link {...linkProps} />
}
break
Expand Down

0 comments on commit 3bb44af

Please sign in to comment.