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

Make location display component form-ready #590

Merged
merged 2 commits into from
Jul 20, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,18 @@ describe('Curator', function () {
cy.contains('Albanian');

// Location.
cy.contains('France');
cy.contains('Country');
cy.contains('45.75');
cy.contains('4.84');
cy.get('input[name="location.country"]').should(
'have.value',
'France',
);
cy.get('input[name="location.geometry.latitude"]').should(
'have.value',
'45.75889',
);
cy.get('input[name="location.geometry.longitude"]').should(
'have.value',
'4.84139',
);
// Events.
cy.get('input[name="onsetSymptomsDate"]').should(
'have.value',
Expand Down Expand Up @@ -289,6 +297,7 @@ describe('Curator', function () {
cy.contains('Afghan, Albanian');
cy.contains('Asian');
cy.contains('France');
// Rounded numbers when displayed.
cy.contains('45.7589');
cy.contains('4.8414');
// Events.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ it('loads and displays case to edit', async () => {
).toBeInTheDocument();
expect(getByDisplayValue('NC_045512.2')).toBeInTheDocument();
expect(getByDisplayValue('33000')).toBeInTheDocument();
expect(getByText('France')).toBeInTheDocument();
expect(getByText('Île-de-F')).toBeInTheDocument();
expect(getByText('Paris')).toBeInTheDocument();
expect(getByDisplayValue('France')).toBeInTheDocument();
expect(getByDisplayValue('Île-de-F')).toBeInTheDocument();
expect(getByDisplayValue('Paris')).toBeInTheDocument();
expect(getByDisplayValue('Recovered')).toBeInTheDocument();
expect(getByText('Severe pneumonia')).toBeInTheDocument();
expect(getByText('United States')).toBeInTheDocument();
expect(getByDisplayValue('United States')).toBeInTheDocument();
expect(getByDisplayValue('Family')).toBeInTheDocument();
// TODO: These show up locally but we need to figure out how to properly
// query them in tests.
Expand Down
6 changes: 3 additions & 3 deletions verification/curator-service/ui/src/components/StaticMap.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Location } from './Case';
import { Geometry } from './Case';
import React from 'react';

export default function StaticMap(props: { location: Location }): JSX.Element {
export default function StaticMap(props: { geometry: Geometry }): JSX.Element {
return (
<img
src={`https://api.mapbox.com/styles/v1/mapbox/light-v10/static/${props.location?.geometry?.longitude},${props.location?.geometry?.latitude},5,0/450x200?access_token=${process.env.REACT_APP_PUBLIC_MAPBOX_TOKEN}`}
src={`https://api.mapbox.com/styles/v1/mapbox/light-v10/static/${props.geometry.longitude},${props.geometry.latitude},5,0/450x200?access_token=${process.env.REACT_APP_PUBLIC_MAPBOX_TOKEN}`}
alt="map"
></img>
);
Expand Down
4 changes: 3 additions & 1 deletion verification/curator-service/ui/src/components/ViewCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,9 @@ function TravelRow(props: { travel: Travel }): JSX.Element {
function MapRow(props: { location?: Location }): JSX.Element {
return (
<Grid item xs={8}>
{props.location && <StaticMap location={props.location} />}
{props.location?.geometry && (
<StaticMap geometry={props.location.geometry} />
)}
</Grid>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,35 @@
import { render, screen } from '@testing-library/react';
import { Form, Formik } from 'formik';

import Location from './Location';
import React from 'react';
import { render } from '@testing-library/react';

test('shows location when passed location information', async () => {
render(
<Location
location={{
geoResolution: 'place',
country: 'United States',
administrativeAreaLevel1: 'Hillsborough County',
administrativeAreaLevel2: '',
administrativeAreaLevel3: 'Some city',
geometry: {
latitude: 80.45,
longitude: 27.9379,
},
name: 'some name',
place: '',
}}
/>,
const loc: Loc = {
geoResolution: 'place',
country: 'United States',
administrativeAreaLevel1: 'Hillsborough County',
administrativeAreaLevel2: '',
administrativeAreaLevel3: 'Some city',
geometry: {
latitude: 80.45,
longitude: 27.9379,
},
name: 'some name',
place: '',
};
const { getByDisplayValue } = render(
<Formik initialValues={{ location: loc }}>
<Form>
<Location locationPath="location" geometry={loc.geometry} />
</Form>
</Formik>,
);
expect(screen.getByText(/place/i)).toBeInTheDocument();
expect(screen.getByText(/united States/i)).toBeInTheDocument();
expect(screen.getByText(/Hillsborough County/i)).toBeInTheDocument();
expect(screen.getByText(/Some city/i)).toBeInTheDocument();
expect(screen.getByText(/place/i)).toBeInTheDocument();
expect(screen.getByText(/80.4500/i)).toBeInTheDocument();
expect(screen.getByText(/27.9379/i)).toBeInTheDocument();
expect(screen.getByText(/N\/A/i)).toBeInTheDocument();
});

test('shows empty defaults when location undefined', async () => {
render(<Location location={undefined} />);
expect(screen.getByText(/Country/i)).toBeInTheDocument();
expect(getByDisplayValue(/place/i)).toBeInTheDocument();
expect(getByDisplayValue(/united States/i)).toBeInTheDocument();
expect(getByDisplayValue(/Hillsborough County/i)).toBeInTheDocument();
expect(getByDisplayValue(/Some city/i)).toBeInTheDocument();
expect(getByDisplayValue(/place/i)).toBeInTheDocument();
expect(getByDisplayValue(/80.45/i)).toBeInTheDocument();
expect(getByDisplayValue(/27.9379/i)).toBeInTheDocument();
});
Original file line number Diff line number Diff line change
@@ -1,82 +1,120 @@
import { Divider, Typography } from '@material-ui/core';

import { Location as Loc } from '../Case';
import { Divider } from '@material-ui/core';
import { Field } from 'formik';
import { Geometry } from '../Case';
import React from 'react';
import StaticMap from '../StaticMap';
import { TextField } from 'formik-material-ui';
import { makeStyles } from '@material-ui/core/styles';

const styles = makeStyles(() => ({
root: {
display: 'flex',
flexWrap: 'wrap',
},
column: {
field: {
marginRight: '1em',
width: '8em',
},
mapContainer: {
textAlign: 'center',
},
divider: {
marginTop: '1em',
marginBottom: '1em',
},
}));

export default function Location(props: { location?: Loc }): JSX.Element {
export default function Location(props: {
locationPath: string;
geometry?: Geometry;
}): JSX.Element {
const classes = styles();
return (
<>
<div className={classes.root}>
<div className={classes.column}>
<p>
<Typography variant="caption">Location Type</Typography>
</p>
<p>{props.location?.geoResolution}</p>
</div>
<div className={classes.column}>
<p>
<Typography variant="caption">Country</Typography>
</p>
<p>{props.location?.country}</p>
</div>
<div className={classes.column}>
<p>
<Typography variant="caption">Admin area 1</Typography>
</p>
<p>{props.location?.administrativeAreaLevel1 || 'N/A'}</p>
</div>
<div className={classes.column}>
<p>
<Typography variant="caption">Admin area 2</Typography>
</p>
<p>{props.location?.administrativeAreaLevel2 || 'N/A'}</p>
</div>
<div className={classes.column}>
<p>
<Typography variant="caption">Admin area 3</Typography>
</p>
<p>{props.location?.administrativeAreaLevel3 || 'N/A'}</p>
</div>
<div className={classes.column}>
<p>
<Typography variant="caption">Latitude</Typography>
</p>
<p>
{props.location?.geometry?.latitude?.toFixed(4) || '-'}
</p>
</div>
<div className={classes.column}>
<p>
<Typography variant="caption">Longitude</Typography>
</p>
<p>
{props.location?.geometry?.longitude?.toFixed(4) || '-'}
</p>
</div>
<Field
className={classes.field}
disabled
label="Location type"
size="small"
name={`${props.locationPath}.geoResolution`}
type="text"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
<Field
className={classes.field}
disabled
label="Country"
name={`${props.locationPath}.country`}
type="text"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
<Field
className={classes.field}
disabled
label="Admin area 1"
name={`${props.locationPath}.administrativeAreaLevel1`}
type="text"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
<Field
className={classes.field}
disabled
label="Admin area 2"
name={`${props.locationPath}.administrativeAreaLevel2`}
type="text"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
<Field
className={classes.field}
disabled
label="Admin area 3"
name={`${props.locationPath}.administrativeAreaLevel3`}
type="text"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
<Field
className={classes.field}
disabled
label="Latitude"
name={`${props.locationPath}.geometry.latitude`}
type="number"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
<Field
className={classes.field}
disabled
label="Longitude"
name={`${props.locationPath}.geometry.longitude`}
type="number"
component={TextField}
InputLabelProps={{
shrink: true,
}}
/>
</div>
{props.location?.geometry !== undefined && (
{props.geometry && (
<div className={classes.mapContainer}>
<Divider className={classes.divider} variant="middle" />
<StaticMap location={props.location}></StaticMap>
<StaticMap geometry={props.geometry}></StaticMap>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ function LocationForm(): JSX.Element {
name="location"
required
/>
{values.location && <Location location={values.location} />}
{values.location && (
<Location
locationPath="location"
geometry={values.location?.geometry}
/>
)}
</fieldset>
</Scroll.Element>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ export default function Events(): JSX.Element {
></PlacesAutocomplete>
{travelHistoryElement.location && (
<Location
location={
travelHistoryElement.location
locationPath={`travelHistory[${index}].location`}
geometry={
values
.travelHistory[
index
]?.location
?.geometry
}
></Location>
)}
Expand Down