generated from RENCI/react-starter
-
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.
Merge pull request #22 from RENCI/feature/dialog
Feature - Base and observation dialogs
- Loading branch information
Showing
7 changed files
with
197 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
import React, { Fragment } from 'react'; | ||
import { Map } from '@components/map'; | ||
import ObservationDialog from "@components/map/observation-dialog"; | ||
import { useLayers } from '@context'; | ||
import { Sidebar } from '@components/sidebar'; | ||
|
||
export const App = () => { | ||
return ( | ||
// install the selected observation list from the layer context | ||
const { | ||
selectedObservations | ||
} = useLayers(); | ||
|
||
return ( | ||
<Fragment> | ||
<Map/> | ||
<Sidebar /> | ||
</Fragment> | ||
); | ||
{ | ||
// for each observation selected | ||
selectedObservations.map (function (obs) { | ||
// render the observation | ||
return <ObservationDialog key={obs.station_name} obs={obs} />; | ||
}) | ||
} | ||
<Map /> | ||
<Sidebar /> | ||
</Fragment> | ||
); | ||
}; |
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,33 @@ | ||
import React, {Fragment} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import BaseFloatingDialog from "@utils/base-floating-dialog"; | ||
|
||
// define the properties of this component | ||
ObservationDialog.propTypes = { | ||
obs_data: PropTypes.object | ||
}; | ||
|
||
export default function ObservationDialog(obs_data) { | ||
// TODO: the url is put in here but it will eventually | ||
// return a graph using data from this url | ||
const graphObj = (url) => { | ||
return ( | ||
<Fragment> | ||
<div> | ||
{url} | ||
</div> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
// create an object for the base dialog | ||
const floaterArgs = {title: obs_data.obs.station_name, description: obs_data.obs.location_name, openDialogImmediately:true, "dialogObject": {...graphObj(obs_data.obs.csvurl)}}; | ||
|
||
// render the dialog. | ||
// the key here will be used to remove the dialog from the selected observation list when the dialog is closed | ||
return ( | ||
<Fragment> | ||
<BaseFloatingDialog {...floaterArgs} /> | ||
</Fragment> | ||
); | ||
}; |
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,104 @@ | ||
import React, {Fragment} from 'react'; | ||
import Draggable from 'react-draggable'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import Button from '@mui/material/Button'; | ||
import CssBaseline from '@mui/material/CssBaseline'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogActions'; | ||
import DialogContentText from '@mui/material/DialogContentText'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import Paper from '@mui/material/Paper'; | ||
import Slide from '@mui/material/Slide'; | ||
|
||
import { useLayers } from '@context'; | ||
|
||
// define the properties of this component | ||
BaseFloatingDialog.propTypes = { | ||
title: PropTypes.string, | ||
description: PropTypes.string, | ||
openDialogImmediately: PropTypes.bool, | ||
dialogObject: PropTypes.any | ||
}; | ||
|
||
/** | ||
* This is a component that displays a floating dialog with the content passed | ||
* | ||
* @param title: string | ||
* @param description: string | ||
* @param openDialogImmediately: boolean | ||
* @param dialogObject: {JSX.Element} | ||
* @returns {JSX.Element} | ||
*/ | ||
export default function BaseFloatingDialog({ title, description, openDialogImmediately, dialogObject} ) { | ||
// define the dialog open/close session state | ||
const [open, setOpen] = React.useState(openDialogImmediately); | ||
|
||
const { | ||
selectedObservations, | ||
setSelectedObservations | ||
} = useLayers(); | ||
|
||
/** | ||
* the close dialog handler | ||
*/ | ||
const handleClose = () => { | ||
// close the dialog | ||
setOpen(false); | ||
|
||
// remove this item from the selected observations list | ||
setSelectedObservations(selectedObservations.filter(item => item.station_name !== title)); | ||
}; | ||
|
||
/** | ||
* configure and render the floating dialog | ||
*/ | ||
return ( | ||
<Fragment> | ||
<CssBaseline /> | ||
<Dialog | ||
aria-labelledby="draggable-dialog-title" | ||
open={open} | ||
onClose={handleClose} | ||
PaperComponent={PaperComponent} | ||
TransitionComponent={Transition} | ||
disableEnforceFocus | ||
style={{ pointerEvents: 'none'}} | ||
PaperProps={{ style: { pointerEvents: 'auto'} }} | ||
sx={{ '.MuiBackdrop-root': { backgroundColor: 'transparent' }}} | ||
> | ||
<DialogTitle sx={{cursor: 'move', backgroundColor: 'lightgray', textAlign: 'center'}} id="draggable-dialog-title"> { "Station: " + title } </DialogTitle> | ||
|
||
<DialogContent sx={{backgroundColor: 'lightblue'}}><DialogContentText> { "Location: " + description } </DialogContentText></DialogContent> | ||
|
||
<DialogContent sx={{backgroundColor: 'lightgreen'}}>{ dialogObject }</DialogContent> | ||
|
||
<DialogActions sx={{backgroundColor: 'lightgray'}}><Button autoFocus onClick={handleClose}> Close </Button></DialogActions> | ||
</Dialog> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
/** | ||
* This creates a 3D dialog. | ||
* | ||
* @param props | ||
* @returns {JSX.Element} | ||
* @constructor | ||
*/ | ||
function PaperComponent(props) { | ||
return ( | ||
<Draggable handle="#draggable-dialog-title" cancel={'[class*="MuiDialogContent-root"]'}> | ||
<Paper {...props} /> | ||
</Draggable> | ||
); | ||
} | ||
|
||
/** | ||
* This creates an animated transition for the dialog that pops up | ||
* @type {React.ForwardRefExoticComponent<React.PropsWithoutRef<{}> & React.RefAttributes<any>>} | ||
*/ | ||
const Transition = React.forwardRef(function Transition(props, ref) { | ||
return <Slide direction="up" ref={ref} {...props} />; | ||
}); |