mirror of
https://github.com/chanzuckerberg/cellxgene.git
synced 2026-10-09 15:30:56 +08:00
Conditionally truncate category string (#1206)
* maybe truncate string * add string formatting to test * correct import * destructuring * add maxlength * test * Respond to feedback from @bkmartinjr Co-authored-by: Matt Weiden <538456+mweiden@users.noreply.github.com>
This commit is contained in:
co-authored by
Matt Weiden
parent
28ddb60b2f
commit
234f25b782
@@ -183,8 +183,11 @@ describe.each([
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function assertCategoryExists(categoryName) {
|
async function assertCategoryExists(categoryName) {
|
||||||
const result = await utils.waitByID(`${categoryName}:category-expand`);
|
const handle = await utils.waitByID(`${categoryName}:category-expand`);
|
||||||
expect(await result.evaluate(node => node.innerText)).toBe(categoryName);
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function assertCategoryDoesNotExist(categoryName) {
|
async function assertCategoryDoesNotExist(categoryName) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import AnnoDialogEditCategoryName from "./annoDialogEditCategoryName";
|
|||||||
import AnnoDialogAddLabel from "./annoDialogAddLabel";
|
import AnnoDialogAddLabel from "./annoDialogAddLabel";
|
||||||
|
|
||||||
import * as globals from "../../globals";
|
import * as globals from "../../globals";
|
||||||
|
import maybeTruncateString from "../../util/maybeTruncateString";
|
||||||
|
|
||||||
@connect(state => ({
|
@connect(state => ({
|
||||||
colorAccessor: state.colors.colorAccessor,
|
colorAccessor: state.colors.colorAccessor,
|
||||||
@@ -204,7 +205,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}
|
||||||
{metadataField}
|
{maybeTruncateString(metadataField, globals.categoryDisplayStringMaxLength)}
|
||||||
{isExpanded ? (
|
{isExpanded ? (
|
||||||
<FaChevronDown
|
<FaChevronDown
|
||||||
data-testclass="category-expand-is-expanded"
|
data-testclass="category-expand-is-expanded"
|
||||||
|
|||||||
@@ -73,6 +73,7 @@ export const leftSidebarSectionHeading = {
|
|||||||
export const leftSidebarSectionPadding = 10;
|
export const leftSidebarSectionPadding = 10;
|
||||||
export const categoryLabelDisplayStringLongLength = 27;
|
export const categoryLabelDisplayStringLongLength = 27;
|
||||||
export const categoryLabelDisplayStringShortLength = 11;
|
export const categoryLabelDisplayStringShortLength = 11;
|
||||||
|
export const categoryDisplayStringMaxLength = 27;
|
||||||
|
|
||||||
export const maxUserDefinedGenes = 25;
|
export const maxUserDefinedGenes = 25;
|
||||||
export const maxGenes = 100;
|
export const maxGenes = 100;
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
const maybeTruncateString = (str, maxLength) => {
|
||||||
|
|
||||||
|
let truncatedString = null;
|
||||||
|
if (
|
||||||
|
str.length > maxLength
|
||||||
|
) {
|
||||||
|
truncatedString = `${str.slice(
|
||||||
|
0,
|
||||||
|
maxLength / 2
|
||||||
|
)}…${str.slice(
|
||||||
|
-maxLength / 2
|
||||||
|
)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return truncatedString || str;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default maybeTruncateString;
|
||||||
Reference in New Issue
Block a user