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鈥檒l 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 37 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
5 changes: 5 additions & 0 deletions client/__tests__/e2e/__snapshots__/e2e.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`did launch page launched 1`] = `"<span style=\\"width: 185px; display: flex; overflow: hidden; justify-content: flex-start;\\"><span style=\\"overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 1; min-width: 5px;\\">pbm</span><span style=\\"color: transparent; position: relative; overflow: hidden; white-space: nowrap;\\">c3k<span style=\\"position: absolute; right: 0px; color: initial;\\">c3k</span></span></span>"`;

exports[`metadata loads categories and values from dataset appear 1`] = `undefined`;
seve marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions client/__tests__/e2e/cellxgeneActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ export const cellxgeneActions = (page, utils) => ({
(rows) =>
Object.fromEntries(
rows.map((row) => {
const cat = row.querySelector(
"[data-testclass='categorical-value']"
).innerText;
const cat = row
.querySelector("[data-testclass='categorical-value']")
.getAttribute("aria-label");

const count = row.querySelector(
"[data-testclass='categorical-value-count']"
).innerText;
Expand Down
12 changes: 7 additions & 5 deletions client/__tests__/e2e/e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ afterAll(() => {

describe("did launch", () => {
test("page launched", async () => {
const element = await utils.getOneElementInnerHTML("[data-testid='header']");
expect(element).toBe(data.title);
const element = await utils.getOneElementInnerHTML(
"[data-testid='header']"
);
expect(element).toMatchSnapshot();
});

test("terms of service, if they are there", async () => {
Expand All @@ -46,10 +48,10 @@ describe("did launch", () => {
describe("metadata loads", () => {
test("categories and values from dataset appear", async () => {
for (const label in data.categorical) {
const categoryName = await utils.getOneElementInnerText(
const elem = await utils.getOneElementInnerHTML(
`[data-testid="category-${label}"]`
);
expect(categoryName).toMatch(label);
).resolves;
expect(elem).toMatchSnapshot();
await utils.clickOn(`${label}:category-expand`);
const categories = await cxgActions.getAllCategoriesAndCounts(label);
expect(Object.keys(categories)).toMatchObject(
Expand Down
12 changes: 7 additions & 5 deletions client/__tests__/e2e/e2eAnnotations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ describe.each([

async function assertCategoryExists(categoryName) {
const handle = await utils.waitByID(`${categoryName}:category-expand`);
const result = await handle.evaluate((node) => node.innerText);
// slice beginning and end of category name result to account for truncation of long names
expect(result.slice(0, 10)).toBe(categoryName.slice(0, 10));
expect(result.slice(-10)).toBe(categoryName.slice(-10));
const result = await handle.evaluate((node) =>
node.getAttribute("aria-label")
);
expect(result).toBe(categoryName);
}

async function assertCategoryDoesNotExist(categoryName) {
Expand All @@ -222,7 +222,9 @@ describe.each([
const previous = await utils.waitByID(
`categorical-value-${categoryName}-${labelName}`
);
expect(await previous.evaluate((node) => node.innerText)).toBe(labelName);
expect(
await previous.evaluate((node) => node.getAttribute("aria-label"))
).toBe(labelName);
}

async function assertLabelDoesNotExist(categoryName, labelName) {
Expand Down
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
};
113 changes: 47 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 - 100;

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,37 @@ 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",
}}
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={{ maxWidth: 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