diff --git a/app/src/components/Layout/ContentView.tsx b/app/src/components/Layout/ContentView.tsx index a876a2e..379a097 100644 --- a/app/src/components/Layout/ContentView.tsx +++ b/app/src/components/Layout/ContentView.tsx @@ -19,8 +19,8 @@ interface Props { function ContentView(props: Props) { const [height, setHeight] = React.useState('100%') const [detectedHeight, setDetectedHeight] = React.useState(0) - const detectSize = React.useCallback((width, height) => { - setDetectedHeight(height) + const detectSize = React.useCallback((width, newHeight) => { + setDetectedHeight(newHeight) }, []) // Open chart panel on start and when a new chart is added but the panel is closed diff --git a/app/src/components/Sidebar/PlotHistory.tsx b/app/src/components/Sidebar/PlotHistory.tsx index 99ea753..1f8f029 100644 --- a/app/src/components/Sidebar/PlotHistory.tsx +++ b/app/src/components/Sidebar/PlotHistory.tsx @@ -14,7 +14,7 @@ interface Props { export default withTheme((props: Props) => { const [width, setWidth] = React.useState(300) const [tooltip, setTooltip] = React.useState({ value: undefined }) - const detectResize = React.useCallback(width => setWidth(width), []) + const detectResize = React.useCallback(newWidth => setWidth(newWidth), []) const hintFormatter = React.useCallback((point: any) => { return [ @@ -41,7 +41,11 @@ export default withTheme((props: Props) => { abbreviate(num)} /> void +}) { + const editorOptions = { + showLineNumbers: false, + tabSize: 2, + } + + return ( + + ) +} + +export default withTheme(Editor) diff --git a/app/src/components/Sidebar/Publish/EditorModeSelect.tsx b/app/src/components/Sidebar/Publish/EditorModeSelect.tsx new file mode 100644 index 0000000..85394bf --- /dev/null +++ b/app/src/components/Sidebar/Publish/EditorModeSelect.tsx @@ -0,0 +1,40 @@ +import * as React from 'react' +import { FormControlLabel, Radio, RadioGroup } from '@material-ui/core' + +interface Props { + value: string + onChange: (event: React.ChangeEvent<{}>, value: string) => void +} +export function EditorModeSelect(props: Props) { + const labelStyle = { margin: '0 8px 0 8px' } + return ( + + } + label="raw" + labelPlacement="top" + /> + } + label="xml" + labelPlacement="top" + /> + } + label="json" + labelPlacement="top" + /> + + ) +} diff --git a/app/src/components/Sidebar/Publish/Publish.tsx b/app/src/components/Sidebar/Publish/Publish.tsx index 098ee18..576efd0 100644 --- a/app/src/components/Sidebar/Publish/Publish.tsx +++ b/app/src/components/Sidebar/Publish/Publish.tsx @@ -8,31 +8,23 @@ import Navigation from '@material-ui/icons/Navigation' import { AppState } from '../../../reducers' import { bindActionCreators } from 'redux' import { connect } from 'react-redux' -import { default as AceEditor } from 'react-ace' import { globalActions, publishActions } from '../../../actions' -import 'brace/mode/json' -import 'brace/theme/dawn' -import 'brace/theme/monokai' -import 'brace/mode/xml' -import 'brace/mode/text' -import 'react-ace' import { Button, FormControlLabel, - Radio, - RadioGroup, - TextField, FormControl, InputLabel, Input, Checkbox, - MenuItem, Tooltip, Fab, Theme, withTheme, } from '@material-ui/core' +import { EditorModeSelect } from './EditorModeSelect' +import QosSelect from './QosSelect' +import Editor from './Editor' const sha1 = require('sha1') @@ -44,7 +36,6 @@ interface Props { globalActions: typeof globalActions retain: boolean editorMode: string - qos: 0 | 1 | 2 theme: Theme } @@ -53,16 +44,12 @@ interface State { } class Publish extends React.Component { - private editorOptions = { - showLineNumbers: false, - tabSize: 2, - } constructor(props: any) { super(props) this.state = { history: [] } } - private updatePayload = (payload: string, event?: any) => { + private updatePayload = (payload: string) => { this.props.actions.setPayload(payload) } @@ -170,7 +157,7 @@ class Publish extends React.Component { return (
- {this.renderEditorModeSelection()} + {this.renderFormatJson()}
{this.publishButton()}
@@ -178,82 +165,13 @@ class Publish extends React.Component { ) } - private renderEditorModeSelection() { - const labelStyle = { margin: '0 8px 0 8px' } - return ( - - } - label="raw" - labelPlacement="top" - /> - } - label="xml" - labelPlacement="top" - /> - } - label="json" - labelPlacement="top" - /> - - ) - } - - private onChangeQoS = (event: React.ChangeEvent) => { - const value = parseInt(event.target.value, 10) - if (value !== 0 && value !== 1 && value !== 2) { - return - } - - this.props.actions.setQoS(value) - } - private publishMode() { const labelStyle = { margin: '0 8px 0 8px' } - const itemStyle = { padding: '0' } - const tooltipStyle = { textAlign: 'center' as 'center', width: '100%' } - const qosSelect = ( - - - -
0
-
-
- - -
1
-
-
- - -
2
-
-
-
- ) + return (
- + } label="QoS" labelPlacement="start" /> { this.props.actions.setPayload(message.payload) } - private editor() { - return ( -
- {this.editorMode()} - {this.renderEditor()} - {this.publishMode()} -
- ) - } - - private renderEditor() { - return ( - - ) - } - public render() { return (
{this.topic()} - {this.editor()} +
+ {this.editorMode()} + + {this.publishMode()} +
{this.history()}
) @@ -340,7 +234,6 @@ const mapStateToProps = (state: AppState) => { payload: state.publish.payload, editorMode: state.publish.editorMode, retain: state.publish.retain, - qos: state.publish.qos, } } diff --git a/app/src/components/Sidebar/Publish/QosSelect.tsx b/app/src/components/Sidebar/Publish/QosSelect.tsx new file mode 100644 index 0000000..551950a --- /dev/null +++ b/app/src/components/Sidebar/Publish/QosSelect.tsx @@ -0,0 +1,75 @@ +import * as React from 'react' +import { TextField, MenuItem, Tooltip } from '@material-ui/core' +import { connect } from 'react-redux' +import { AppState } from '../../../reducers' +import { bindActionCreators } from 'redux' +import { publishActions } from '../../../actions' + +interface Props { + qos: 0 | 1 | 2 + actions: { + publish: typeof publishActions + } +} + +function QosSelect(props: Props) { + const tooltipStyle = { textAlign: 'center' as 'center', width: '100%' } + const itemStyle = { padding: '0' } + + const onChangeQos = React.useCallback( + (event: React.ChangeEvent) => { + const value = parseInt(event.target.value, 10) + if (value !== 0 && value !== 1 && value !== 2) { + return + } + + props.actions.publish.setQoS(value) + }, + [props.actions.publish] + ) + + return ( + + + +
0
+
+
+ + +
1
+
+
+ + +
2
+
+
+
+ ) +} + +const mapDispatchToProps = (dispatch: any) => { + return { + actions: { + publish: bindActionCreators(publishActions, dispatch), + }, + } +} + +const mapStateToProps = (state: AppState) => { + return { + qos: state.publish.qos, + } +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(QosSelect)