mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-07-20 11:10:54 +00:00
TRA-4274 fix ui common linter issues (#1161)
* fix lint issues * fix all ui-common line issues * max warnings 0
This commit is contained in:
parent
4d64dd4b04
commit
d7d802830f
@ -20,7 +20,7 @@
|
|||||||
"test:lint": "eslint .",
|
"test:lint": "eslint .",
|
||||||
"predeploy": "cd example && npm install && npm run build",
|
"predeploy": "cd example && npm install && npm run build",
|
||||||
"deploy": "gh-pages -d example/build",
|
"deploy": "gh-pages -d example/build",
|
||||||
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx"
|
"eslint": "eslint . --ext .js,.jsx,.ts,.tsx --max-warnings=0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@craco/craco": "^6.4.3",
|
"@craco/craco": "^6.4.3",
|
||||||
|
@ -109,7 +109,7 @@ export const EntriesList: React.FC<EntriesListProps> = ({
|
|||||||
if (scrollTo) {
|
if (scrollTo) {
|
||||||
scrollableRef.current.scrollToIndex(data.data.length - 1);
|
scrollableRef.current.scrollToIndex(data.data.length - 1);
|
||||||
}
|
}
|
||||||
}, [setLoadMoreTop, setIsLoadingTop, entries, setEntries, query, setNoMoreDataTop, leftOffTop, setLeftOffTop, setQueriedTotal, setTruncatedTimestamp, scrollableRef]);
|
}, [setLoadMoreTop, setIsLoadingTop, entries, setEntries, query, setNoMoreDataTop, leftOffTop, setLeftOffTop, setQueriedTotal, setTruncatedTimestamp, scrollableRef, trafficViewerApi]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!isWsConnectionClosed || !loadMoreTop || noMoreDataTop) return;
|
if (!isWsConnectionClosed || !loadMoreTop || noMoreDataTop) return;
|
||||||
@ -121,7 +121,7 @@ export const EntriesList: React.FC<EntriesListProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!focusedEntryId && entries.length > 0)
|
if (!focusedEntryId && entries.length > 0)
|
||||||
setFocusedEntryId(entries[0].id);
|
setFocusedEntryId(entries[0].id);
|
||||||
}, [focusedEntryId, entries])
|
}, [focusedEntryId, entries, setFocusedEntryId])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const newEntries = [...entries];
|
const newEntries = [...entries];
|
||||||
@ -131,7 +131,7 @@ export const EntriesList: React.FC<EntriesListProps> = ({
|
|||||||
setNoMoreDataTop(false);
|
setNoMoreDataTop(false);
|
||||||
setEntries(newEntries);
|
setEntries(newEntries);
|
||||||
}
|
}
|
||||||
}, [entries])
|
}, [entries, setLeftOffTop, setNoMoreDataTop, setEntries])
|
||||||
|
|
||||||
if(ws.current && !ws.current.onmessage) {
|
if(ws.current && !ws.current.onmessage) {
|
||||||
ws.current.onmessage = (e) => {
|
ws.current.onmessage = (e) => {
|
||||||
|
@ -15,7 +15,6 @@ import outgoingIconFailure from "assets/outgoing-traffic-failure.svg"
|
|||||||
import outgoingIconNeutral from "assets/outgoing-traffic-neutral.svg"
|
import outgoingIconNeutral from "assets/outgoing-traffic-neutral.svg"
|
||||||
import {useRecoilState} from "recoil";
|
import {useRecoilState} from "recoil";
|
||||||
import focusedEntryIdAtom from "../../recoil/focusedEntryId";
|
import focusedEntryIdAtom from "../../recoil/focusedEntryId";
|
||||||
import queryAtom from "../../recoil/query";
|
|
||||||
|
|
||||||
interface TCPInterface {
|
interface TCPInterface {
|
||||||
ip: string
|
ip: string
|
||||||
@ -66,7 +65,6 @@ enum CaptureTypes {
|
|||||||
export const EntryItem: React.FC<EntryProps> = ({entry, style, headingMode, namespace}) => {
|
export const EntryItem: React.FC<EntryProps> = ({entry, style, headingMode, namespace}) => {
|
||||||
|
|
||||||
const [focusedEntryId, setFocusedEntryId] = useRecoilState(focusedEntryIdAtom);
|
const [focusedEntryId, setFocusedEntryId] = useRecoilState(focusedEntryIdAtom);
|
||||||
const [queryState, setQuery] = useRecoilState(queryAtom);
|
|
||||||
const isSelected = focusedEntryId === entry.id;
|
const isSelected = focusedEntryId === entry.id;
|
||||||
|
|
||||||
const classification = getClassification(entry.status)
|
const classification = getClassification(entry.status)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, {useCallback, useEffect, useRef, useState} from "react";
|
||||||
import { Filters } from "../Filters/Filters";
|
import { Filters } from "../Filters/Filters";
|
||||||
import { EntriesList } from "../EntriesList/EntriesList";
|
import { EntriesList } from "../EntriesList/EntriesList";
|
||||||
import makeStyles from '@mui/styles/makeStyles';
|
import makeStyles from '@mui/styles/makeStyles';
|
||||||
@ -59,7 +59,6 @@ export const TrafficViewer: React.FC<TrafficViewerProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
|
|
||||||
const classes = useLayoutStyles();
|
const classes = useLayoutStyles();
|
||||||
|
|
||||||
const setEntries = useSetRecoilState(entriesAtom);
|
const setEntries = useSetRecoilState(entriesAtom);
|
||||||
const setFocusedEntryId = useSetRecoilState(focusedEntryIdAtom);
|
const setFocusedEntryId = useSetRecoilState(focusedEntryIdAtom);
|
||||||
const query = useRecoilValue(queryAtom);
|
const query = useRecoilValue(queryAtom);
|
||||||
@ -68,40 +67,44 @@ export const TrafficViewer: React.FC<TrafficViewerProps> = ({
|
|||||||
const [noMoreDataTop, setNoMoreDataTop] = useState(false);
|
const [noMoreDataTop, setNoMoreDataTop] = useState(false);
|
||||||
const [isSnappedToBottom, setIsSnappedToBottom] = useState(true);
|
const [isSnappedToBottom, setIsSnappedToBottom] = useState(true);
|
||||||
const [wsReadyState, setWsReadyState] = useState(0);
|
const [wsReadyState, setWsReadyState] = useState(0);
|
||||||
|
|
||||||
const setLeftOffTop = useSetRecoilState(leftOffTopAtom);
|
const setLeftOffTop = useSetRecoilState(leftOffTopAtom);
|
||||||
const scrollableRef = useRef(null);
|
const scrollableRef = useRef(null);
|
||||||
|
|
||||||
|
|
||||||
|
const ws = useRef(null);
|
||||||
|
|
||||||
|
const closeWebSocket = useCallback(() => {
|
||||||
|
if (ws?.current?.readyState === WebSocket.OPEN) {
|
||||||
|
ws.current.close();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if(shouldCloseWebSocket){
|
if(shouldCloseWebSocket){
|
||||||
closeWebSocket()
|
closeWebSocket()
|
||||||
setShouldCloseWebSocket(false);
|
setShouldCloseWebSocket(false);
|
||||||
}
|
}
|
||||||
}, [shouldCloseWebSocket])
|
}, [shouldCloseWebSocket, setShouldCloseWebSocket, closeWebSocket])
|
||||||
|
|
||||||
useEffect(() => {
|
const sendQueryWhenWsOpen = useCallback((leftOff: string, query: string, fetch: number, fetchTimeoutMs: number) => {
|
||||||
reopenConnection()
|
setTimeout(() => {
|
||||||
}, [webSocketUrl])
|
if (ws?.current?.readyState === WebSocket.OPEN) {
|
||||||
|
ws.current.send(JSON.stringify({
|
||||||
const ws = useRef(null);
|
"leftOff": leftOff,
|
||||||
|
"query": query,
|
||||||
const openEmptyWebSocket = () => {
|
"enableFullEntries": false,
|
||||||
openWebSocket(DEFAULT_LEFTOFF, query, true, DEFAULT_FETCH, DEFAULT_FETCH_TIMEOUT_MS);
|
"fetch": fetch,
|
||||||
}
|
"timeoutMs": fetchTimeoutMs
|
||||||
|
}));
|
||||||
const closeWebSocket = () => {
|
} else {
|
||||||
if (ws?.current?.readyState === WebSocket.OPEN) {
|
sendQueryWhenWsOpen(leftOff, query, fetch, fetchTimeoutMs);
|
||||||
ws.current.close();
|
}
|
||||||
return true;
|
}, 500)
|
||||||
}
|
}, [])
|
||||||
}
|
|
||||||
|
|
||||||
const listEntry = useRef(null);
|
const listEntry = useRef(null);
|
||||||
const openWebSocket = (leftOff: string, query: string, resetEntries: boolean, fetch: number, fetchTimeoutMs: number) => {
|
const openWebSocket = useCallback((leftOff: string, query: string, resetEntries: boolean, fetch: number, fetchTimeoutMs: number) => {
|
||||||
if (resetEntries) {
|
if (resetEntries) {
|
||||||
setFocusedEntryId(null);
|
setFocusedEntryId(null);
|
||||||
setEntries([]);
|
setEntries([]);
|
||||||
@ -127,24 +130,11 @@ export const TrafficViewer: React.FC<TrafficViewerProps> = ({
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
}
|
}, [setFocusedEntryId, setEntries, setLeftOffTop, setNoMoreDataTop, ws, sendQueryWhenWsOpen, webSocketUrl])
|
||||||
|
|
||||||
const sendQueryWhenWsOpen = (leftOff: string, query: string, fetch: number, fetchTimeoutMs: number) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
if (ws?.current?.readyState === WebSocket.OPEN) {
|
|
||||||
ws.current.send(JSON.stringify({
|
|
||||||
"leftOff": leftOff,
|
|
||||||
"query": query,
|
|
||||||
"enableFullEntries": false,
|
|
||||||
"fetch": fetch,
|
|
||||||
"timeoutMs": fetchTimeoutMs
|
|
||||||
}));
|
|
||||||
} else {
|
|
||||||
sendQueryWhenWsOpen(leftOff, query, fetch, fetchTimeoutMs);
|
|
||||||
}
|
|
||||||
}, 500)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const openEmptyWebSocket = useCallback(() => {
|
||||||
|
openWebSocket(DEFAULT_LEFTOFF, query, true, DEFAULT_FETCH, DEFAULT_FETCH_TIMEOUT_MS);
|
||||||
|
}, [openWebSocket, query])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTrafficViewerApiState({...trafficViewerApiProp, webSocket: {close: closeWebSocket}});
|
setTrafficViewerApiState({...trafficViewerApiProp, webSocket: {close: closeWebSocket}});
|
||||||
@ -156,7 +146,7 @@ export const TrafficViewer: React.FC<TrafficViewerProps> = ({
|
|||||||
console.error(error);
|
console.error(error);
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
}, []);
|
}, [trafficViewerApiProp, closeWebSocket, setTappingStatus, setTrafficViewerApiState]);
|
||||||
|
|
||||||
const toggleConnection = () => {
|
const toggleConnection = () => {
|
||||||
if (!closeWebSocket()) {
|
if (!closeWebSocket()) {
|
||||||
@ -166,12 +156,17 @@ export const TrafficViewer: React.FC<TrafficViewerProps> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const reopenConnection = async () => {
|
const reopenConnection = useCallback(async () => {
|
||||||
closeWebSocket()
|
closeWebSocket()
|
||||||
openEmptyWebSocket();
|
openEmptyWebSocket();
|
||||||
scrollableRef.current.jumpToBottom();
|
scrollableRef.current.jumpToBottom();
|
||||||
setIsSnappedToBottom(true);
|
setIsSnappedToBottom(true);
|
||||||
}
|
}, [scrollableRef, setIsSnappedToBottom, closeWebSocket, openEmptyWebSocket])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reopenConnection()
|
||||||
|
// eslint-disable-next-line
|
||||||
|
}, [webSocketUrl])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
|
@ -11,7 +11,7 @@ interface LinkProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Link: React.FC<LinkProps> = ({ link, className, title, children }) => {
|
export const Link: React.FC<LinkProps> = ({ link, className, title, children }) => {
|
||||||
return <a href={link} className={className} title={title} target="_blank">
|
return <a href={link} className={className} title={title} target="_blank" rel="noreferrer">
|
||||||
{children}
|
{children}
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ const SelectList: React.FC<Props> = ({ items, tableName, checkedValues = [], mul
|
|||||||
}
|
}
|
||||||
|
|
||||||
setCheckedValues(newChecked)
|
setCheckedValues(newChecked)
|
||||||
}, [searchValue, checkedValues, filteredValuesKeys])
|
}, [checkedValues, filteredValuesKeys, items, setCheckedValues])
|
||||||
|
|
||||||
const dataFieldFunc = (listValue) => listValue.component ? listValue.component :
|
const dataFieldFunc = (listValue) => listValue.component ? listValue.component :
|
||||||
<span className={styles.nowrap} title={listValue.value}>
|
<span className={styles.nowrap} title={listValue.value}>
|
||||||
|
@ -40,7 +40,7 @@ export const TimelineBarChart: React.FC<TimelineBarChartProps> = ({ timeLineBarC
|
|||||||
if (!data) return;
|
if (!data) return;
|
||||||
const protocolsBarsData = [];
|
const protocolsBarsData = [];
|
||||||
const prtcNames = [];
|
const prtcNames = [];
|
||||||
data.map(protocolObj => {
|
data.forEach(protocolObj => {
|
||||||
let obj: { [k: string]: any } = {};
|
let obj: { [k: string]: any } = {};
|
||||||
obj.timestamp = getHoursAndMinutes(protocolObj.timestamp);
|
obj.timestamp = getHoursAndMinutes(protocolObj.timestamp);
|
||||||
protocolObj.protocols.forEach(protocol => {
|
protocolObj.protocols.forEach(protocol => {
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { atom } from "recoil";
|
import { atom } from "recoil";
|
||||||
import TrafficViewerApi from "../../components/TrafficViewer/TrafficViewerApi";
|
|
||||||
|
|
||||||
const TrafficViewerApiAtom = atom({
|
const TrafficViewerApiAtom = atom({
|
||||||
key: "TrafficViewerApiAtom",
|
key: "TrafficViewerApiAtom",
|
||||||
|
Loading…
Reference in New Issue
Block a user