-
-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
decode data in frontend #795
Merged
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
567f6d2
Added support for binary data types
mhorsche 626b9ca
Specific int/uint byte size
mhorsche f4bda3e
feat: use tahu for sparkplug decoding
bj00rn 10aae59
Merge remote-tracking branch 'fb/multi-decoder/master' into feat/use-…
980072f
chore: decode data in frontend
1f23c65
Stop click event propagation prevent panel from collapsing
bj00rn 97fedcb
fix sparkplug topic regexp
bj00rn 1ecb53b
fix: update react when decoder has been overriden
b3a37e4
chore: refactor
c88978f
fix: fix ui updates
a2c4388
fix: repair types
bbe2ae3
test: fix tests
4406bf5
feat: use tahu for sparkplug decoding
bj00rn b4bdd01
add sparkplug messages to demovideo
bj00rn e9a56ac
Merge remote-tracking branch 'origin/master' into tnordquist/decode-d…
3bc23e6
test: fix demo video
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
app/src/components/Sidebar/TopicPanel/TopicTypeButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { useCallback, useMemo } from 'react' | ||
import * as q from '../../../../../backend/src/Model' | ||
import ClickAwayListener from '@material-ui/core/ClickAwayListener' | ||
import Grow from '@material-ui/core/Grow' | ||
import Button from '@material-ui/core/Button' | ||
import Paper from '@material-ui/core/Paper' | ||
import Popper from '@material-ui/core/Popper' | ||
import MenuItem from '@material-ui/core/MenuItem' | ||
import MenuList from '@material-ui/core/MenuList' | ||
import WarningRounded from '@material-ui/icons/WarningRounded' | ||
import { MessageDecoder, decoders } from '../../../decoders' | ||
import { Tooltip } from '@material-ui/core' | ||
|
||
export const TopicTypeButton = (props: { node?: q.TreeNode<any> }) => { | ||
const { node } = props | ||
if (!node || !node.message || !node.message.payload) { | ||
return null | ||
} | ||
|
||
const options = decoders.flatMap(decoder => decoder.formats.map(format => [decoder, format] as const)) | ||
|
||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null) | ||
const [open, setOpen] = React.useState(false) | ||
|
||
const selectOption = useCallback( | ||
(decoder: MessageDecoder, format: string) => { | ||
if (!node) { | ||
return | ||
} | ||
|
||
node.viewModel.decoder = { decoder, format } | ||
setOpen(false) | ||
}, | ||
[node] | ||
) | ||
|
||
const handleToggle = useCallback( | ||
(event: React.MouseEvent<HTMLElement>) => { | ||
event.stopPropagation() | ||
if (open === true) { | ||
return | ||
} | ||
setAnchorEl(event.currentTarget) | ||
setOpen(prevOpen => !prevOpen) | ||
}, | ||
[open] | ||
) | ||
|
||
const handleClose = useCallback((event: React.MouseEvent<Document, MouseEvent>) => { | ||
if (anchorEl && anchorEl.contains(event.target as HTMLElement)) { | ||
return | ||
} | ||
setOpen(false) | ||
}, []) | ||
|
||
return ( | ||
<Button onClick={handleToggle}> | ||
{props.node?.viewModel.decoder?.format ?? props.node?.type} | ||
<Popper open={open} anchorEl={anchorEl} role={undefined} transition> | ||
{({ TransitionProps, placement }) => ( | ||
<Grow | ||
{...TransitionProps} | ||
style={{ | ||
transformOrigin: placement === 'bottom' ? 'center top' : 'center bottom', | ||
}} | ||
> | ||
<Paper> | ||
<ClickAwayListener onClickAway={handleClose}> | ||
<MenuList id="topicTypeMode"> | ||
{options.map(([decoder, format], index) => ( | ||
<MenuItem | ||
key={format} | ||
selected={node && format === node.type} | ||
onClick={() => selectOption(decoder, format)} | ||
> | ||
<DecoderStatus decoder={decoder} format={format} node={node} /> | ||
</MenuItem> | ||
))} | ||
</MenuList> | ||
</ClickAwayListener> | ||
</Paper> | ||
</Grow> | ||
)} | ||
</Popper> | ||
</Button> | ||
) | ||
} | ||
|
||
function DecoderStatus({ node, decoder, format }: { node: q.TreeNode<any>; decoder: MessageDecoder; format: string }) { | ||
const decoded = useMemo(() => { | ||
return node.message?.payload && decoder.decode(node.message?.payload, format) | ||
}, [node.message, decoder, format]) | ||
|
||
return decoded?.error ? ( | ||
<Tooltip title={decoded.error}> | ||
<div> | ||
{format} <WarningRounded /> | ||
</div> | ||
</Tooltip> | ||
) : ( | ||
<>{format}</> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thomasnordquist i'm a bit confused about node.type here? Should't
type
be derived from the selectedDecoder
?