diff --git a/components/Chart.js b/components/Chart.js index df7d1dd4..887e6c46 100644 --- a/components/Chart.js +++ b/components/Chart.js @@ -95,16 +95,13 @@ const Chart = memo(function Chart({ )} {error && ( -
- - Error: {error.message} - -
{JSON.stringify(error, null, 2)}
-
- +
+ + Error: {error.message} + +
{JSON.stringify(error, null, 2)}
+
} /> )} diff --git a/components/ConditionalWrapper.js b/components/ConditionalWrapper.js new file mode 100644 index 00000000..19dd698f --- /dev/null +++ b/components/ConditionalWrapper.js @@ -0,0 +1,12 @@ +// import type { ReactNode } from 'react' + +// type ConditionalWrapperProps = { +// condition: boolean +// wrapper: (children: ReactNode) => ReactNode +// children: ReactNode +// } + +const ConditionalWrapper = ({ condition, wrapper, children }) => + condition ? wrapper(children) : children + +export default ConditionalWrapper diff --git a/components/DomainChart.js b/components/DomainChart.js index 44c7a067..bbb7db30 100644 --- a/components/DomainChart.js +++ b/components/DomainChart.js @@ -75,16 +75,13 @@ const Chart = memo(function Chart({ queryParams = {}, setState }) { {error && ( -
- - Error: {error.message} - -
{JSON.stringify(error, null, 2)}
-
- +
+ + Error: {error.message} + +
{JSON.stringify(error, null, 2)}
+
} /> )} diff --git a/components/Layout.js b/components/Layout.js index 1b497263..aff2c1d4 100644 --- a/components/Layout.js +++ b/components/Layout.js @@ -4,12 +4,16 @@ import { useMemo } from 'react' import { StyledStickyNavBar } from 'components/SharedStyledComponents' import { UserProvider } from 'hooks/useUser' import { useRouter } from 'next/router' +import ConditionalWrapper from './ConditionalWrapper' import Footer from './Footer' import Header from './Header' import NavBar from './NavBar' const Layout = ({ children }) => { - const { pathname } = useRouter() + const { + pathname, + query: { webview }, + } = useRouter() const navbarColor = useMemo(() => { return pathname === '/' || @@ -34,20 +38,25 @@ const Layout = ({ children }) => {
- {navbarSticky ? ( - + {!webview && ( + ( + {children} + )} + > - - ) : ( - + )}
{children}
-
-
-
+ {!webview && ( +
+
+
+ )}
) diff --git a/components/aggregation/mat/Filters.js b/components/aggregation/mat/Filters.js index 68f7a22d..8e72cd8c 100644 --- a/components/aggregation/mat/Filters.js +++ b/components/aggregation/mat/Filters.js @@ -312,10 +312,7 @@ const Filters = ({ data = [], tableData, setDataForCharts, query }) => { }) return ( - +
+ - - -
+
+ )} } content={ diff --git a/components/measurement/CommonSummary.js b/components/measurement/CommonSummary.js index 21fc9b99..eedaddf4 100644 --- a/components/measurement/CommonSummary.js +++ b/components/measurement/CommonSummary.js @@ -1,7 +1,9 @@ import Link from 'next/link' +import { useRouter } from 'next/router' import PropTypes from 'prop-types' import { MdOutlineFactCheck } from 'react-icons/md' import { useIntl } from 'react-intl' +import ConditionalWrapper from '../ConditionalWrapper' import Flag from '../Flag' const CommonSummary = ({ @@ -14,6 +16,9 @@ const CommonSummary = ({ hero, onVerifyClick, }) => { + const { + query: { webview }, + } = useRouter() const intl = useIntl() const startTime = measurement_start_time const network = probe_asn @@ -32,27 +37,36 @@ const CommonSummary = ({ >
-
{formattedDate}
-
-
- -
-
- {intl - .formatMessage({ id: 'Measurement.CommonSummary.Verify' }) - .toUpperCase()} +
{formattedDate}
+ {!webview && ( +
+
+ +
+
+ {intl + .formatMessage({ id: 'Measurement.CommonSummary.Verify' }) + .toUpperCase()} +
-
+ )}
{hero} -
+
- ( + + {children} + + )} >
@@ -60,13 +74,22 @@ const CommonSummary = ({
{country}
- - + ( + + {children} + + )} > - {network} {networkName} - +
+ {network} {networkName} +
+
diff --git a/components/measurement/DetailsBox.js b/components/measurement/DetailsBox.js index 4bc2ec27..fcce7895 100644 --- a/components/measurement/DetailsBox.js +++ b/components/measurement/DetailsBox.js @@ -1,3 +1,4 @@ +import { useRouter } from 'next/router' import PropTypes from 'prop-types' import { useCallback, useState } from 'react' import { MdExpandLess } from 'react-icons/md' @@ -35,29 +36,38 @@ export const DetailsBox = ({ className, ...rest }) => { + const { + query: { webview }, + } = useRouter() + const [isOpen, setIsOpen] = useState(!collapsed) const onToggle = useCallback(() => { setIsOpen(!isOpen) - }, [isOpen, setIsOpen]) + }, [isOpen]) return (
- {title && ( -
- {title} - -
- )} + {title && + (webview ? ( +
+ {title} +
+ ) : ( +
+ {title} + +
+ ))} {isOpen && (
{content || children} diff --git a/components/measurement/StatusInfo.js b/components/measurement/StatusInfo.js index 05e83c07..3f8cf7ee 100644 --- a/components/measurement/StatusInfo.js +++ b/components/measurement/StatusInfo.js @@ -2,7 +2,7 @@ import PropTypes from 'prop-types' const StatusInfo = ({ title, message }) => (
-
{title}
+
{title}
{' '} {message}{' '} diff --git a/components/measurement/nettests/Telegram.js b/components/measurement/nettests/Telegram.js index 10d1281d..72250801 100644 --- a/components/measurement/nettests/Telegram.js +++ b/components/measurement/nettests/Telegram.js @@ -88,7 +88,6 @@ const TelegramDetails = ({ measurement, render }) => { title={ } - collapsed={false} > {tcp_connect.map((connection, index) => (
diff --git a/components/measurement/nettests/WebConnectivity.js b/components/measurement/nettests/WebConnectivity.js index 02a4ed69..67d61d61 100644 --- a/components/measurement/nettests/WebConnectivity.js +++ b/components/measurement/nettests/WebConnectivity.js @@ -1,13 +1,14 @@ import bufferFrom from 'buffer-from' import deepmerge from 'deepmerge' import Link from 'next/link' +import { useRouter } from 'next/router' import { Cross, Tick } from 'ooni-components/icons' import PropTypes from 'prop-types' -import url from 'url' - +import { Fragment } from 'react' import { FormattedMessage, defineMessages, useIntl } from 'react-intl' +import url from 'url' -import { Fragment } from 'react' +import ConditionalWrapper from '../../ConditionalWrapper' import { DetailsBox } from '../DetailsBox' import StatusInfo from '../StatusInfo' @@ -286,6 +287,22 @@ const StyledLink = ({ children, href }) => ( ) +const UrlWrapper = ({ href }) => { + const { + query: { webview }, + } = useRouter() + return ( + ( + {children} + )} + > + {href} + + ) +} + const WebConnectivityDetails = ({ isConfirmed, isAnomaly, @@ -312,6 +329,10 @@ const WebConnectivityDetails = ({ }, } = validateMeasurement(measurement ?? {}) + const { + query: { webview }, + } = useRouter() + const intl = useIntl() const date = new Intl.DateTimeFormat(intl.locale, { dateStyle: 'long', @@ -336,7 +357,8 @@ const WebConnectivityDetails = ({ values={{ date, WebsiteURL: ( - {input} + + // {input} ), network: probe_asn, country, @@ -351,7 +373,8 @@ const WebConnectivityDetails = ({ values={{ date, WebsiteURL: ( - {input} + + // {input} ), network: probe_asn, country, @@ -381,7 +404,8 @@ const WebConnectivityDetails = ({ values={{ date, WebsiteURL: ( - {input} + + // {input} ), 'link-to-docs': (string) => ( @@ -414,7 +438,8 @@ const WebConnectivityDetails = ({ values={{ date, WebsiteURL: ( - {input} + + // {input} ), network: probe_asn, country, @@ -441,7 +466,8 @@ const WebConnectivityDetails = ({ values={{ date, WebsiteURL: ( - {input} + + // {input} ), network: probe_asn, country, @@ -469,7 +495,8 @@ const WebConnectivityDetails = ({ values={{ date, WebsiteURL: ( - {input} + + // {input} ), network: probe_asn, country, @@ -505,12 +532,19 @@ const WebConnectivityDetails = ({ statusInfo: ( ( + + {children} + + )} > {input} - + } message={reason} /> diff --git a/pages/m/[measurement_uid].js b/pages/m/[measurement_uid].js index 9d78b060..be87d3fa 100644 --- a/pages/m/[measurement_uid].js +++ b/pages/m/[measurement_uid].js @@ -1,10 +1,11 @@ import axios from 'axios' import Head from 'next/head' +import { useRouter } from 'next/router' import { colors } from 'ooni-components' import PropTypes from 'prop-types' import { useMemo, useState } from 'react' +import { useIntl } from 'react-intl' import useSWR from 'swr' -import { getLocalisedRegionName } from '/utils/i18nCountries' import CommonDetails from 'components/measurement/CommonDetails' import CommonSummary from 'components/measurement/CommonSummary' @@ -14,12 +15,11 @@ import HeadMetadata from 'components/measurement/HeadMetadata' import Hero from 'components/measurement/Hero' import MeasurementContainer from 'components/measurement/MeasurementContainer' import SummaryText from 'components/measurement/SummaryText' - import useUser from 'hooks/useUser' import ErrorPage from 'pages/_error' -import { useIntl } from 'react-intl' import NotFound from '../../components/NotFound' import { fetcher } from '/lib/api' +import { getLocalisedRegionName } from '/utils/i18nCountries' const pageColors = { default: colors.blue['500'], @@ -138,7 +138,7 @@ const Measurement = ({ value, })) : [] - }, [userFeedback]) + }, [userFeedback, intl]) // Add the 'AS' prefix to probe_asn when API chooses to send just the number probe_asn = typeof probe_asn === 'number' ? `AS${probe_asn}` : probe_asn @@ -181,6 +181,10 @@ const Measurement = ({ headMetadata, details, }) => { + const { + query: { webview }, + } = useRouter() + const color = failure === true ? pageColors.error : pageColors[status] const info = scores?.msg ?? statusInfo @@ -222,12 +226,14 @@ const Measurement = ({ onVerifyClick={() => setShowModal(true)} />
- + {!webview && ( + + )} {summaryText && (