Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 29 additions & 30 deletions superset-frontend/src/components/Tags/Tag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const Tag = ({
onDelete = undefined,
editable = false,
onClick = undefined,
toolTipTitle = name,
}: TagType) => {
const isLongTag = useMemo(() => name.length > 20, [name]);

Expand All @@ -46,41 +47,39 @@ const Tag = ({
const tagElem = (
<>
{editable ? (
<StyledTag
key={id}
closable={editable}
onClose={handleClose}
color="blue"
>
{isLongTag ? `${name.slice(0, 20)}...` : name}
</StyledTag>
<Tooltip title={toolTipTitle} key={toolTipTitle}>
<StyledTag
key={id}
closable={editable}
onClose={handleClose}
color="blue"
>
{isLongTag ? `${name.slice(0, 20)}...` : name}
</StyledTag>
</Tooltip>
) : (
<StyledTag role="link" key={id} onClick={onClick}>
{id ? (
<a
href={`/superset/all_entities/?id=${id}`}
target="_blank"
rel="noreferrer"
>
{isLongTag ? `${name.slice(0, 20)}...` : name}
</a>
) : isLongTag ? (
`${name.slice(0, 20)}...`
) : (
name
)}
</StyledTag>
<Tooltip title={toolTipTitle} key={toolTipTitle}>
<StyledTag role="link" key={id} onClick={onClick}>
{id ? (
<a
href={`/superset/all_entities/?id=${id}`}
target="_blank"
rel="noreferrer"
>
{isLongTag ? `${name.slice(0, 20)}...` : name}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we put a const at the top holding this 20 ? I see we're using it in a few places and would be good to just update it once if needed. Or instead of having a isLongTag bool, why not just truncating the name altogether and use that when rendering? if it's a long tag we are always truncating it either way.

</a>
) : isLongTag ? (
`${name.slice(0, 20)}...`
) : (
name
)}
</StyledTag>
</Tooltip>
)}
</>
);

return isLongTag ? (
<Tooltip title={name} key={name}>
{tagElem}
</Tooltip>
) : (
tagElem
);
return tagElem;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a test asserting we are rendering the "short" version of the tag when needed?

};

export default Tag;
6 changes: 5 additions & 1 deletion superset-frontend/src/components/Tags/TagsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ const TagsList = ({
/>
))}
{tags.length > tempMaxTags ? (
<Tag name={`+${extraTags}...`} onClick={expand} />
<Tag
name={`+${extraTags}...`}
onClick={expand}
toolTipTitle={tags.map(t => t.name).join(', ')}
/>
) : null}
</>
) : (
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/types/TagType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface TagType {
onClick?: MouseEventHandler<HTMLSpanElement>;
name: string;
index?: number | undefined;
toolTipTitle?: string;
}

export default TagType;