-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First pass at a frontend for the pixel-driller API. Clicking anywhere on the map opens a righthand sidebar panel with tables of hazard information for that point.
- Loading branch information
1 parent
a88df49
commit 717aa38
Showing
12 changed files
with
4,128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { StoryObj, Meta } from '@storybook/react'; | ||
import { expect, within } from '@storybook/test'; | ||
import { http, HttpResponse } from 'msw'; | ||
|
||
import mockPixelData from 'mocks/details/pixel-data/mockPixelData.json'; | ||
import { PixelData } from './PixelData'; | ||
|
||
function FixedWidthDecorator(Story) { | ||
return ( | ||
<div style={{ width: '60ch' }}> | ||
<Story /> | ||
</div> | ||
); | ||
} | ||
|
||
const meta = { | ||
title: 'Details/PixelData', | ||
component: PixelData, | ||
decorators: [FixedWidthDecorator], | ||
} as Meta; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
parameters: { | ||
msw: { | ||
handlers: [ | ||
http.get('/pixel/0.000/0.000', () => { | ||
return HttpResponse.json(mockPixelData); | ||
}), | ||
], | ||
}, | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
expect(await canvas.findByText('Cyclones: speed (m s-1)')).toBeTruthy(); | ||
expect(await canvas.findByText('River flooding: depth (m)')).toBeTruthy(); | ||
expect(await canvas.findByText('Surface flooding: depth (m)')).toBeTruthy(); | ||
const grids = await canvas.findAllByRole('grid'); | ||
expect(grids).toHaveLength(6); | ||
grids.forEach((grid, i) => { | ||
const rowGroup = within(grid).getByRole('rowgroup'); | ||
expect(rowGroup).toBeTruthy(); | ||
const rows = within(rowGroup).getAllByRole('row'); | ||
expect(rows.length).toBeGreaterThan(0); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useRecoilValue, useSetRecoilState } from 'recoil'; | ||
|
||
import { Box, IconButton } from '@mui/material'; | ||
import { SidePanel } from 'details/SidePanel'; | ||
import { ErrorBoundary } from 'lib/react/ErrorBoundary'; | ||
import { MobileTabContentWatcher } from 'lib/map/layouts/tab-has-content'; | ||
import { | ||
pixelDrillerDataHeaders, | ||
pixelDrillerDataState, | ||
pixelSelectionState, | ||
} from 'lib/state/pixel-driller'; | ||
import { PixelDataGrid } from './PixelDataGrid'; | ||
import { Close } from '@mui/icons-material'; | ||
|
||
/** | ||
* Display detailed information about a selected pixel (lat/lon point.) | ||
*/ | ||
export const PixelData = () => { | ||
const { data: selectedData } = useRecoilValue(pixelDrillerDataState); | ||
const headers = useRecoilValue(pixelDrillerDataHeaders); | ||
const setPixelSelection = useSetRecoilState(pixelSelectionState); | ||
|
||
function clearSelectedLocation() { | ||
setPixelSelection(null); | ||
} | ||
|
||
if (!selectedData) { | ||
return null; | ||
} | ||
if (!headers.length) { | ||
return null; | ||
} | ||
const hazards = [...new Set(selectedData.hazard)]; | ||
|
||
return ( | ||
<SidePanel position="relative"> | ||
<MobileTabContentWatcher tabId="details" /> | ||
<ErrorBoundary message="There was a problem displaying these details."> | ||
<Box position="absolute" top={0} right={0} p={2}> | ||
<IconButton onClick={clearSelectedLocation} title={'Close'}> | ||
<Close /> | ||
</IconButton> | ||
</Box> | ||
{hazards.map((hazard) => ( | ||
<Box key={hazard} mt={2}> | ||
<PixelDataGrid hazard={hazard} /> | ||
</Box> | ||
))} | ||
</ErrorBoundary> | ||
</SidePanel> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
|
||
import { | ||
pixelDrillerDataHeaders, | ||
pixelDrillerDataRows, | ||
pixelDrillerDataRPs, | ||
} from 'lib/state/pixel-driller'; | ||
import { useRecoilValue } from 'recoil'; | ||
|
||
import './hazard-table.css'; | ||
import { Typography } from '@mui/material'; | ||
|
||
const headings = { | ||
cyclone: 'Cyclones', | ||
fluvial: 'River flooding', | ||
surface: 'Surface flooding', | ||
coastal_mangrove: 'Coastal (mangrove)', | ||
coastal_nomangrove: 'Coastal (no mangrove)', | ||
coastal_nomangrove_minus_mangrove: 'Coastal (no mangrove - mangrove)', | ||
}; | ||
|
||
const displayReturnPeriods = new Set([10, 20, 50, 100, 200, 500]); | ||
|
||
export const PixelDataGrid = ({ hazard }) => { | ||
const headers = useRecoilValue(pixelDrillerDataHeaders); | ||
const rows = useRecoilValue(pixelDrillerDataRows(hazard)); | ||
const dataReturnPeriods = useRecoilValue(pixelDrillerDataRPs(hazard)); | ||
const columns = [ | ||
{ field: 'epoch', headerName: 'Epoch' }, | ||
{ field: 'rcp', headerName: 'RCP' }, | ||
]; | ||
const returnPeriods = displayReturnPeriods.intersection(dataReturnPeriods); | ||
|
||
returnPeriods.forEach((rp) => { | ||
columns.push({ field: `rp-${rp}`, headerName: `RP ${rp}` }); | ||
}); | ||
if (!headers.length) { | ||
return null; | ||
} | ||
const variable = rows[0].variable; | ||
const unit = rows[0].unit; | ||
|
||
return ( | ||
<> | ||
<Typography variant="subtitle2" component="h3"> | ||
{headings[hazard]}: {variable} ({unit}) | ||
</Typography> | ||
|
||
<DataGrid columns={columns} rows={rows} density="compact" /> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.MuiDataGrid-footerContainer { | ||
display: none; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.