add/fix label tooltips (#1278)

* Move tooltip to right

* Change function to only return truncated string

* add tooltip to category label

* use position instead of PopoutPosition
This commit is contained in:
Severiano Badajoz
2020-03-23 10:28:54 -07:00
committed by GitHub
parent d99b84ba09
commit b249df9036
3 changed files with 65 additions and 45 deletions
+25 -5
View File
@@ -2,7 +2,13 @@ import React from "react";
import _ from "lodash"; import _ from "lodash";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { FaChevronRight, FaChevronDown } from "react-icons/fa"; import { FaChevronRight, FaChevronDown } from "react-icons/fa";
import { AnchorButton, Button, Tooltip, Icon } from "@blueprintjs/core"; import {
AnchorButton,
Button,
Tooltip,
Icon,
Position
} from "@blueprintjs/core";
import CategoryFlipperLayout from "./categoryFlipperLayout"; import CategoryFlipperLayout from "./categoryFlipperLayout";
import AnnoMenu from "./annoMenuCategory"; import AnnoMenu from "./annoMenuCategory";
import AnnoDialogEditCategoryName from "./annoDialogEditCategoryName"; import AnnoDialogEditCategoryName from "./annoDialogEditCategoryName";
@@ -164,6 +170,11 @@ class Category extends React.Component {
false false
); );
const truncatedString = maybeTruncateString(
metadataField,
globals.categoryDisplayStringMaxLength
);
return ( return (
<CategoryFlipperLayout <CategoryFlipperLayout
metadataField={metadataField} metadataField={metadataField}
@@ -191,6 +202,17 @@ class Category extends React.Component {
/> />
<span className="bp3-control-indicator" /> <span className="bp3-control-indicator" />
</label> </label>
<Tooltip
content={metadataField}
disabled={truncatedString === null}
hoverOpenDelay={globals.tooltipHoverOpenDelayQuick}
position={Position.LEFT}
usePortal
modifiers={{
preventOverflow: { enabled: false },
hide: { enabled: false }
}}
>
<span <span
data-testid={`${metadataField}:category-expand`} data-testid={`${metadataField}:category-expand`}
style={{ style={{
@@ -209,10 +231,7 @@ class Category extends React.Component {
{isUserAnno ? ( {isUserAnno ? (
<Icon style={{ marginRight: 5 }} icon="tag" iconSize={16} /> <Icon style={{ marginRight: 5 }} icon="tag" iconSize={16} />
) : null} ) : null}
{maybeTruncateString( {truncatedString || metadataField}
metadataField,
globals.categoryDisplayStringMaxLength
)}
{isExpanded ? ( {isExpanded ? (
<FaChevronDown <FaChevronDown
data-testclass="category-expand-is-expanded" data-testclass="category-expand-is-expanded"
@@ -225,6 +244,7 @@ class Category extends React.Component {
/> />
)} )}
</span> </span>
</Tooltip>
</div> </div>
{<AnnoDialogEditCategoryName metadataField={metadataField} />} {<AnnoDialogEditCategoryName metadataField={metadataField} />}
{<AnnoDialogAddLabel metadataField={metadataField} />} {<AnnoDialogAddLabel metadataField={metadataField} />}
@@ -393,6 +393,12 @@ class CategoryValue extends React.Component {
content={displayString} content={displayString}
disabled={truncatedString === null} disabled={truncatedString === null}
hoverOpenDelay={globals.tooltipHoverOpenDelayQuick} hoverOpenDelay={globals.tooltipHoverOpenDelayQuick}
position={Position.LEFT}
usePortal
modifiers={{
preventOverflow: { enabled: false },
hide: { enabled: false }
}}
> >
<span <span
data-testid={`categorical-value-${metadataField}-${displayString}`} data-testid={`categorical-value-${metadataField}-${displayString}`}
+4 -10
View File
@@ -1,18 +1,12 @@
const maybeTruncateString = (str, maxLength) => { const maybeTruncateString = (str, maxLength) => {
let truncatedString = null; let truncatedString = null;
if ( if (str.length > maxLength) {
str.length > maxLength truncatedString = `${str.slice(0, maxLength / 2)}…${str.slice(
) {
truncatedString = `${str.slice(
0,
maxLength / 2
)}…${str.slice(
-maxLength / 2 -maxLength / 2
)}`; )}`;
} }
return truncatedString || str; return truncatedString;
} };
export default maybeTruncateString; export default maybeTruncateString;