Show the EntryItem as EntrySummary in EntryDetailed (#506)

This commit is contained in:
M. Mert Yıldıran
2021-11-28 10:59:40 +03:00
committed by GitHub
parent a1bda0a6c3
commit 9696ad9bad
4 changed files with 41 additions and 30 deletions

View File

@@ -1,9 +1,8 @@
import React from "react"; import React from "react";
import EntryViewer from "./EntryDetailed/EntryViewer"; import EntryViewer from "./EntryDetailed/EntryViewer";
import {EntryItem} from "./EntryListItem/EntryListItem";
import {makeStyles} from "@material-ui/core"; import {makeStyles} from "@material-ui/core";
import Protocol from "./UI/Protocol" import Protocol from "./UI/Protocol"
import StatusCode from "./UI/StatusCode";
import {Summary} from "./UI/Summary";
const useStyles = makeStyles(() => ({ const useStyles = makeStyles(() => ({
entryTitle: { entryTitle: {
@@ -12,6 +11,7 @@ const useStyles = makeStyles(() => ({
maxHeight: 46, maxHeight: 46,
alignItems: 'center', alignItems: 'center',
marginBottom: 4, marginBottom: 4,
marginLeft: 6,
padding: 2, padding: 2,
paddingBottom: 0 paddingBottom: 0
}, },
@@ -64,18 +64,17 @@ const EntryTitle: React.FC<any> = ({protocol, data, bodySize, elapsedTime, updat
}; };
const EntrySummary: React.FC<any> = ({data, updateQuery}) => { const EntrySummary: React.FC<any> = ({data, updateQuery}) => {
const classes = useStyles(); const entry = data.base;
const response = data.response; return <EntryItem
key={entry.id}
return <div className={classes.entrySummary}> entry={entry}
{response && "status" in response && <div style={{marginRight: 8}}> setFocusedEntryId={null}
<StatusCode statusCode={response.status} updateQuery={updateQuery}/> style={{}}
</div>} updateQuery={updateQuery}
<div style={{flexGrow: 1, overflow: 'hidden'}}> forceSelect={false}
<Summary method={data.method} summary={data.summary} updateQuery={updateQuery}/> headingMode={true}
</div> />;
</div>;
}; };
export const EntryDetailed: React.FC<EntryDetailedProps> = ({entryData, updateQuery}) => { export const EntryDetailed: React.FC<EntryDetailedProps> = ({entryData, updateQuery}) => {

View File

@@ -4,6 +4,7 @@
font-family: "Source Sans Pro", Lucida Grande, Tahoma, sans-serif font-family: "Source Sans Pro", Lucida Grande, Tahoma, sans-serif
height: calc(100% - 70px) height: calc(100% - 70px)
width: 100% width: 100%
margin-top: 10px
h3, h3,
h4 h4

View File

@@ -40,11 +40,13 @@ interface EntryProps {
setFocusedEntryId: (id: string) => void; setFocusedEntryId: (id: string) => void;
style: object; style: object;
updateQuery: any; updateQuery: any;
forceSelect: boolean;
headingMode: boolean;
} }
export const EntryItem: React.FC<EntryProps> = ({entry, setFocusedEntryId, style, updateQuery}) => { export const EntryItem: React.FC<EntryProps> = ({entry, setFocusedEntryId, style, updateQuery, forceSelect, headingMode}) => {
const [isSelected, setIsSelected] = useState(false); const [isSelected, setIsSelected] = useState(!forceSelect ? false : true);
const classification = getClassification(entry.statusCode) const classification = getClassification(entry.statusCode)
const numberOfRules = entry.rules.numberOfRules const numberOfRules = entry.rules.numberOfRules
@@ -122,22 +124,23 @@ export const EntryItem: React.FC<EntryProps> = ({entry, setFocusedEntryId, style
className={`${styles.row} className={`${styles.row}
${isSelected && !rule && !contractEnabled ? styles.rowSelected : additionalRulesProperties}`} ${isSelected && !rule && !contractEnabled ? styles.rowSelected : additionalRulesProperties}`}
onClick={() => { onClick={() => {
if (!setFocusedEntryId) return;
setIsSelected(!isSelected); setIsSelected(!isSelected);
setFocusedEntryId(entry.id.toString()); setFocusedEntryId(entry.id.toString());
}} }}
style={{ style={{
border: isSelected ? `1px ${entry.protocol.backgroundColor} solid` : "1px transparent solid", border: isSelected ? `1px ${entry.protocol.backgroundColor} solid` : "1px transparent solid",
position: "absolute", position: !headingMode ? "absolute" : "unset",
top: style['top'], top: style['top'],
marginTop: style['marginTop'], marginTop: style['marginTop'],
width: "calc(100% - 25px)", width: !headingMode ? "calc(100% - 25px)" : "calc(100% - 18px)",
}} }}
> >
<Protocol {!headingMode ? <Protocol
protocol={entry.protocol} protocol={entry.protocol}
horizontal={false} horizontal={false}
updateQuery={updateQuery} updateQuery={updateQuery}
/> /> : null}
{((entry.protocol.name === "http" && "statusCode" in entry) || entry.statusCode !== 0) && <div> {((entry.protocol.name === "http" && "statusCode" in entry) || entry.statusCode !== 0) && <div>
<StatusCode statusCode={entry.statusCode} updateQuery={updateQuery}/> <StatusCode statusCode={entry.statusCode} updateQuery={updateQuery}/>
</div>} </div>}

View File

@@ -119,7 +119,11 @@ export const TrafficPage: React.FC<TrafficPageProps> = ({setAnalyzeStatus, onTLS
switch (message.messageType) { switch (message.messageType) {
case "entry": case "entry":
const entry = message.data; const entry = message.data;
if (!focusedEntryId) setFocusedEntryId(entry.id.toString()); var forceSelect = false;
if (!focusedEntryId) {
setFocusedEntryId(entry.id.toString());
forceSelect = true;
}
setEntriesBuffer([ setEntriesBuffer([
...entriesBuffer, ...entriesBuffer,
<EntryItem <EntryItem
@@ -128,6 +132,8 @@ export const TrafficPage: React.FC<TrafficPageProps> = ({setAnalyzeStatus, onTLS
setFocusedEntryId={setFocusedEntryId} setFocusedEntryId={setFocusedEntryId}
style={{}} style={{}}
updateQuery={updateQuery} updateQuery={updateQuery}
forceSelect={forceSelect}
headingMode={false}
/> />
]); ]);
break break
@@ -190,6 +196,7 @@ export const TrafficPage: React.FC<TrafficPageProps> = ({setAnalyzeStatus, onTLS
const entryData = await api.getEntry(focusedEntryId); const entryData = await api.getEntry(focusedEntryId);
setSelectedEntryData(entryData); setSelectedEntryData(entryData);
} catch (error) { } catch (error) {
if (error.response) {
toast[error.response.data.type](`Entry[${focusedEntryId}]: ${error.response.data.msg}`, { toast[error.response.data.type](`Entry[${focusedEntryId}]: ${error.response.data.msg}`, {
position: "bottom-right", position: "bottom-right",
theme: "colored", theme: "colored",
@@ -200,6 +207,7 @@ export const TrafficPage: React.FC<TrafficPageProps> = ({setAnalyzeStatus, onTLS
draggable: true, draggable: true,
progress: undefined, progress: undefined,
}); });
}
console.error(error); console.error(error);
} }
})() })()