import * as React from 'react' import * as q from '../../../../backend/src/Model' import { ExpansionPanel, ExpansionPanelDetails, ExpansionPanelSummary, Fade, Paper, Popper, Typography, } from '@material-ui/core' import { StyleRulesCallback, Theme, withStyles } from '@material-ui/core/styles' import { AppState } from '../../reducers' import Copy from '../Copy' import ExpandMore from '@material-ui/icons/ExpandMore' import MessageHistory from './MessageHistory' import NodeStats from './NodeStats' import Publish from './Publish/Publish' import Topic from './Topic' import ValueRenderer from './ValueRenderer' import { connect } from 'react-redux' interface Props { node?: q.TreeNode, classes: any, theme: Theme, connectionId?: string, } interface State { node: q.TreeNode, compareMessage?: q.Message } class Sidebar extends React.Component { private valueRef: any = React.createRef() private updateNode = () => { this.setState(this.state) } constructor(props: any) { super(props) console.error('Find and fix me #state') this.state = { node: new q.Tree() } } public static styles: StyleRulesCallback = (theme: Theme) => { return { drawer: { display: 'block', height: '100%', }, valuePaper: { margin: `${theme.spacing.unit}px ${theme.spacing.unit}px ${theme.spacing.unit}px ${theme.spacing.unit}px`, }, heading: { fontSize: theme.typography.pxToRem(15), fontWeight: theme.typography.fontWeightRegular, }, } } public componentWillReceiveProps(nextProps: Props) { this.props.node && this.removeUpdateListener(this.props.node) nextProps.node && this.registerUpdateListener(nextProps.node) this.props.node && this.setState({ node: this.props.node }) if (this.props.node !== nextProps.node) { this.setState({ compareMessage: undefined }) } } private registerUpdateListener(node: q.TreeNode) { node.onMerge.subscribe(this.updateNode) node.onMessage.subscribe(this.updateNode) } private removeUpdateListener(node: q.TreeNode) { node.onMerge.unsubscribe(this.updateNode) node.onMessage.unsubscribe(this.updateNode) } public render() { return (
{this.renderNode()}
) } private detailsStyle = { padding: '0px 16px 8px 8px', display: 'block' } private renderNode() { const { classes, node } = this.props const copyTopic = node ? : null const copyValue = node && node.message ? : null const summeryStyle = { minHeight: '0' } return (
} style={summeryStyle}> Topic {copyTopic} } style={summeryStyle}> Value {copyValue}
{({ TransitionProps }) => ( )}
} style={summeryStyle}> Publish } style={summeryStyle}> Stats {this.renderNodeStats()}
) } private handleMessageHistorySelect = (message: q.Message) => { if (message !== this.state.compareMessage) { this.setState({ compareMessage: message }) } else { this.setState({ compareMessage: undefined }) } } private renderNodeStats() { if (!this.props.node) { return null } return ( ) } } const mapStateToProps = (state: AppState) => { return { node: state.selectedTopic, } } export default withStyles(Sidebar.styles, { withTheme: true })(connect(mapStateToProps)(Sidebar))