From fd7feada3a29836d9e858739c37e6ffbdb6e4ffe Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 5 Jul 2023 01:46:59 +0100 Subject: [PATCH] Re-structured result components to use re-usable card --- src/components/Results/BuiltWith.tsx | 30 ++++------- src/components/Results/Cookies.tsx | 22 +++----- src/components/Results/DnsRecords.tsx | 17 +++--- src/components/Results/Headers.tsx | 19 +++---- src/components/Results/HostNames.tsx | 25 ++++----- src/components/Results/Lighthouse.tsx | 17 ++---- src/components/Results/OpenPorts.tsx | 23 +++----- src/components/Results/Redirects.tsx | 23 ++++---- src/components/Results/RobotsTxt.tsx | 15 +++--- src/components/Results/Screenshot.tsx | 30 +++++------ src/components/Results/ServerInfo.tsx | 16 ++---- src/components/Results/ServerLocation.tsx | 17 +++--- src/components/Results/ServerStatus.tsx | 14 +++-- src/components/Results/SslCert.tsx | 13 ++--- src/components/Results/TraceRoute.tsx | 64 ++++++++++++++++++----- src/components/Results/TxtRecords.tsx | 15 +++--- src/components/Results/WhoIs.tsx | 14 +++-- 17 files changed, 171 insertions(+), 203 deletions(-) diff --git a/src/components/Results/BuiltWith.tsx b/src/components/Results/BuiltWith.tsx index c0ce415..59a06d9 100644 --- a/src/components/Results/BuiltWith.tsx +++ b/src/components/Results/BuiltWith.tsx @@ -23,36 +23,26 @@ const Row = styled.div` } `; -const DataRow = (props: { lbl: string, val: string }) => { - const { lbl, val } = props; - return ( - - {lbl} - {val} - - ); -}; - const ListRow = (props: { list: Technology[], title: string }) => { const { list, title } = props; return ( - <> - {title} - { list.map((entry: Technology, index: number) => { - return ( - { entry.Name } + <> + {title} + { list.map((entry: Technology, index: number) => { + return ( + { entry.Name } + )} )} - )} - -); + + ); } -const BuiltWithCard = (technologies: TechnologyGroup[]): JSX.Element => { +const BuiltWithCard = (props: { data: TechnologyGroup[]}): JSX.Element => { // const { created, updated, expires, nameservers } = whois; return ( Technologies - { technologies.map((group: TechnologyGroup) => { + { props.data.map((group: TechnologyGroup) => { return ( ); diff --git a/src/components/Results/Cookies.tsx b/src/components/Results/Cookies.tsx index 609d8e0..dcfff0e 100644 --- a/src/components/Results/Cookies.tsx +++ b/src/components/Results/Cookies.tsx @@ -1,21 +1,13 @@ - -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import { ExpandableRow } from 'components/Form/Row'; -const Outer = styled(Card)``; - -const CookiesCard = (cookies: { cookies: any }): JSX.Element => { +const CookiesCard = (props: { data: any, title: string, actionButtons: any}): JSX.Element => { + const cookies = props.data.cookies; return ( - - Cookies + + { cookies.length === 0 &&

No cookies found.

} { - cookies.cookies.length === 0 &&

No cookies found.

- } - { - cookies.cookies.map((cookie: any, index: number) => { + cookies.map((cookie: any, index: number) => { const attributes = Object.keys(cookie.attributes).map((key: string) => { return { lbl: key, val: cookie.attributes[key] } }); @@ -24,7 +16,7 @@ const CookiesCard = (cookies: { cookies: any }): JSX.Element => { ) }) } -
+ ); } diff --git a/src/components/Results/DnsRecords.tsx b/src/components/Results/DnsRecords.tsx index 30ffbec..b9018c9 100644 --- a/src/components/Results/DnsRecords.tsx +++ b/src/components/Results/DnsRecords.tsx @@ -1,21 +1,17 @@ - -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row, { ListRow } from 'components/Form/Row'; -const Outer = styled(Card)` +const styles = ` .content { max-height: 28rem; overflow-y: auto; } `; -const DnsRecordsCard = (dnsRecords: any): JSX.Element => { +const DnsRecordsCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const dnsRecords = props.data; return ( - - DNS Records +
{ dnsRecords.A && } { dnsRecords.AAAA?.length > 0 && } @@ -25,9 +21,8 @@ const DnsRecordsCard = (dnsRecords: any): JSX.Element => { { dnsRecords.PTR?.length > 0 && } { dnsRecords.SOA?.length > 0 && }
-
+ ); } export default DnsRecordsCard; - diff --git a/src/components/Results/Headers.tsx b/src/components/Results/Headers.tsx index 5417739..56f5a9f 100644 --- a/src/components/Results/Headers.tsx +++ b/src/components/Results/Headers.tsx @@ -1,18 +1,11 @@ - -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row from 'components/Form/Row'; +import { ReactNode } from 'react'; -const Outer = styled(Card)` - grid-row: span 2; -`; - -const HeadersCard = (headers: any): JSX.Element => { +const HeadersCard = (props: { data: any, title: string, actionButtons: ReactNode }): JSX.Element => { + const headers = props.data; return ( - - Headers + { Object.keys(headers).map((header: string, index: number) => { return ( @@ -20,7 +13,7 @@ const HeadersCard = (headers: any): JSX.Element => { ) }) } - + ); } diff --git a/src/components/Results/HostNames.tsx b/src/components/Results/HostNames.tsx index 4e433df..40cbe41 100644 --- a/src/components/Results/HostNames.tsx +++ b/src/components/Results/HostNames.tsx @@ -2,14 +2,9 @@ import styled from 'styled-components'; import { HostNames } from 'utils/result-processor'; import colors from 'styles/colors'; -import Card from 'components/Form/Card'; +import { Card } from 'components/Form/Card'; import Heading from 'components/Form/Heading'; -const Outer = styled(Card)` - max-height: 28rem; - overflow: auto; -`; - const Row = styled.div` display: flex; justify-content: space-between; @@ -22,7 +17,7 @@ const HostListSection = (props: { list: string[], title: string }) => { const { list, title } = props; return ( <> - {title} + {title} { list.map((entry: string, index: number) => { return ( { entry } @@ -32,16 +27,22 @@ const HostListSection = (props: { list: string[], title: string }) => { ); } -const HostNamesCard = (hosts: HostNames): JSX.Element => { +const cardStyles = ` + max-height: 28rem; + overflow: auto; +`; + +const HostNamesCard = (props: { data: HostNames, title: string, actionButtons: any }): JSX.Element => { + const hosts = props.data; return ( - + { hosts.domains.length > 0 && - + } { hosts.hostnames.length > 0 && - + } - + ); } diff --git a/src/components/Results/Lighthouse.tsx b/src/components/Results/Lighthouse.tsx index 4405aed..bc45cc5 100644 --- a/src/components/Results/Lighthouse.tsx +++ b/src/components/Results/Lighthouse.tsx @@ -1,17 +1,10 @@ - -import styled from 'styled-components'; - -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import { ExpandableRow } from 'components/Form/Row'; const processScore = (percentile: number) => { return `${Math.round(percentile * 100)}%`; } -const Outer = styled(Card)``; - interface Audit { id: string, score?: number | string, @@ -31,13 +24,13 @@ const makeValue = (audit: Audit) => { return score; }; -const LighthouseCard = (lighthouse: any): JSX.Element => { +const LighthouseCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const lighthouse = props.data; const categories = lighthouse?.categories || {}; const audits = lighthouse?.audits || []; return ( - - Performance + { Object.keys(categories).map((title: string, index: number) => { const scoreIds = categories[title].auditRefs.map((ref: { id: string }) => ref.id); const scoreList = scoreIds.map((id: string) => { @@ -52,7 +45,7 @@ const LighthouseCard = (lighthouse: any): JSX.Element => { /> ); }) } - + ); } diff --git a/src/components/Results/OpenPorts.tsx b/src/components/Results/OpenPorts.tsx index 9a85c59..7362c70 100644 --- a/src/components/Results/OpenPorts.tsx +++ b/src/components/Results/OpenPorts.tsx @@ -1,23 +1,14 @@ - -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row from 'components/Form/Row'; -const Outer = styled(Card)` - -small { - margin-top: 1rem; - opacity: 0.5; -} +const cardStyles = ` + small { margin-top: 1rem; opacity: 0.5; } `; -const OpenPortsCard = (portData: any): JSX.Element => { +const OpenPortsCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const portData = props.data; return ( - - Open Ports - + {portData.openPorts.map((port: any) => ( {port} @@ -29,7 +20,7 @@ const OpenPortsCard = (portData: any): JSX.Element => { Unable to establish connections to:
{portData.failedPorts.join(', ')} -
+ ); } diff --git a/src/components/Results/Redirects.tsx b/src/components/Results/Redirects.tsx index 38e27a6..e3c67cd 100644 --- a/src/components/Results/Redirects.tsx +++ b/src/components/Results/Redirects.tsx @@ -1,11 +1,8 @@ - -import styled from 'styled-components'; import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row from 'components/Form/Row'; -const Outer = styled(Card)` +const cardStyles = ` div { justify-content: flex-start; align-items: baseline; @@ -16,13 +13,21 @@ const Outer = styled(Card)` font-weight: bold; margin-right: 0.5rem; } + .redirect-count { + color: ${colors.textColorSecondary}; + margin: 0; + } `; -const RedirectsCard = (redirects: any): JSX.Element => { +const RedirectsCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const redirects = props.data; return ( - - Redirects + { !redirects?.redirects.length && } +

+ Followed {redirects.redirects.length}{' '} + redirect{redirects.redirects.length === 1 ? '' : 's'} when contacting host +

{redirects.redirects.map((redirect: any, index: number) => { return ( @@ -30,7 +35,7 @@ const RedirectsCard = (redirects: any): JSX.Element => { ); })} -
+ ); } diff --git a/src/components/Results/RobotsTxt.tsx b/src/components/Results/RobotsTxt.tsx index 0b16786..8063506 100644 --- a/src/components/Results/RobotsTxt.tsx +++ b/src/components/Results/RobotsTxt.tsx @@ -1,21 +1,18 @@ -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row, { RowProps } from 'components/Form/Row'; -const Outer = styled(Card)` +const cardStyles = ` .content { max-height: 28rem; overflow-y: auto; } `; -const RobotsTxtCard = ( robots: { robots: RowProps[]}): JSX.Element => { +const RobotsTxtCard = ( props: { data: { robots: RowProps[]}, title: string, actionButtons: any}): JSX.Element => { + const robots = props.data; return ( - - Crawl Rules +
{ robots.robots.length === 0 &&

No crawl rules found.

@@ -28,7 +25,7 @@ const RobotsTxtCard = ( robots: { robots: RowProps[]}): JSX.Element => { }) }
-
+ ); } diff --git a/src/components/Results/Screenshot.tsx b/src/components/Results/Screenshot.tsx index 65bd7d9..cff4fef 100644 --- a/src/components/Results/Screenshot.tsx +++ b/src/components/Results/Screenshot.tsx @@ -1,25 +1,21 @@ +import { Card } from 'components/Form/Card'; -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; - -const Outer = styled(Card)` -overflow: auto; -max-height: 28rem; -img { - border-radius: 6px; - width: 100%; - margin 0.5rem 0;; -} +const cardStyles = ` + overflow: auto; + max-height: 32rem; + img { + border-radius: 6px; + width: 100%; + margin 0.5rem 0;; + } `; -const ScreenshotCard = (screenshot: { data: string }): JSX.Element => { +const ScreenshotCard = (props: { data: { data: string }, title: string, actionButtons: any }): JSX.Element => { + const screenshot = props.data; return ( - - Screenshot + Full page screenshot - + ); } diff --git a/src/components/Results/ServerInfo.tsx b/src/components/Results/ServerInfo.tsx index af07acc..757b313 100644 --- a/src/components/Results/ServerInfo.tsx +++ b/src/components/Results/ServerInfo.tsx @@ -1,18 +1,12 @@ - -import styled from 'styled-components'; import { ServerInfo } from 'utils/result-processor'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row from 'components/Form/Row'; -const Outer = styled(Card)``; - -const ServerInfoCard = (info: ServerInfo): JSX.Element => { +const ServerInfoCard = (props: { data: ServerInfo, title: string, actionButtons: any }): JSX.Element => { + const info = props.data; const { org, asn, isp, os, ports, ip, loc, type } = info; return ( - - Server Info + { org && } { (isp && isp !== org) && } { os && } @@ -21,7 +15,7 @@ const ServerInfoCard = (info: ServerInfo): JSX.Element => { { ip && } { type && } { loc && } - + ); } diff --git a/src/components/Results/ServerLocation.tsx b/src/components/Results/ServerLocation.tsx index 4f6aadd..6d1e9d2 100644 --- a/src/components/Results/ServerLocation.tsx +++ b/src/components/Results/ServerLocation.tsx @@ -1,17 +1,13 @@ import styled from 'styled-components'; import { ServerLocation } from 'utils/result-processor'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import LocationMap from 'components/misc/LocationMap'; import Flag from 'components/misc/Flag'; import { TextSizes } from 'styles/typography'; import Row, { StyledRow } from 'components/Form/Row'; -const Outer = styled(Card)` - grid-row: span 2 -`; +const cardStyles = 'grid-row: span 2'; const SmallText = styled.span` opacity: 0.5; @@ -30,8 +26,8 @@ const CountryValue = styled.span` gap: 0.5rem; `; -const ServerLocationCard = (location: ServerLocation): JSX.Element => { - +const ServerLocationCard = (props: { data: ServerLocation, title: string, actionButtons: any }): JSX.Element => { + const location = props.data; const { city, region, country, postCode, countryCode, coords, @@ -39,8 +35,7 @@ const ServerLocationCard = (location: ServerLocation): JSX.Element => { } = location; return ( - - Location + Country @@ -56,7 +51,7 @@ const ServerLocationCard = (location: ServerLocation): JSX.Element => { Latitude: {coords.latitude}, Longitude: {coords.longitude} - + ); } diff --git a/src/components/Results/ServerStatus.tsx b/src/components/Results/ServerStatus.tsx index e070540..f23b193 100644 --- a/src/components/Results/ServerStatus.tsx +++ b/src/components/Results/ServerStatus.tsx @@ -1,28 +1,26 @@ -import styled from 'styled-components'; import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row from 'components/Form/Row'; -const Outer = styled(Card)` +const cardStyles = ` span.val { &.up { color: ${colors.success}; } &.down { color: ${colors.danger}; } } `; -const ServerStatusCard = (serverStatus: any): JSX.Element => { +const ServerStatusCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const serverStatus = props.data; return ( - - Server Status + Is Up? { serverStatus.isUp ? ✅ Online : ❌ Offline} { serverStatus.responseTime && } - + ); } diff --git a/src/components/Results/SslCert.tsx b/src/components/Results/SslCert.tsx index d9941e6..bd217e7 100644 --- a/src/components/Results/SslCert.tsx +++ b/src/components/Results/SslCert.tsx @@ -1,11 +1,9 @@ import styled from 'styled-components'; import colors from 'styles/colors'; -import Card from 'components/Form/Card'; +import { Card } from 'components/Form/Card'; import Heading from 'components/Form/Heading'; -const Outer = styled(Card)``; - const Row = styled.div` display: flex; justify-content: space-between; @@ -79,14 +77,13 @@ const ListRow = (props: { list: string[], title: string }) => { ); } -const SslCertCard = (sslCert: any): JSX.Element => { +const SslCertCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const sslCert = props.data; const { subject, issuer, fingerprint, serialNumber, asn1Curve, nistCurve, valid_to, valid_from, ext_key_usage } = sslCert; return ( - - SSL Info + { subject && } { issuer?.O && } - { asn1Curve && } { nistCurve && } { valid_to && } @@ -96,7 +93,7 @@ const SslCertCard = (sslCert: any): JSX.Element => { { fingerprint && } { ext_key_usage && } - + ); } diff --git a/src/components/Results/TraceRoute.tsx b/src/components/Results/TraceRoute.tsx index 78e770c..2c6230c 100644 --- a/src/components/Results/TraceRoute.tsx +++ b/src/components/Results/TraceRoute.tsx @@ -1,27 +1,63 @@ - import styled from 'styled-components'; import colors from 'styles/colors'; -import Card from 'components/Form/Card'; +import { Card } from 'components/Form/Card'; import Heading from 'components/Form/Heading'; -import Row from 'components/Form/Row'; -const Outer = styled(Card)``; +const RouteRow = styled.div` + text-align: center; + width: fit-content; + margin: 0 auto; + .ipName { + font-size: 1rem; + } +`; -const TraceRouteCard = (traceRouteResponse: any): JSX.Element => { - console.log(traceRouteResponse.result); +const RouteTimings = styled.div` +p { + margin: 0 auto; +} +.arrow { + font-size: 2.5rem; + color: ${colors.primary}; + margin-top: -1rem; +} +.times { + font-size: 0.85rem; + color: ${colors.textColorSecondary}; +} +.completed { + text-align: center; + font-weight: bold; +} +`; + +const TraceRouteCard = (props: { data: any, title: string, actionButtons: any }): JSX.Element => { + const traceRouteResponse = props.data; const routes = traceRouteResponse.result; - console.log(Object.keys(routes)); return ( - - Trace Route - {routes.map((route: any) => ( - + + {routes.filter((x: any) => x).map((route: any, index: number) => ( + {/* {route} */} - {Object.keys(route)[0]} - + {Object.keys(route)[0]} + + {route[Object.keys(route)[0]].map((time: any, packetIndex: number) => ( +

+ { route[Object.keys(route)[0]].length > 1 && (<>Packet #{packetIndex + 1}:) } + Took {time} ms +

+ ))} +

+
+ ) )} -
+ +

+ Round trip completed in {traceRouteResponse.timeTaken} ms +

+
+ ); } diff --git a/src/components/Results/TxtRecords.tsx b/src/components/Results/TxtRecords.tsx index 6c23678..fc5bb50 100644 --- a/src/components/Results/TxtRecords.tsx +++ b/src/components/Results/TxtRecords.tsx @@ -1,23 +1,20 @@ -import styled from 'styled-components'; -import colors from 'styles/colors'; -import Card from 'components/Form/Card'; -import Heading from 'components/Form/Heading'; +import { Card } from 'components/Form/Card'; import Row from 'components/Form/Row'; -const Outer = styled(Card)``; +const cardStyles = ''; -const TxtRecordCard = (records: any): JSX.Element => { +const TxtRecordCard = (props: {data: any, title: string, actionButtons: any }): JSX.Element => { + const records = props.data; return ( - - TXT Config + { !records && } {Object.keys(records).map((recordName: any, index: number) => { return ( ); })} - + ); } diff --git a/src/components/Results/WhoIs.tsx b/src/components/Results/WhoIs.tsx index 123bd77..4766d14 100644 --- a/src/components/Results/WhoIs.tsx +++ b/src/components/Results/WhoIs.tsx @@ -2,11 +2,9 @@ import styled from 'styled-components'; import { Whois } from 'utils/result-processor'; import colors from 'styles/colors'; -import Card from 'components/Form/Card'; +import { Card } from 'components/Form/Card'; import Heading from 'components/Form/Heading'; -const Outer = styled(Card)``; - const Row = styled.div` display: flex; justify-content: space-between; @@ -55,17 +53,17 @@ const ListRow = (props: { list: string[], title: string }) => { ); } -const ServerInfoCard = (whois: Whois): JSX.Element => { +const WhoIsCard = (props: { data: Whois, title: string, actionButtons: any }): JSX.Element => { + const whois = props.data; const { created, updated, expires, nameservers } = whois; return ( - - Who Is Info + { created && } { updated && } { expires && } { nameservers && } - + ); } -export default ServerInfoCard; +export default WhoIsCard;