Add proper copy to clipboard

This commit is contained in:
Thomas Nordquist
2019-01-07 12:24:01 +01:00
parent e2192b11c7
commit d6a245893a
5 changed files with 22 additions and 15 deletions

View File

@@ -10,6 +10,7 @@ import NodeStats from './NodeStats'
import Topic from './Topic' import Topic from './Topic'
import { Typography } from '@material-ui/core' import { Typography } from '@material-ui/core'
import { withStyles, Theme, StyleRulesCallback } from '@material-ui/core/styles' import { withStyles, Theme, StyleRulesCallback } from '@material-ui/core/styles'
import Copy from '../Copy'
interface Props { interface Props {
node?: q.TreeNode | undefined, node?: q.TreeNode | undefined,
@@ -70,15 +71,15 @@ class Sidebar extends React.Component<Props, State> {
} }
private renderNode() { private renderNode() {
const { classes } = this.props const { classes, node } = this.props
if (!this.state.node) {
return null const copyTopic = node ? <Copy value={node.path()} /> : null
} const copyValue = node && node.message ? <Copy value={node.message.value} /> : null
return <div> return <div>
<ExpansionPanel key="topic" defaultExpanded={true}> <ExpansionPanel key="topic" defaultExpanded={true}>
<ExpansionPanelSummary expandIcon={<ExpandMore />}> <ExpansionPanelSummary expandIcon={<ExpandMore />}>
<Typography className={classes.heading}>Topic</Typography> <Typography className={classes.heading}>Topic {copyTopic}</Typography>
</ExpansionPanelSummary> </ExpansionPanelSummary>
<ExpansionPanelDetails> <ExpansionPanelDetails>
<Topic node={this.props.node} didSelectNode={this.updateNode} /> <Topic node={this.props.node} didSelectNode={this.updateNode} />
@@ -86,7 +87,7 @@ class Sidebar extends React.Component<Props, State> {
</ExpansionPanel> </ExpansionPanel>
<ExpansionPanel key="value" defaultExpanded={true}> <ExpansionPanel key="value" defaultExpanded={true}>
<ExpansionPanelSummary expandIcon={<ExpandMore />}> <ExpansionPanelSummary expandIcon={<ExpandMore />}>
<Typography className={classes.heading}>Value</Typography> <Typography className={classes.heading}>Value {copyValue}</Typography>
</ExpansionPanelSummary> </ExpansionPanelSummary>
<ExpansionPanelDetails> <ExpansionPanelDetails>
<ValueRenderer node={this.state.node} /> <ValueRenderer node={this.state.node} />

View File

@@ -2,7 +2,6 @@ import * as React from 'react'
import * as q from '../../../../backend/src/Model' import * as q from '../../../../backend/src/Model'
import { withStyles, Theme, StyleRulesCallback } from '@material-ui/core/styles' import { withStyles, Theme, StyleRulesCallback } from '@material-ui/core/styles'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
const copy = require('copy-text-to-clipboard')
interface Props { interface Props {
classes: any classes: any
@@ -51,10 +50,7 @@ class Topic extends React.Component<Props, {}> {
prev.concat([<span key={key += 1}>/</span>]).concat(current), prev.concat([<span key={key += 1}>/</span>]).concat(current),
) )
return <span style={{ lineHeight: '2.2em' }}> return <span style={{ lineHeight: '2.2em' }}>{joinedBreadCrumps}</span>
<a onClick={() => copy(this.props.node && this.props.node.path())}>📋</a>
{joinedBreadCrumps}
</span>
} }
} }

View File

@@ -91,7 +91,12 @@ export class Tree extends React.Component<Props, TreeState> {
} }
public render() { public render() {
return <Typography> const style: React.CSSProperties = {
lineHeight: '1.1',
cursor: 'default',
}
return <Typography style={ style }>
<TreeNode <TreeNode
animateChages={true} animateChages={true}
autoExpandLimit={3000} autoExpandLimit={3000}

View File

@@ -174,7 +174,7 @@ class TreeNode extends React.Component<TreeNodeProps, TreeNodeState> {
return {} return {}
} }
const isInViewPort = this.titleRef.current && isElementInViewport(this.titleRef.current) const isInViewPort = this.titleRef.current && isElementInViewport(this.titleRef.current)
const isDirty = this.dirtyMessage || this.dirtyEdges || this.collapsed() const isDirty = this.dirtyMessage || this.dirtyEdges
if (this.props.animateChages && isDirty && isInViewPort) { if (this.props.animateChages && isDirty && isInViewPort) {
if (!this.cssAnimationWasSetAt) { if (!this.cssAnimationWasSetAt) {
this.cssAnimationWasSetAt = performance.now() this.cssAnimationWasSetAt = performance.now()

View File

@@ -37,7 +37,13 @@ class TreeNodeTitle extends React.Component<TreeNodeProps, {}> {
onClick={() => { onClick={() => {
this.toggle() this.toggle()
this.props.didSelectNode && this.props.didSelectNode(this.props.treeNode) this.props.didSelectNode && this.props.didSelectNode(this.props.treeNode)
}}> }}
onMouseOver={() => {
if (this.props.treeNode.message) {
this.props.didSelectNode && this.props.didSelectNode(this.props.treeNode)
}
}}
>
{this.renderExpander()} {this.renderSourceEdge()} {this.renderCollapsedSubnodes()} {this.renderValue()} {this.renderExpander()} {this.renderSourceEdge()} {this.renderCollapsedSubnodes()} {this.renderValue()}
</span> </span>
} }
@@ -66,7 +72,6 @@ class TreeNodeTitle extends React.Component<TreeNodeProps, {}> {
return this.props.treeNode.message return this.props.treeNode.message
? <span ? <span
style={style} style={style}
onMouseOver={() => this.props.didSelectNode && this.props.didSelectNode(this.props.treeNode)}
> = {this.props.treeNode.message.value.toString()}</span> > = {this.props.treeNode.message.value.toString()}</span>
: null : null
} }