Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Truncation Component #1500

Merged
merged 45 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bfcc624
remove ESLint rules
seve May 26, 2020
0ce3767
add string-pixel-width dep
seve May 26, 2020
52a54b7
don't lint-staged src, only staged
seve May 26, 2020
9806bd3
add widthMap
seve May 26, 2020
136d515
create Truncate component
seve May 26, 2020
7dc211f
refactor in truncate component
seve May 26, 2020
f97c94c
add font load checking
seve May 27, 2020
56f143e
remove font-family styling
seve May 27, 2020
f0faf36
render Truncate's child instead of creating own component to render
seve May 27, 2020
241f219
refactor to use Truncate component
seve May 27, 2020
13d24b6
add span back
seve May 27, 2020
8c6d806
support children
seve May 27, 2020
318ca86
remove maybeTruncateString
seve May 27, 2020
6ce95d4
sub in Truncate component
seve May 27, 2020
ae295b0
add bold prop
seve May 27, 2020
1e9c17d
accurately compute largest possible string
seve May 28, 2020
fb998dc
remove logs
seve May 28, 2020
1976c15
tweak truncation method
seve May 28, 2020
f523133
memoize comp function
seve May 28, 2020
bde5e32
explain disable
seve May 28, 2020
618c4f1
fix bugs w/ abs/floor
seve May 28, 2020
7db76d3
tweak widths
seve May 28, 2020
cb94a10
tweak widths
seve May 28, 2020
2c50b3d
fix font size
seve May 28, 2020
607a1d3
remove border
seve May 28, 2020
716ba2b
move test-id
seve May 28, 2020
aac4d8a
attempt css solution
seve Jun 1, 2020
02c291a
Revert "attempt css solution"
seve Jun 1, 2020
8052e37
CSS solution v2
seve Jun 1, 2020
a4d7136
remove string-pixel-width
seve Jun 1, 2020
72d4fb1
remove widthsMap
seve Jun 1, 2020
b3fcc3a
remove dead code
seve Jun 2, 2020
31eb284
remove "data-truncated" as it is always true
seve Jun 2, 2020
215ef29
tweak label width
seve Jun 2, 2020
6bf6448
fix e2e tests
seve Jun 3, 2020
16129de
remove testing string
seve Jun 3, 2020
e56e539
e2e annotations tweaks
seve Jun 3, 2020
6e03233
correct snapshot
seve Jun 4, 2020
e61aaf4
remove resolves
seve Jun 4, 2020
345cf38
check for labels
seve Jun 4, 2020
eba2854
add test-id
seve Jun 4, 2020
c6cd236
format fix
seve Jun 4, 2020
e5f1a45
update snapshot
seve Jun 4, 2020
25492d1
fix color
seve Jun 4, 2020
5b14b61
pull constants out where available
seve Jun 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions client/configuration/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,7 @@ module.exports = {
"react/jsx-filename-extension": "off",
"comma-dangle": "off",
"no-underscore-dangle": "off",
quotes: ["error", "double"],
seve marked this conversation as resolved.
Show resolved Hide resolved
seve marked this conversation as resolved.
Show resolved Hide resolved
"implicit-arrow-linebreak": "off",
"operator-linebreak": [
"error",
"after",
{ overrides: { "?": "before", ":": "before" } },
],
"no-console": "off",
"spaced-comment": ["error", "always", { exceptions: ["*"] }],
"no-param-reassign": "off",
Expand Down
2 changes: 1 addition & 1 deletion client/configuration/lint-staged/lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = {
"./src/**/*.js": "eslint --fix ./src/",
"./src/**/*.js": "eslint --fix",
seve marked this conversation as resolved.
Show resolved Hide resolved
};
112 changes: 46 additions & 66 deletions client/src/components/categorical/category/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import React from "react";
import _ from "lodash";
import { connect } from "react-redux";
import { FaChevronRight, FaChevronDown } from "react-icons/fa";
import { AnchorButton, Button, Tooltip, Position } from "@blueprintjs/core";
import { AnchorButton, Button, Tooltip } from "@blueprintjs/core";
import CategoryFlipperLayout from "./categoryFlipperLayout";
import AnnoMenu from "./annoMenuCategory";
import AnnoDialogEditCategoryName from "./annoDialogEditCategoryName";
import AnnoDialogAddLabel from "./annoDialogAddLabel";
import Truncate from "../../util/truncate";

import * as globals from "../../../globals";
import maybeTruncateString from "../../../util/maybeTruncateString";

@connect((state, ownProps) => {
const { metadataField } = ownProps;
Expand All @@ -22,6 +22,8 @@ import maybeTruncateString from "../../../util/maybeTruncateString";
};
})
class Category extends React.Component {
_labelWidth = globals.leftSidebarWidth - 80;
seve marked this conversation as resolved.
Show resolved Hide resolved

constructor(props) {
super(props);
this.state = {
Expand Down Expand Up @@ -114,10 +116,6 @@ class Category extends React.Component {
We are still loading this category, so render a "busy" signal.
*/
const { metadataField } = this.props;
const truncatedString = maybeTruncateString(
metadataField,
globals.categoryDisplayStringMaxLength
);

const checkboxID = `category-select-${metadataField}`;

Expand Down Expand Up @@ -145,26 +143,17 @@ class Category extends React.Component {
<input disabled id={checkboxID} checked type="checkbox" />
<span className="bp3-control-indicator" />
</label>
<Tooltip
content={metadataField}
disabled={truncatedString === null}
hoverOpenDelay={globals.tooltipHoverOpenDelayQuick}
position={Position.LEFT}
usePortal
modifiers={{
preventOverflow: { enabled: false },
hide: { enabled: false },
}}
>
<Truncate>
<span
style={{
cursor: "pointer",
display: "inline-block",
width: this._labelWidth,
}}
>
{truncatedString || metadataField}
{metadataField}
</span>
</Tooltip>
</Truncate>
</div>
<div>
<Button minimal loading intent="primary" />
Expand Down Expand Up @@ -199,21 +188,22 @@ class Category extends React.Component {
false
);

const truncatedString = maybeTruncateString(
metadataField,
globals.categoryDisplayStringMaxLength
);

if (
!isUserAnno &&
schema?.annotations?.obsByName[metadataField]?.categories?.length === 1
) {
return (
<div style={{ marginBottom: 10, marginTop: 4 }}>
<span style={{ fontWeight: 700 }}>
{truncatedString || metadataField}
</span>
: {schema.annotations.obsByName[metadataField].categories[0]}
<Truncate>
<span style={{ maxWidth: 150, fontWeight: 700 }}>
{metadataField}
</span>
</Truncate>
<Truncate>
<span style={{ maxWidth: 150 }}>
{`: ${schema.annotations.obsByName[metadataField].categories[0]}`}
</span>
</Truncate>
</div>
);
}
Expand Down Expand Up @@ -246,46 +236,36 @@ class Category extends React.Component {
/>
<span className="bp3-control-indicator" />
</label>
<Tooltip
content={metadataField}
disabled={truncatedString === null}
hoverOpenDelay={globals.tooltipHoverOpenDelayQuick}
position={Position.LEFT}
usePortal
modifiers={{
preventOverflow: { enabled: false },
hide: { enabled: false },
<span
role="menuitem"
tabIndex="0"
data-testid={`${metadataField}:category-expand`}
onKeyPress={(e) => {
if (e.key === "Enter") {
this.handleCategoryClick();
}
}}
style={{
cursor: "pointer",
width: this._labelWidth,
}}
onClick={this.handleCategoryClick}
>
<span
role="menuitem"
tabIndex="0"
data-testid={`${metadataField}:category-expand`}
onKeyPress={(e) => {
if (e.key === "Enter") {
this.handleCategoryClick();
}
}}
style={{
cursor: "pointer",
display: "inline-block",
}}
onClick={this.handleCategoryClick}
>
{truncatedString || metadataField}
{isExpanded ? (
<FaChevronDown
data-testclass="category-expand-is-expanded"
style={{ fontSize: 10, marginLeft: 5 }}
/>
) : (
<FaChevronRight
data-testclass="category-expand-is-not-expanded"
style={{ fontSize: 10, marginLeft: 5 }}
/>
)}
</span>
</Tooltip>
<Truncate>
<span style={{ width: this._labelWidth }}>{metadataField}</span>
</Truncate>
{isExpanded ? (
<FaChevronDown
data-testclass="category-expand-is-expanded"
style={{ fontSize: 10, marginLeft: 5 }}
/>
) : (
<FaChevronRight
data-testclass="category-expand-is-not-expanded"
style={{ fontSize: 10, marginLeft: 5 }}
/>
)}
</span>
</div>
{<AnnoDialogEditCategoryName metadataField={metadataField} />}
{<AnnoDialogAddLabel metadataField={metadataField} />}
Expand Down
33 changes: 10 additions & 23 deletions client/src/components/categorical/value/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ import {
Position,
Icon,
PopoverInteractionKind,
Tooltip,
} from "@blueprintjs/core";
import Occupancy from "./occupancy";
import * as globals from "../../../globals";
import styles from "../categorical.css";
import AnnoDialog from "../annoDialog";
import LabelInput from "../labelInput";
import Truncate from "../../util/truncate";

import { AnnotationsHelpers } from "../../../util/stateManager";
import maybeTruncateString from "../../../util/maybeTruncateString";
import { labelPrompt, isLabelErroneous } from "../labelUtil";

/* this is defined outside of the class so we can use it in connect() */
Expand Down Expand Up @@ -317,13 +316,6 @@ class CategoryValue extends React.Component {
categories = schema.annotations.obsByName[colorAccessor]?.categories;
}

const truncatedString = maybeTruncateString(
displayString,
colorAccessor && !isColorBy
? globals.categoryLabelDisplayStringShortLength
: globals.categoryLabelDisplayStringLongLength
);

const editModeActive =
isUserAnno &&
annotations.labelEditable.category === metadataField &&
Expand All @@ -332,6 +324,11 @@ class CategoryValue extends React.Component {

const valueToggleLabel = `value-toggle-checkbox-${displayString}`;

const labelWidth =
colorAccessor && !isColorBy
? globals.leftSidebarWidth - 145 - 15 - 100
seve marked this conversation as resolved.
Show resolved Hide resolved
: globals.leftSidebarWidth - 145 - 15;

return (
<div
key={i}
Expand Down Expand Up @@ -384,21 +381,12 @@ class CategoryValue extends React.Component {
onMouseLeave={this.handleMouseEnter}
/>
</label>
<Tooltip
content={displayString}
disabled={truncatedString === null}
hoverOpenDelay={globals.tooltipHoverOpenDelayQuick}
position={Position.LEFT}
usePortal
modifiers={{
preventOverflow: { enabled: false },
hide: { enabled: false },
}}
>
<Truncate>
<span
data-testid={`categorical-value-${metadataField}-${displayString}`}
data-testclass="categorical-value"
style={{
width: labelWidth,
color:
displayString === globals.unassignedCategoryLabel
? "#ababab"
Expand All @@ -411,13 +399,12 @@ class CategoryValue extends React.Component {
overflow: "hidden",
lineHeight: "1.1em",
height: "1.1em",
wordBreak: "break-all",
verticalAlign: "middle",
}}
>
{truncatedString || displayString}
{displayString}
</span>
</Tooltip>
</Truncate>
{editModeActive ? (
<div>
<AnnoDialog
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/categorical/value/occupancy.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Occupancy extends React.PureComponent {
else this.createHistogram();
}}
/>
<div key="text" style={{ fontFamily: "Roboto", fontSize: "14px" }}>
<div key="text" style={{ fontSize: "14px" }}>
<p style={{ margin: "0" }}>
This histograms shows the distribution of{" "}
<strong>{colorAccessor}</strong> within{" "}
Expand Down
1 change: 0 additions & 1 deletion client/src/components/graph/overlays/centroidLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class CentroidLabels extends PureComponent {
textAnchor="middle"
data-label={label}
style={{
fontFamily: "Roboto Condensed",
fontSize,
fontWeight,
fill: "black",
Expand Down
39 changes: 21 additions & 18 deletions client/src/components/leftSidebar/topLeftLogoAndTitle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import { connect } from "react-redux";
import * as globals from "../../globals";
import Logo from "../framework/logo";
import Truncate from "../util/truncate";
seve marked this conversation as resolved.
Show resolved Hide resolved

@connect((state) => ({
datasetTitle: state.config?.displayNames?.dataset ?? "",
Expand All @@ -13,16 +14,8 @@ import Logo from "../framework/logo";
class LeftSideBar extends React.Component {
render() {
const { datasetTitle, aboutURL } = this.props;

const displayTitle =
datasetTitle.length > globals.datasetTitleMaxCharacterCount
? `${datasetTitle.substring(
0,
Math.floor(globals.datasetTitleMaxCharacterCount / 2)
)}…${datasetTitle.slice(
-Math.floor(globals.datasetTitleMaxCharacterCount / 2)
)}`
: datasetTitle;
const width = 190;
seve marked this conversation as resolved.
Show resolved Hide resolved
const fontSize = 14;

return (
<div
Expand Down Expand Up @@ -60,26 +53,36 @@ class LeftSideBar extends React.Component {
gene
</span>
<div
data-testid="header"
style={{
fontSize: 14,
fontSize,
position: "relative",
top: -6,
display: "inline-block",
width: "190px",
width,
marginLeft: "7px",
height: "1.2em",
overflow: "hidden",
wordBreak: "break-all",
}}
title={datasetTitle}
>
{aboutURL ? (
<a href={aboutURL} target="_blank" rel="noopener noreferrer">
{displayTitle}
</a>
<Truncate>
<a
style={{ width: 185 }}
href={aboutURL}
data-testid="header"
target="_blank"
rel="noopener noreferrer"
>
{datasetTitle}
</a>
</Truncate>
) : (
displayTitle
<Truncate>
<span style={{ width: 185 }} data-testid="header">
{datasetTitle}
</span>
</Truncate>
)}
</div>
</div>
Expand Down