Skip to content

Commit

Permalink
Truncate the column type (amundsen-io#297)
Browse files Browse the repository at this point in the history
* Truncate the column type

* Update truncation method

* Cleanup logic
  • Loading branch information
ttannis authored and Hans Adriaans committed Jun 30, 2022
1 parent 0955142 commit 6fbd15d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
5 changes: 5 additions & 0 deletions frontend/amundsen_application/static/css/_popovers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,8 @@
width: 24px;
margin: auto;
}

.column-type-popover {
max-width: 552px; // arbitrary 2x default
word-break: break-word;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as React from 'react';
import moment from 'moment-timezone';

import { OverlayTrigger, Popover } from 'react-bootstrap';

import ColumnDescEditableText from 'components/TableDetail/ColumnDescEditableText';
import { logClick } from 'ducks/utilMethods';
import { TableColumn } from 'interfaces';
Expand Down Expand Up @@ -49,6 +51,48 @@ class DetailListItem extends React.Component<DetailListItemProps, DetailListItem
return moment(unixEpochSeconds * 1000).format("MMM DD, YYYY");
};

renderColumnType = (columnIndex: number, type: string) => {
const truncatedTypes: string[] = ['array', 'struct', 'map'];
let shouldTrucate = false;

const fullText = type.toLowerCase();
let text = fullText;

truncatedTypes.forEach((truncatedType) => {
if (type.startsWith(truncatedType) && type !== truncatedType) {
shouldTrucate = true;
text = `${truncatedType}<...>`;
return;
};
})

if (shouldTrucate) {
const popoverHover = (
<Popover className='column-type-popover' id={`column-type-popover:${columnIndex}`}>
{fullText}
</Popover>
);
const stopPropagation = (event) => {
event.stopPropagation();
}
return (
<OverlayTrigger
trigger={['click']}
placement='right'
overlay={popoverHover}
rootClose={true}>
<a className='column-type'
href="JavaScript:void(0)"
onClick={ stopPropagation }
>
{text}
</a>
</OverlayTrigger>
)
}
return (<div className='column-type'>{text}</div>);
};

render() {
const metadata = this.props.data;
const isExpandable = metadata.stats && metadata.stats.length > 0;
Expand All @@ -75,7 +119,7 @@ class DetailListItem extends React.Component<DetailListItemProps, DetailListItem
<div className='title-section'>
<div className='title-row'>
<div className='name title-2'>{metadata.name}</div>
<div className='column-type'>{metadata.type ? metadata.type.toLowerCase() : 'null'}</div>
{ this.renderColumnType(this.props.index, metadata.type) }
</div>
</div>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
margin-top: 4px;
max-width: 15%;
}

a.column-type {
text-decoration: none;
}
}
}

Expand Down

0 comments on commit 6fbd15d

Please sign in to comment.