mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-03 14:28:11 +08:00
Create Truncation Component (#1500)
* remove ESLint rules
operator-linebreak is no different then default
quotes is overwriting prettier config
* add string-pixel-width dep
* don't lint-staged src, only staged
* add widthMap
* create Truncate component
* refactor in truncate component
* add font load checking
* remove font-family styling
* render Truncate's child instead of creating own component to render
* refactor to use Truncate component
* add span back
* support children
* remove maybeTruncateString
* sub in Truncate component
* add bold prop
* accurately compute largest possible string
* remove logs
* tweak truncation method
* memoize comp function
* explain disable
* fix bugs w/ abs/floor
* tweak widths
* tweak widths
* fix font size
* remove border
* move test-id
* attempt css solution
* Revert "attempt css solution"
This reverts commit aac4d8a6f6.
* CSS solution v2
* remove string-pixel-width
* remove widthsMap
* remove dead code
* remove "data-truncated" as it is always true
* tweak label width
* fix e2e tests
* remove testing string
* e2e annotations tweaks
* correct snapshot
* remove resolves
* check for labels
* add test-id
* format fix
* update snapshot
* fix color
* pull constants out where available
This commit is contained in:
@@ -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() */
|
||||
@@ -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 &&
|
||||
@@ -332,6 +324,26 @@ class CategoryValue extends React.Component {
|
||||
|
||||
const valueToggleLabel = `value-toggle-checkbox-${displayString}`;
|
||||
|
||||
const LEFT_MARGIN = 33;
|
||||
const CHECKBOX = 26;
|
||||
const CELL_NUMBER = 61;
|
||||
const ANNO_MENU = 26;
|
||||
const LABEL_MARGIN = 24;
|
||||
|
||||
const otherElementsWidth =
|
||||
LEFT_MARGIN +
|
||||
CHECKBOX +
|
||||
CELL_NUMBER +
|
||||
LABEL_MARGIN +
|
||||
(isUserAnno ? ANNO_MENU : 0);
|
||||
|
||||
const OCCUPANCY_WIDTH = 100;
|
||||
|
||||
const labelWidth =
|
||||
colorAccessor && !isColorBy
|
||||
? globals.leftSidebarWidth - otherElementsWidth - OCCUPANCY_WIDTH
|
||||
: globals.leftSidebarWidth - otherElementsWidth;
|
||||
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
@@ -384,21 +396,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"
|
||||
@@ -411,13 +414,13 @@ class CategoryValue extends React.Component {
|
||||
overflow: "hidden",
|
||||
lineHeight: "1.1em",
|
||||
height: "1.1em",
|
||||
wordBreak: "break-all",
|
||||
verticalAlign: "middle",
|
||||
marginRight: LABEL_MARGIN,
|
||||
}}
|
||||
>
|
||||
{truncatedString || displayString}
|
||||
{displayString}
|
||||
</span>
|
||||
</Tooltip>
|
||||
</Truncate>
|
||||
{editModeActive ? (
|
||||
<div>
|
||||
<AnnoDialog
|
||||
|
||||
@@ -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{" "}
|
||||
|
||||
Reference in New Issue
Block a user