From d7a5af34a445f469ec6e5a00b306e2aa0e3c56b1 Mon Sep 17 00:00:00 2001 From: "M. Mert Yildiran" Date: Thu, 26 Aug 2021 00:01:43 +0300 Subject: [PATCH] Fix all of the minor issues in the React code --- .../EntryDetailed/EntrySections.tsx | 22 +++++----------- .../components/EntryDetailed/EntryViewer.tsx | 26 +++++++++++-------- ui/src/components/UI/StatusCode.tsx | 2 ++ .../components/UI/style/Protocol.module.sass | 12 ++++----- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/ui/src/components/EntryDetailed/EntrySections.tsx b/ui/src/components/EntryDetailed/EntrySections.tsx index 38dea2e79..d4968e046 100644 --- a/ui/src/components/EntryDetailed/EntrySections.tsx +++ b/ui/src/components/EntryDetailed/EntrySections.tsx @@ -201,7 +201,6 @@ export const EntryPolicySectionContainer: React.FC = ({service, title, color, response, latency, arrayToIterate}) => { - // const base64ToJson = response.content.mimeType === "application/json; charset=utf-8" ? JSON.parse(Buffer.from(response.content.text, "base64").toString()) : {}; return { arrayToIterate && arrayToIterate.length > 0 ? @@ -215,39 +214,32 @@ export const EntryTablePolicySection: React.FC = ({serv { <> { - rule.Key !== "" ? + rule.Key && Key:{rule.Key} - : null } { - rule.Latency !== "" ? + rule.Latency && Latency: {rule.Latency} - : null } { - rule.Method !== "" ? + rule.Method && Method: {rule.Method} - : null } { - rule.Path !== "" ? + rule.Path && Path: {rule.Path} - : null } { - rule.Service !== "" ? + rule.Service && Service: {service} - : null } { - rule.Type !== "" ? + rule.Type && Type: {rule.Type} - : null } { - rule.Value !== "" ? + rule.Value && Value: {rule.Value} - : null } } diff --git a/ui/src/components/EntryDetailed/EntryViewer.tsx b/ui/src/components/EntryDetailed/EntryViewer.tsx index 59f16bed8..efc7c3b43 100644 --- a/ui/src/components/EntryDetailed/EntryViewer.tsx +++ b/ui/src/components/EntryDetailed/EntryViewer.tsx @@ -3,18 +3,23 @@ import styles from './EntryViewer.module.sass'; import Tabs from "../UI/Tabs"; import {EntryTableSection, EntryBodySection, EntryTablePolicySection} from "./EntrySections"; +enum SectionTypes { + SectionTable = "table", + SectionBody = "body", +} + const SectionsRepresentation: React.FC = ({data, color}) => { const sections = [] - if (data !== undefined) { + if (data) { for (const [i, row] of data.entries()) { switch (row.type) { - case "table": + case SectionTypes.SectionTable: sections.push( ) break; - case "body": + case SectionTypes.SectionBody: sections.push( ) @@ -28,13 +33,14 @@ const SectionsRepresentation: React.FC = ({data, color}) => { return <>{sections}; } -const AutoRepresentation: React.FC = ({representation, color, isResponseMocked}) => { +const AutoRepresentation: React.FC = ({representation, color}) => { const rulesMatched = [] const TABS = [ - {tab: 'request'}, + { + tab: 'request' + }, { tab: 'response', - badge: <>{isResponseMocked && MOCK} }, { tab: 'Rules', @@ -43,7 +49,7 @@ const AutoRepresentation: React.FC = ({representation, color, isResponseMoc const [currentTab, setCurrentTab] = useState(TABS[0].tab); // Don't fail even if `representation` is an empty string - if (representation.length === 0) { + if (!representation) { return <>; } @@ -72,12 +78,10 @@ const AutoRepresentation: React.FC = ({representation, color, isResponseMoc interface Props { representation: any; color: string, - isResponseMocked?: boolean; - showTitle?: boolean; } -const EntryViewer: React.FC = ({representation, color, isResponseMocked, showTitle=true}) => { - return +const EntryViewer: React.FC = ({representation, color}) => { + return }; export default EntryViewer; diff --git a/ui/src/components/UI/StatusCode.tsx b/ui/src/components/UI/StatusCode.tsx index 95e322f3e..b35788ac1 100644 --- a/ui/src/components/UI/StatusCode.tsx +++ b/ui/src/components/UI/StatusCode.tsx @@ -25,6 +25,8 @@ const StatusCode: React.FC = ({statusCode}) => { export function getClassification(statusCode: number): string { let classification = StatusCodeClassification.NEUTRAL; + // 1 - 16 HTTP/2 (gRPC) status codes + // 2xx - 5xx HTTP/1.1 status codes if ((statusCode >= 200 && statusCode <= 399) || statusCode === 0) { classification = StatusCodeClassification.SUCCESS; } else if (statusCode >= 400 || (statusCode >= 1 && statusCode <= 16)) { diff --git a/ui/src/components/UI/style/Protocol.module.sass b/ui/src/components/UI/style/Protocol.module.sass index 54eb0f2d3..e702f5ae2 100644 --- a/ui/src/components/UI/style/Protocol.module.sass +++ b/ui/src/components/UI/style/Protocol.module.sass @@ -5,18 +5,18 @@ font-weight: 600 background-color: #000 color: #fff - margin-left: -8px; - margin-bottom: -4px; + margin-left: -8px + margin-bottom: -4px .vertical line-height: 22px - letter-spacing: 0.5px; + letter-spacing: 0.5px width: 22px height: 48px border-radius: 0px 4px 4px 0 - writing-mode: vertical-lr; - transform: rotate(-180deg); - text-orientation: mixed; + writing-mode: vertical-lr + transform: rotate(-180deg) + text-orientation: mixed .horizontal border-radius: 4px