Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce webview for measurement pages #972

Merged
merged 8 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions components/Chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,13 @@ const Chart = memo(function Chart({
)}
{error && (
<DetailsBox
collapsed={false}
content={
<>
<details>
<summary>
<span>Error: {error.message}</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
</>
<details>
<summary>
<span>Error: {error.message}</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
}
/>
)}
Expand Down
12 changes: 12 additions & 0 deletions components/ConditionalWrapper.js
Original file line number Diff line number Diff line change
@@ -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
15 changes: 6 additions & 9 deletions components/DomainChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,13 @@ const Chart = memo(function Chart({ queryParams = {}, setState }) {
</div>
{error && (
<DetailsBox
collapsed={false}
content={
<>
<details>
<summary>
<span>Error: {error.message}</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
</>
<details>
<summary>
<span>Error: {error.message}</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
}
/>
)}
Expand Down
26 changes: 16 additions & 10 deletions components/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ 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 Layout = ({ children, isEmbeddedView }) => {
const { pathname } = useRouter()

const navbarColor = useMemo(() => {
Expand All @@ -31,23 +32,28 @@ const Layout = ({ children }) => {

return (
<UserProvider>
<div className="site text-sm flex flex-col min-h-[100vh]">
<div className="site flex flex-col min-h-[100vh]">
<div className="flex-[1_0_auto]">
<Header />
{navbarSticky ? (
<StyledStickyNavBar>
{!isEmbeddedView && (
<ConditionalWrapper
condition={!!navbarSticky}
wrapper={(children) => (
<StyledStickyNavBar>{children}</StyledStickyNavBar>
)}
>
<NavBar color={navbarColor} />
</StyledStickyNavBar>
) : (
<NavBar color={navbarColor} />
</ConditionalWrapper>
)}
<div className={`content ${!navbarColor && 'mt-[-66px]'}`}>
{children}
</div>
</div>
<div className="flex-shrink-0">
<Footer />
</div>
{!isEmbeddedView && (
<div className="flex-shrink-0">
<Footer />
</div>
)}
</div>
</UserProvider>
)
Expand Down
2 changes: 1 addition & 1 deletion components/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export const NavBar = ({ color }) => {
</div>
)}
<div
className={`flex gap-4 lg:gap-8 ${showMenu && 'pt-2 flex-col items-start [&>a]:border-black [&>a]:hover:border-black [&>*]:opacity-100 [&>*]:text-black [&>*]:hover:text-black'}`}
className={`flex gap-4 lg:gap-8 text-sm ${showMenu && 'pt-2 flex-col items-start [&>a]:border-black [&>a]:hover:border-black [&>*]:opacity-100 [&>*]:text-black [&>*]:hover:text-black'}`}
>
<NavItem
label={<FormattedMessage id="Navbar.Findings" />}
Expand Down
4 changes: 2 additions & 2 deletions components/SocialButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ const SocialButtons = ({ url }) => {
const intl = useIntl()

return (
<div className="flex px-2 items-center">
<div className="flex gap-2 items-center">
<MdShare height="20px" width="20px" />
<div className="pl-2 text-right">
<div>
{intl.formatMessage(
{ id: 'SocialButtons.CTA' },
{
Expand Down
5 changes: 1 addition & 4 deletions components/aggregation/mat/Filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,7 @@ const Filters = ({ data = [], tableData, setDataForCharts, query }) => {
})

return (
<DetailsBox
title={intl.formatMessage({ id: 'MAT.Table.Filters' })}
collapsed={false}
>
<DetailsBox title={intl.formatMessage({ id: 'MAT.Table.Filters' })}>
<div className="flex flex-col">
<div className="flex mb-4 items-center">
<button
Expand Down
2 changes: 1 addition & 1 deletion components/aggregation/mat/Help.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const boxTitle = (

const Help = () => {
return (
<DetailsBox title={boxTitle} collapsed={false}>
<DetailsBox title={boxTitle}>
<FormattedMarkdown id="MAT.Help.Content" />
<div className="flex flex-col">
{[...getCategoryCodesMap().values()].map(
Expand Down
51 changes: 23 additions & 28 deletions components/country/ConfirmedBlockedCategory.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,32 @@ const ConfirmedBlockedCategory = () => {
id: 'Country.Websites.ConfirmedBlockedCategories',
})}
</h3>
<>
{!blockedCategoriesData && !error ? (
<div> Loading ...</div>
) : blockedCategoriesData === null ||
blockedCategoriesData.length === 0 ? (
<h5>
<FormattedMessage id="General.NoData" />
</h5>
) : (
<div className="flex flex-wrap gap-2">
{blockedCategoriesData?.map((category) => (
<CategoryBadge
key={category.category_code}
categoryCode={category.category_code}
/>
))}
</div>
)}
</>
{!blockedCategoriesData && !error ? (
<div> Loading ...</div>
) : blockedCategoriesData === null ||
blockedCategoriesData.length === 0 ? (
<h5>
<FormattedMessage id="General.NoData" />
</h5>
) : (
<div className="flex flex-wrap gap-2">
{blockedCategoriesData?.map((category) => (
<CategoryBadge
key={category.category_code}
categoryCode={category.category_code}
/>
))}
</div>
)}
{error && (
<DetailsBox
collapsed={false}
content={
<>
<details>
<summary>
<span>Error: {error.message}</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
</>
<details>
<summary>
<span>Error: {error.message}</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
}
/>
)}
Expand Down
20 changes: 8 additions & 12 deletions components/dashboard/Charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,15 @@ const Chart = memo(function Chart({ testName }) {
</div>
{error && (
<DetailsBox
collapsed={false}
content={
<>
<details>
<summary>
<span>
{intl.formatMessage({ id: 'General.Error' })}:{' '}
{error.message}
</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
</>
<details>
<summary>
<span>
{intl.formatMessage({ id: 'General.Error' })}: {error.message}
</span>
</summary>
<pre>{JSON.stringify(error, null, 2)}</pre>
</details>
}
/>
)}
Expand Down
87 changes: 41 additions & 46 deletions components/measurement/CommonDetails.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'
import { colors } from 'ooni-components'
import PropTypes from 'prop-types'
import { useState } from 'react'
import { useContext, useState } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'

import { EmbeddedViewContext } from '../../pages/m/[measurement_uid]'
import { DetailsBox, DetailsBoxTable } from './DetailsBox'

const LoadingRawData = () => {
Expand All @@ -21,7 +21,7 @@ const ReactJson = dynamic(() => import('react-json-view'), {
})

const JsonViewer = ({ src, collapsed }) => (
<div className="[&_.string-value]:overflow-ellipsis [&_.string-value]:max-w-[800px] [&_.string-value]:overflow-hidden [&_.string-value]:inline-block">
<div className="text-xs md:text-sm [&_.string-value]:overflow-ellipsis [&_.string-value]:max-w-[800px] [&_.string-value]:overflow-hidden [&_.string-value]:inline-block">
<ReactJson collapsed={collapsed} src={src} name={null} indentWidth={2} />
</div>
)
Expand All @@ -45,6 +45,8 @@ const CommonDetails = ({
resolver_network_name,
} = measurement ?? {}

const isEmbeddedView = useContext(EmbeddedViewContext)

const { query } = useRouter()
const queryString = new URLSearchParams(query)
const rawMsmtDownloadURL = `${process.env.NEXT_PUBLIC_OONI_API}/api/v1/raw_measurement?${queryString}`
Expand Down Expand Up @@ -137,42 +139,35 @@ const CommonDetails = ({
return (
<>
{showResolverItems && (
<div className="flex my-8">
{/* Resolver data */}
<DetailsBoxTable
title={
<FormattedMessage id="Measurement.CommonDetails.Label.Resolver" />
}
items={resolverItems}
/>
</div>
// Resolver data
<DetailsBoxTable
title={
<FormattedMessage id="Measurement.CommonDetails.Label.Resolver" />
}
items={resolverItems}
/>
)}
<div className="flex my-8">
{/* Metadata: platform, probe, MK version etc. */}
<DetailsBoxTable items={items} className="bg-gray-200" />
</div>
{/* Metadata: platform, probe, MK version etc. */}
<DetailsBoxTable items={items} className="bg-gray-200" />
{/* User Feedback */}
{!!userFeedbackItems.length && (
<div className="flex my-8">
<DetailsBoxTable
title={
<FormattedMessage id="Measurement.CommonDetails.Label.UserFeedback" />
}
items={userFeedbackItems}
/>
</div>
<DetailsBoxTable
title={
<FormattedMessage id="Measurement.CommonDetails.Label.UserFeedback" />
}
items={userFeedbackItems}
/>
)}
{/* Raw Measurement */}
<div className="flex">
<DetailsBox
collapsed={false}
title={
<div className="flex flex-1 px-4 justify-between flex-col md:flex-row items-center bg-gray-200">
<div>
{intl.formatMessage({
id: 'Measurement.CommonDetails.RawMeasurement.Heading',
})}
</div>
<DetailsBox
title={
<div className="flex flex-1 justify-between flex-col md:flex-row items-center bg-gray-200">
<div className="self-start">
{intl.formatMessage({
id: 'Measurement.CommonDetails.RawMeasurement.Heading',
})}
</div>
{!isEmbeddedView && (
<div className="flex">
<a
className="text-blue-700"
Expand Down Expand Up @@ -201,19 +196,19 @@ const CommonDetails = ({
})}
</button>
</div>
)}
</div>
}
content={
measurement && typeof measurement === 'object' ? (
<div className="flex bg-white" style={{ direction: 'ltr' }}>
<JsonViewer src={measurement} collapsed={collapsed} />
</div>
}
content={
measurement && typeof measurement === 'object' ? (
<div className="flex bg-white p-4" style={{ direction: 'ltr' }}>
<JsonViewer src={measurement} collapsed={collapsed} />
</div>
) : (
<FormattedMessage id="Measurement.CommonDetails.RawMeasurement.Unavailable" />
)
}
/>
</div>
) : (
<FormattedMessage id="Measurement.CommonDetails.RawMeasurement.Unavailable" />
)
}
/>
</>
)
}
Expand Down
Loading