diff --git a/app/src/components/ConnectionSetup/AdvancedConnectionSettings.tsx b/app/src/components/ConnectionSetup/AdvancedConnectionSettings.tsx index 550f6bb..0b529a7 100644 --- a/app/src/components/ConnectionSetup/AdvancedConnectionSettings.tsx +++ b/app/src/components/ConnectionSetup/AdvancedConnectionSettings.tsx @@ -162,14 +162,6 @@ const styles = (theme: Theme) => ({ marginTop: theme.spacing(3), float: 'right' as 'right', }, - certificateName: { - width: '100%', - height: 'calc(1em + 4px)', - overflow: 'hidden' as 'hidden', - whiteSpace: 'nowrap' as 'nowrap', - textOverflow: 'ellipsis' as 'ellipsis', - color: theme.palette.text.hint, - }, }) export default connect( diff --git a/app/src/components/ConnectionSetup/ProfileList.tsx b/app/src/components/ConnectionSetup/ProfileList.tsx deleted file mode 100644 index 5b2926a..0000000 --- a/app/src/components/ConnectionSetup/ProfileList.tsx +++ /dev/null @@ -1,120 +0,0 @@ -import * as React from 'react' -import { AddButton } from './AddButton' -import { AppState } from '../../reducers' -import { bindActionCreators } from 'redux' -import { connect } from 'react-redux' -import { connectionManagerActions } from '../../actions' -import { ConnectionOptions, toMqttConnection } from '../../model/ConnectionOptions' -import { Theme, withStyles } from '@material-ui/core/styles' -import { List, ListItem, ListSubheader, Typography } from '@material-ui/core' - -interface Props { - classes: any - selected?: string - connections: { [s: string]: ConnectionOptions } - actions: any -} - -class ProfileList extends React.Component { - constructor(props: Props) { - super(props) - } - - private addConnectionButton() { - return ( - - - - ) - } - - public render() { - return ( - {this.addConnectionButton()}Connections} - > -
- {Object.values(this.props.connections).map(connection => ( - - ))} -
-
- ) - } -} - -const styles = (theme: Theme) => ({ - list: { - marginTop: theme.spacing(1), - height: `calc(100% - ${theme.spacing(6)})`, - overflowY: 'auto' as 'auto', - }, -}) - -const mapDispatchToProps = (dispatch: any) => { - return { - actions: bindActionCreators(connectionManagerActions, dispatch), - } -} - -interface ConnectionItemProps { - connection: ConnectionOptions - actions: any - selected: boolean - classes: any -} - -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 ( - props.actions.selectConnection(props.connection.id)} - > - {props.connection.name || 'mqtt broker'} - {connection && connection.url} - - ) -}) - -const ConnectionItem = connect( - null, - mapDispatchToProps -)(connectionItemRenderer) - -const mapStateToProps = (state: AppState) => { - return { - connections: state.connectionManager.connections, - selected: state.connectionManager.selected, - } -} - -export default connect( - mapStateToProps, - mapDispatchToProps -)(withStyles(styles)(ProfileList)) diff --git a/app/src/components/ConnectionSetup/AddButton.tsx b/app/src/components/ConnectionSetup/ProfileList/AddButton.tsx similarity index 64% rename from app/src/components/ConnectionSetup/AddButton.tsx rename to app/src/components/ConnectionSetup/ProfileList/AddButton.tsx index b9eb588..ef6b831 100644 --- a/app/src/components/ConnectionSetup/AddButton.tsx +++ b/app/src/components/ConnectionSetup/ProfileList/AddButton.tsx @@ -16,8 +16,10 @@ const styles = (theme: Theme) => ({ export const AddButton = withStyles(styles)((props: { classes: any; action: any }) => { return ( - - - + + + + + ) }) diff --git a/app/src/components/ConnectionSetup/ProfileList/ConnectionItem.tsx b/app/src/components/ConnectionSetup/ProfileList/ConnectionItem.tsx new file mode 100644 index 0000000..de393d2 --- /dev/null +++ b/app/src/components/ConnectionSetup/ProfileList/ConnectionItem.tsx @@ -0,0 +1,57 @@ +import React from 'react' +import { connect } from 'react-redux' +import { ListItem, Typography } from '@material-ui/core' +import { toMqttConnection, ConnectionOptions } from '../../../model/ConnectionOptions' +import { withStyles, Theme } from '@material-ui/core/styles' +import { bindActionCreators } from 'redux' +import { connectionManagerActions } from '../../../actions' + +export interface Props { + connection: ConnectionOptions + actions: any + selected: boolean + classes: any +} + +const ConnectionItem = (props: Props) => { + const connection = props.connection.host && toMqttConnection(props.connection) + return ( + props.actions.selectConnection(props.connection.id)} + > + {props.connection.name || 'mqtt broker'} + {connection && connection.url} + + ) +} + +export const mapDispatchToProps = (dispatch: any) => { + return { + actions: bindActionCreators(connectionManagerActions, dispatch), + } +} + +export 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', + }, +}) + +export default connect( + null, + mapDispatchToProps +)(withStyles(connectionItemStyle)(ConnectionItem)) diff --git a/app/src/components/ConnectionSetup/ProfileList/index.tsx b/app/src/components/ConnectionSetup/ProfileList/index.tsx new file mode 100644 index 0000000..5bcbd59 --- /dev/null +++ b/app/src/components/ConnectionSetup/ProfileList/index.tsx @@ -0,0 +1,66 @@ +import ConnectionItem from './ConnectionItem' +import React from 'react' +import { AddButton } from './AddButton' +import { AppState } from '../../../reducers' +import { bindActionCreators } from 'redux' +import { connect } from 'react-redux' +import { connectionManagerActions } from '../../../actions' +import { ConnectionOptions } from '../../../model/ConnectionOptions' +import { List, ListSubheader } from '@material-ui/core' +import { Theme, withStyles } from '@material-ui/core/styles' + +interface Props { + classes: any + selected?: string + connections: { [s: string]: ConnectionOptions } + actions: any +} + +function ProfileList(props: Props) { + const { actions, classes, connections, selected } = props + + return ( + + + Connections + + } + > +
+ {Object.values(connections).map(connection => ( + + ))} +
+
+ ) +} + +const styles = (theme: Theme) => ({ + list: { + marginTop: theme.spacing(1), + height: `calc(100% - ${theme.spacing(6)})`, + overflowY: 'auto' as 'auto', + }, +}) + +const mapDispatchToProps = (dispatch: any) => { + return { + actions: bindActionCreators(connectionManagerActions, dispatch), + } +} + +const mapStateToProps = (state: AppState) => { + return { + connections: state.connectionManager.connections, + selected: state.connectionManager.selected, + } +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(withStyles(styles)(ProfileList))