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

Implement skeleton for Test Details Views #44

Merged
merged 4 commits into from Oct 2, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
165 changes: 140 additions & 25 deletions renderer/components/measurement/MeasurementContainer.js
@@ -1,15 +1,14 @@
import React from 'react'

import PropTypes from 'prop-types'
import moment from 'moment'

import { Text } from 'rebass'
import {
Text,
Container,
Flex,
Box,
Heading
} from 'ooni-components'
import { FormattedMessage } from 'react-intl'
import { FormattedMessage, FormattedDate } from 'react-intl'
import styled from 'styled-components'


Expand All @@ -22,11 +21,14 @@ import {
MdPublic
} from 'react-icons/md'

import { renderDetails, testGroups } from '../nettests'
import { renderDetails, testGroups, tests } from '../nettests'
import TwoColumnTable from '../TwoColumnTable'
import BackButton from '../BackButton'
import { StickyContainer, Sticky } from 'react-sticky'

import { FacebookMessengerDetails } from '../nettests/im/facebook-messenger'
import { WebConnectivity } from '../nettests/websites/WebConnectivity'

const MeasurementOverviewContainer = styled.div`
position: relative;
width: 100%;
Expand Down Expand Up @@ -97,32 +99,145 @@ const HeaderContent = styled(Box)`
-webkit-app-region: drag;
`

// TODO: (sarathms) Add rest of the implementations when ready
const detailsMap = {
web_connectivity: WebConnectivity,
facebook_messenger: FacebookMessengerDetails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that more will come later? If so, please add a // TODO(sarathms): ... comment to say that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

}

const Placeholder = ({ id }) => <Box px={5} py={3} bg='gray3'>{id}</Box>

const HeroItemBox = ({ label, content, ...props }) => (
<Box p={3} {...props}>
<Text fontSize={24} fontWeight={300}>{content}</Text>
<Text fontSize={16} fontWeight={600}>{label}</Text>
</Box>
)

HeroItemBox.propTypes = {
label: PropTypes.node,
content: PropTypes.node
}

const StickyHero = ({
isSticky,
bg,
testName,
startTime,
networkName,
asn
}) => {
const testFullName = tests[testName].name
if (isSticky) {
return (
<Flex bg={bg} color='white' alignItems='center'>
<Box><BackButton /></Box>
<Box><Heading textAlign='center' h={4}>{testFullName}</Heading></Box>
</Flex>
)
} else {
return (
<Flex flexWrap='wrap' bg={bg} color='white'>
<Box width={1}>
<Flex>
<Box>
<BackButton />
</Box>
<Box>
<Heading textAlign='center' h={4}>{testFullName}</Heading>
</Box>
</Flex>
</Box>
<Box width={1} my={4}>

</Box>
<Box width={1}>
<Flex flexWrap='wrap'>
<HeroItemBox
width={1/2}
label={<FormattedMessage id='TestResults.Summary.Hero.DateAndTime' />}
content={moment.utc(new Date(startTime)).format('lll')}
/>
<HeroItemBox
width={1/2}
label={<FormattedMessage id='TestResults.Summary.Hero.Network' />}
content={`${networkName} (AS${asn})`}
/>
</Flex>
</Box>
</Flex>
)
}
}

const MeasurementDetailContainer = ({ measurement, ...props }) => {
const TestDetails = detailsMap[measurement.test_name]
return (
<TestDetails measurement={measurement} {...props} />
)
}

MeasurementDetailContainer.propTypes = {
measurement: PropTypes.object
}

const MeasurementContainer = ({measurement}) => {
const overviewProps = mapOverviewProps(measurement)
const testName = measurement.test_name
const startTime = measurement.start_time
const networkName = measurement.network_name
const asn = measurement.asn

return (
<StickyContainer>
<Sticky topOffset={100}>
{({
style,
isSticky
}) => {
return (
<HeaderContent
bg={overviewProps.group.color}
style={style}>
<MeasurementOverview
isSticky={isSticky}
{...overviewProps}
/>
</HeaderContent>
)
}}
</Sticky>
{renderDetails(measurement)}
</StickyContainer>
<MeasurementDetailContainer
measurement={measurement}
render={({
heroBG,
hero,
collapsedHero,
details
}) => (
<StickyContainer>
<Sticky topOffset={100}>
{({
style,
isSticky
}) => {
return (
<Box style={style}>
<StickyHero
isSticky={isSticky}
bg={heroBG}
testName={testName}
startTime={startTime}
networkName={networkName}
asn={asn}
hero={hero}
collapsedHero={collapsedHero}
/>
</Box>
)
}}
</Sticky>
<Flex my={3} justifyContent='space-around'>
<Placeholder id='Methodology' />
<Placeholder id='Runtime: 2s' />
</Flex>
{details}
<Flex my={3} justifyContent='space-around'>
<Placeholder id='Raw Data' />
<Placeholder id='Explorer URL' />
<Placeholder id='View Log' />
</Flex>
</StickyContainer>
)}
/>
)

}

MeasurementContainer.propTypes = {
measurement: PropTypes.object
}

export default MeasurementContainer
21 changes: 21 additions & 0 deletions renderer/components/nettests/index.js
Expand Up @@ -16,6 +16,8 @@ import middlebox from './middleboxes'
import performance from './performance'
import websites from './websites'

import web_connectivity from './websites/WebConnectivity'

import {
Cross,
Tick
Expand Down Expand Up @@ -89,6 +91,25 @@ export const testGroups = {
}
}

// Metadata for tests
// Contains: {
// name: Full descriptive name of the test, translated with <FormattedMessage>
//}
export const tests = {
// TODO: (sarathms) Replace each one with their own implementations when ready
web_connectivity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is syntactic sugar for web_connectivity: web_connectivity, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct.

http_header_field_manipulation: web_connectivity,
http_invalid_request_line: web_connectivity,
telegram: web_connectivity,
whatsapp: web_connectivity,
ndt: web_connectivity,
dash: web_connectivity,
vanilla_tor: web_connectivity,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your goal is to later replace each of them, please add a TODO(sarathms): ... comment to indicate that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TODO

'default': {
'name': 'Default',
}
}

export const testList = ['websites', 'im', 'performance', 'middlebox'].map(key => ({
name: testGroups[key].name,
key: key,
Expand Down
45 changes: 45 additions & 0 deletions renderer/components/nettests/websites/WebConnectivity.js
@@ -0,0 +1,45 @@
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { Flex, Box, Text } from 'ooni-components'

const WebConnectivity = ({measurement, render}) => {

const WebDetails = () => (
<Flex justifyContent='center'>
<Box>
<Flex my={6}>
<Box> Web Details </Box>
<Box> </Box>
</Flex>
<Flex my={6}>
<Box> More Details </Box>
<Box> </Box>
</Flex>
<Flex my={6}>
<Box> More Details </Box>
<Box> </Box>
</Flex>
<Flex my={6}>
<Box> More Details </Box>
<Box> </Box>
</Flex>
</Box>
</Flex>
)

return (
<div>
{render({
heroBG: 'green8', // TODO: (sarathms) Determine color based on presence of anomaly
details: <WebDetails />
})}
</div>
)
}

export { WebConnectivity }

// Metadata for the nettest
export default {
name: <FormattedMessage id='Test.WebConnectivity.Fullname' />
}