From 0b6a1e42d6ea9717562c18ce0a62da7d41c8c037 Mon Sep 17 00:00:00 2001 From: Thomas Nordquist Date: Sat, 13 Jul 2019 12:40:47 +0200 Subject: [PATCH] Improve payload truncation in tree --- .../Tree/TreeNode/TreeNodeSubnodes.tsx | 1 - .../Tree/TreeNode/TreeNodeTitle.tsx | 21 ++++++++++++++----- app/src/components/Tree/TreeNode/index.tsx | 14 ++++++------- app/src/components/Tree/TreeNode/styles.ts | 18 +++++++++------- 4 files changed, 34 insertions(+), 20 deletions(-) diff --git a/app/src/components/Tree/TreeNode/TreeNodeSubnodes.tsx b/app/src/components/Tree/TreeNode/TreeNodeSubnodes.tsx index b9d98c1..55c67e1 100644 --- a/app/src/components/Tree/TreeNode/TreeNodeSubnodes.tsx +++ b/app/src/components/Tree/TreeNode/TreeNodeSubnodes.tsx @@ -53,7 +53,6 @@ function TreeNodeSubnodes(props: Props) { { treeNode: q.TreeNode + lastUpdate: number name?: string | undefined collapsed?: boolean | undefined didSelectNode: any @@ -13,7 +14,7 @@ export interface TreeNodeProps extends React.HTMLAttributes { classes: any } -class TreeNodeTitle extends React.Component { +class TreeNodeTitle extends React.PureComponent { private renderSourceEdge() { const name = this.props.name || (this.props.treeNode.sourceEdge && this.props.treeNode.sourceEdge.name) @@ -24,13 +25,23 @@ class TreeNodeTitle extends React.Component { ) } + private truncatedMessage() { + const limit = 350 + if (!this.props.treeNode.message || !this.props.treeNode.message.value) { + return '' + } + + const str = Base64Message.toUnicodeString(this.props.treeNode.message.value) + return str.length > limit ? `${str.slice(0, limit)}…` : str + } + private renderValue() { return this.props.treeNode.message && this.props.treeNode.message.value && this.props.treeNode.message.length > 0 ? ( {' '} - = {Base64Message.toUnicodeString(this.props.treeNode.message.value).slice(0, 120)} + = {this.truncatedMessage()} ) : null } diff --git a/app/src/components/Tree/TreeNode/index.tsx b/app/src/components/Tree/TreeNode/index.tsx index 8ccca06..3dd17cc 100644 --- a/app/src/components/Tree/TreeNode/index.tsx +++ b/app/src/components/Tree/TreeNode/index.tsx @@ -19,7 +19,6 @@ export interface Props { name?: string | undefined collapsed?: boolean | undefined classes: any - className?: string lastUpdate: number actions: typeof treeActions selectTopicAction: (treeNode: q.TreeNode) => void @@ -28,7 +27,7 @@ export interface Props { } function TreeNodeComponent(props: Props) { - const { actions, classes, className, settings, theme, treeNode, lastUpdate, name } = props + const { actions, classes, settings, theme, treeNode, lastUpdate, name } = props const [collapsedOverride, setCollapsedOverride] = useState(undefined) const [selected, selectionLastUpdate, setSelected] = useSelectionState(false) const nodeRef = useRef() @@ -112,25 +111,26 @@ function TreeNodeComponent(props: Props) { const highlightClass = selected ? classes.selected : '' return ( -
-
+ -
+ {renderNodes()}
) diff --git a/app/src/components/Tree/TreeNode/styles.ts b/app/src/components/Tree/TreeNode/styles.ts index 237ff50..3ab4605 100644 --- a/app/src/components/Tree/TreeNode/styles.ts +++ b/app/src/components/Tree/TreeNode/styles.ts @@ -17,14 +17,15 @@ export const styles = (theme: Theme) => { color: theme.palette.text.secondary, }, displayBlock: { - display: 'block', + display: 'block' as 'block', }, node: { - display: 'block', - marginLeft: '10px', - '&:hover': { - backgroundColor: theme.palette.type === 'light' ? blueGrey[100] : theme.palette.primary.light, - }, + display: 'block' as 'block', + width: '100%', + overflow: 'hidden' as 'hidden', + textOverflow: 'ellipsis' as 'ellipsis', + whiteSpace: 'nowrap' as 'nowrap', + padding: '1px 0px 0px 0px', }, topicSelect: { float: 'right' as 'right', @@ -44,9 +45,12 @@ export const styles = (theme: Theme) => { lineHeight: '1em', display: 'inline-block' as 'inline-block', whiteSpace: 'nowrap' as 'nowrap', - padding: '1px 4px 0px 4px', height: '14px', + padding: '0 4px', margin: '1px 0px 2px 0px', + '&:hover': { + backgroundColor: theme.palette.type === 'light' ? blueGrey[100] : theme.palette.primary.light, + }, }, } }