Merge pull request #13 from up9inc/feature/ui/Live_traffic_web_socket

Live traffic web socket
This commit is contained in:
lirazyehezkel 2021-04-28 17:29:04 +03:00 committed by GitHub
commit 00949d885a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 31 deletions

10
ui/package-lock.json generated
View File

@ -13420,6 +13420,11 @@
"workbox-webpack-plugin": "5.1.4" "workbox-webpack-plugin": "5.1.4"
} }
}, },
"react-scrollable-feed": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/react-scrollable-feed/-/react-scrollable-feed-1.3.0.tgz",
"integrity": "sha512-ZoaWcrYlzNoGHNuYy//Wkz9jtFiy+pb8VvHzRVmthktU4cJAN4//aYzEIATyT+amAROL8qpZnoWUZJypDtmvfg=="
},
"react-syntax-highlighter": { "react-syntax-highlighter": {
"version": "15.4.3", "version": "15.4.3",
"resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-15.4.3.tgz", "resolved": "https://registry.npmjs.org/react-syntax-highlighter/-/react-syntax-highlighter-15.4.3.tgz",
@ -13443,6 +13448,11 @@
"prop-types": "^15.6.2" "prop-types": "^15.6.2"
} }
}, },
"react-use-websocket": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/react-use-websocket/-/react-use-websocket-2.6.1.tgz",
"integrity": "sha512-Nx1jUab+7eHpVftBpscgVG26UMVjy4P8ss+I3sE6LijHXC0chFej7unzH9YXElN9stEm1of+qZA+YX/ZlPIQBQ=="
},
"read-pkg": { "read-pkg": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz",

View File

@ -17,7 +17,9 @@
"react-copy-to-clipboard": "^5.0.3", "react-copy-to-clipboard": "^5.0.3",
"react-dom": "^17.0.2", "react-dom": "^17.0.2",
"react-scripts": "4.0.3", "react-scripts": "4.0.3",
"react-scrollable-feed": "^1.3.0",
"react-syntax-highlighter": "^15.4.3", "react-syntax-highlighter": "^15.4.3",
"react-use-websocket": "^2.6.1",
"typescript": "^4.2.4", "typescript": "^4.2.4",
"web-vitals": "^1.1.1" "web-vitals": "^1.1.1"
}, },

View File

@ -1,6 +1,7 @@
import {HarEntry} from "./HarEntry"; import {HarEntry} from "./HarEntry";
import React, {useEffect, useRef} from "react"; import React, {useEffect, useRef} from "react";
import styles from './style/HarEntriesList.module.sass'; import styles from './style/HarEntriesList.module.sass';
import ScrollableFeed from 'react-scrollable-feed'
interface HarEntriesListProps { interface HarEntriesListProps {
entries: any[]; entries: any[];
@ -9,24 +10,16 @@ interface HarEntriesListProps {
} }
export const HarEntriesList: React.FC<HarEntriesListProps> = ({entries, focusedEntryId, setFocusedEntryId}) => { export const HarEntriesList: React.FC<HarEntriesListProps> = ({entries, focusedEntryId, setFocusedEntryId}) => {
const entriesDiv = useRef(null);
const totalCount = null; //todo
// Scroll to bottom in case results do not fit in screen
useEffect(() => {
if (entriesDiv.current && totalCount > 0) {
entriesDiv.current.scrollTop = entriesDiv.current.scrollHeight;
}
}, [entriesDiv, totalCount])
return <> return <>
<div ref={entriesDiv} className={styles.list}> <div className={styles.list}>
<ScrollableFeed>
{entries?.map(entry => <HarEntry key={entry.id} {entries?.map(entry => <HarEntry key={entry.id}
entry={entry} entry={entry}
setFocusedEntryId={setFocusedEntryId} setFocusedEntryId={setFocusedEntryId}
isSelected={focusedEntryId === entry.id} isSelected={focusedEntryId === entry.id}
/>)} />)}
</ScrollableFeed>
</div> </div>
</>; </>;
}; };

View File

@ -12,7 +12,9 @@ const useStyles = makeStyles(() => ({
minHeight: 46, minHeight: 46,
maxHeight: 46, maxHeight: 46,
alignItems: 'center', alignItems: 'center',
marginBottom: 8 marginBottom: 8,
padding: 5,
paddingBottom: 0
} }
})); }));

View File

@ -5,7 +5,7 @@ import {makeStyles} from "@material-ui/core";
import "./style/HarPage.sass"; import "./style/HarPage.sass";
import styles from './style/HarEntriesList.module.sass'; import styles from './style/HarEntriesList.module.sass';
import {HAREntryDetailed} from "./HarEntryDetailed"; import {HAREntryDetailed} from "./HarEntryDetailed";
// import {HarPaging} from "./HarPaging"; import useWebSocket from 'react-use-websocket';
const useLayoutStyles = makeStyles(() => ({ const useLayoutStyles = makeStyles(() => ({
details: { details: {
@ -19,6 +19,8 @@ const useLayoutStyles = makeStyles(() => ({
display: 'flex', display: 'flex',
overflowY: 'auto', overflowY: 'auto',
height: "calc(100% - 58px)", height: "calc(100% - 58px)",
padding: 5,
paddingBottom: 0
} }
})); }));
@ -30,11 +32,15 @@ export const HarPage: React.FC = () => {
const [focusedEntryId, setFocusedEntryId] = useState(null); const [focusedEntryId, setFocusedEntryId] = useState(null);
const [selectedHarEntry, setSelectedHarEntry] = useState(null); const [selectedHarEntry, setSelectedHarEntry] = useState(null);
const socketUrl = 'ws://localhost:8899/ws';
const {lastMessage} = useWebSocket(socketUrl, {shouldReconnect: (closeEvent) => true});
useEffect(() => { useEffect(() => {
fetch("http://localhost:8899/api/entries") if(!lastMessage?.data) return;
.then(response => response.json()) const entry = JSON.parse(lastMessage.data);
.then(data => {setEntries(data); setFocusedEntryId(data[0]?.id)}); if(!focusedEntryId) setFocusedEntryId(entry.id)
}, []); setEntries([...entries, entry])
},[lastMessage?.data])
useEffect(() => { useEffect(() => {
if(!focusedEntryId) return; if(!focusedEntryId) return;
@ -50,16 +56,11 @@ export const HarPage: React.FC = () => {
{/*<HarFilters />*/} {/*<HarFilters />*/}
<div className={styles.container}> <div className={styles.container}>
<HarEntriesList entries={entries} focusedEntryId={focusedEntryId} setFocusedEntryId={setFocusedEntryId}/> <HarEntriesList entries={entries} focusedEntryId={focusedEntryId} setFocusedEntryId={setFocusedEntryId}/>
{/*<Box flexGrow={0} flexShrink={0}>*/}
{/* {!harStore.data.isFirstLoading &&*/}
{/* <HarPaging showPageNumber />*/}
{/* }*/}
{/*</Box>*/}
</div> </div>
</div> </div>
<div className={classes.details}> {selectedHarEntry && <div className={classes.details}>
<HAREntryDetailed harEntry={selectedHarEntry} classes={{root: classes.harViewer}}/> <HAREntryDetailed harEntry={selectedHarEntry} classes={{root: classes.harViewer}}/>
</div> </div>}
</div> </div>
</div> </div>
) )

View File

@ -8,6 +8,7 @@
border-radius: 4px border-radius: 4px
cursor: pointer cursor: pointer
border: solid 1px transparent border: solid 1px transparent
margin-right: 5px
&:not(:first-child) &:not(:first-child)
margin-top: 10px margin-top: 10px

View File

@ -22,7 +22,7 @@ code
width: 8px width: 8px
::-webkit-scrollbar-thumb ::-webkit-scrollbar-thumb
background-color: rgba(0,0,0,0.5) background-color: #272d44
border-radius: 16px border-radius: 16px
::-webkit-scrollbar-button ::-webkit-scrollbar-button