Preview connection URI

This commit is contained in:
Thomas Nordquist
2019-02-17 10:36:56 +01:00
parent 9c863c8339
commit 804c96d041
4 changed files with 44 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ import { AppState } from '../../reducers'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { connectionManagerActions } from '../../actions' import { connectionManagerActions } from '../../actions'
import { ConnectionOptions } from '../../model/ConnectionOptions' import { ConnectionOptions, toMqttConnection } from '../../model/ConnectionOptions'
import { Theme, withStyles } from '@material-ui/core/styles' import { Theme, withStyles } from '@material-ui/core/styles'
import { import {
Modal, Modal,
@@ -34,7 +34,8 @@ class ConnectionSetup extends React.Component<Props, {}> {
} }
public render() { public render() {
const { classes, visible } = this.props const { classes, visible, connection } = this.props
const mqttConnection = connection && toMqttConnection(connection)
return ( return (
<div> <div>
<Modal open={visible} disableAutoFocus={true}> <Modal open={visible} disableAutoFocus={true}>
@@ -43,6 +44,9 @@ class ConnectionSetup extends React.Component<Props, {}> {
<div className={classes.right}> <div className={classes.right}>
<Toolbar> <Toolbar>
<Typography className={classes.title} variant="h6" color="inherit">MQTT Connection</Typography> <Typography className={classes.title} variant="h6" color="inherit">MQTT Connection</Typography>
<Typography className={classes.connectionUri}>
{mqttConnection && mqttConnection.url}
</Typography>
</Toolbar> </Toolbar>
{this.renderSettings()} {this.renderSettings()}
</div> </div>
@@ -70,6 +74,7 @@ class ConnectionSetup extends React.Component<Props, {}> {
const styles = (theme: Theme) => ({ const styles = (theme: Theme) => ({
title: { title: {
color: theme.palette.text.primary, color: theme.palette.text.primary,
whiteSpace: 'nowrap' as 'nowrap',
}, },
root: { root: {
margin: '13vw auto 0 auto', margin: '13vw auto 0 auto',
@@ -94,6 +99,15 @@ const styles = (theme: Theme) => ({
padding: `${2 * theme.spacing.unit}px`, padding: `${2 * theme.spacing.unit}px`,
flex: 10, flex: 10,
}, },
connectionUri: {
width: '27em',
textOverflow: 'ellipsis' as 'ellipsis',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
color: theme.palette.text.hint,
fontSize: '0.9em',
marginLeft: '24px',
},
}) })
const mapStateToProps = (state: AppState) => { const mapStateToProps = (state: AppState) => {

View File

@@ -4,12 +4,11 @@ import { AppState } from '../../reducers'
import { bindActionCreators } from 'redux' import { bindActionCreators } from 'redux'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import { connectionManagerActions } from '../../actions' import { connectionManagerActions } from '../../actions'
import { ConnectionOptions } from '../../model/ConnectionOptions' import { ConnectionOptions, toMqttConnection } from '../../model/ConnectionOptions'
import { Theme, withStyles } from '@material-ui/core/styles' import { Theme, withStyles } from '@material-ui/core/styles'
import { import {
List, List,
ListItem, ListItem,
ListItemText,
ListSubheader, ListSubheader,
Typography, Typography,
} from '@material-ui/core' } from '@material-ui/core'
@@ -63,21 +62,44 @@ interface ConnectionItemProps {
connection: ConnectionOptions, connection: ConnectionOptions,
actions: any, actions: any,
selected: boolean, selected: boolean,
classes: any
} }
const connectionItemRenderer = (props: ConnectionItemProps) => { const connectionItemStyle = (theme: Theme) => ({
name: {
width: '100%',
textOverflow: 'ellipsis' as 'ellipsis',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
},
details: {
width: '100%',
textOverflow: 'ellipsis' as 'ellipsis',
whiteSpace: 'nowrap' as 'nowrap',
overflow: 'hidden' as 'hidden',
color: theme.palette.text.hint,
fontSize: '0.7em',
},
})
const connectionItemRenderer = withStyles(connectionItemStyle)((props: ConnectionItemProps) => {
const connection = props.connection.host && toMqttConnection(props.connection)
return ( return (
<ListItem <ListItem
button={true} button={true}
selected={props.selected} selected={props.selected}
style={{ display: 'block' }}
onClick={() => props.actions.selectConnection(props.connection.id)} onClick={() => props.actions.selectConnection(props.connection.id)}
> >
<Typography style={{ width: '100%', textOverflow: 'ellipsis', whiteSpace: 'nowrap', overflow: 'hidden'}}> <Typography className={props.classes.name}>
{props.connection.name || 'mqtt broker'} {props.connection.name || 'mqtt broker'}
</Typography> </Typography>
<Typography className={props.classes.details}>
{ connection && connection.url }
</Typography>
</ListItem> </ListItem>
) )
} })
const ConnectionItem = connect(null, mapDispatchToProps)(connectionItemRenderer) const ConnectionItem = connect(null, mapDispatchToProps)(connectionItemRenderer)

View File

@@ -1,10 +1,7 @@
import * as React from 'react' import * as React from 'react'
import * as q from '../../../../backend/src/Model' import * as q from '../../../../backend/src/Model'
import { AppState } from '../../reducers'
import TreeNode from './TreeNode' import TreeNode from './TreeNode'
import { connect } from 'react-redux'
import { TopicOrder } from '../../reducers/Settings' import { TopicOrder } from '../../reducers/Settings'
import { Theme, withStyles } from '@material-ui/core' import { Theme, withStyles } from '@material-ui/core'
import { TopicViewModel } from '../../TopicViewModel' import { TopicViewModel } from '../../TopicViewModel'

View File

@@ -6,7 +6,7 @@ export interface ConnectionOptions {
type: 'mqtt' type: 'mqtt'
id: string id: string
host: string host: string
protocol: 'mqtt' | 'ws' | 'wss' protocol: 'mqtt' | 'ws'
basePath?: string basePath?: string
port: number port: number
name: string name: string