Skip to content

Commit

Permalink
trying to resync with main
Browse files Browse the repository at this point in the history
  • Loading branch information
PhillipsOwen committed May 7, 2024
1 parent 2ed09ec commit bd53023
Show file tree
Hide file tree
Showing 15 changed files with 578 additions and 25 deletions.
25 changes: 25 additions & 0 deletions src/components/buttons/action-button-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import { Sheet, Stack } from '@mui/joy';
import PropTypes from 'prop-types';

export const ActionButtonMenu = ({ children }) => {
return (
<Sheet
component={ Stack }
direction="row"
justifyContent="flex-end"
gap={ 1 }
className="action-button-menu"
sx={{
p: 1,
backgroundColor: 'background.surface',
}}
>
{ children }
</Sheet>
);
};

ActionButtonMenu.propTypes = {
children: PropTypes.node.isRequired,
};
23 changes: 23 additions & 0 deletions src/components/buttons/action-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import PropTypes from 'prop-types';
import { IconButton } from '@mui/joy';

export const ActionButton = ({
children,
...props
}) => {
return (
<IconButton
size="sm"
variant="soft"
className="action-button"
{ ...props }
>
{ children }
</IconButton>
);
};

ActionButton.propTypes = {
children: PropTypes.node,
};
2 changes: 2 additions & 0 deletions src/components/buttons/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './action-button';
export * from './action-button-menu';
6 changes: 3 additions & 3 deletions src/components/dialog/base-floating-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export default function BaseFloatingDialog({ title, dialogObject, dataKey, dataL
TransitionComponent={Transition}
disableEnforceFocus
style={{ pointerEvents: 'none' }}
PaperProps={{ sx: { width: 750, height: 510, pointerEvents: 'auto'} }}
sx={{ width: 750, height: 510, '.MuiBackdrop-root': { backgroundColor: 'transparent' }}}
PaperProps={{ sx: { width: 625, height: 510, pointerEvents: 'auto'} }}
sx={{ width: 625, height: 510, '.MuiBackdrop-root': { backgroundColor: 'transparent' }}}
>
<DialogTitle sx={{cursor: 'move', backgroundColor: 'lightblue', textAlign: 'center', fontSize: 14, height: 35, m: 0, p: 1 }} id="draggable-dialog-title"> { title } </DialogTitle>

<DialogContent sx={{backgroundColor: 'white', fontSize: 14, height: 375 }}>{ dialogObject }</DialogContent>
<DialogContent sx={{backgroundColor: 'white', fontSize: 14, m: 0, width: 500, height: 375 }}>{ dialogObject }</DialogContent>

<DialogActions sx={{backgroundColor: 'lightgray', height: 35, m: 0, p: 1}}><Button style={{fontSize: 14}} autoFocus onClick={handleClose}> Close </Button></DialogActions>
</Dialog>
Expand Down
16 changes: 10 additions & 6 deletions src/components/map/map.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';
import { MapContainer, TileLayer } from 'react-leaflet';
import { DefaultLayers } from './default-layers';
import { useLayers } from '@context';
import {
useLayers,
useSettings,
} from '@context';
import 'leaflet/dist/leaflet.css';

const DEFAULT_CENTER = [30.0, -73.0];

export const Map = () => {
const { darkMode } = useSettings();
const {
setMap
} = useLayers();
Expand All @@ -17,12 +21,12 @@ export const Map = () => {
zoom={5}
zoomControl={false}
scrollWheelZoom={true}
ref={setMap}
whenCreated={setMap}
style={{ height: '100vh', width:'100wh' }}>
<TileLayer
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/>
{ darkMode.enabled
? <TileLayer url={ `https://api.mapbox.com/styles/v1/mvvatson/clvu3inqs05v901qlabcfhxsr/tiles/256/{z}/{x}/{y}@2x?access_token=${ process.env.REACT_APP_MAPBOX_TOKEN }` } />
: <TileLayer url={ `https://api.mapbox.com/styles/v1/mvvatson/clvu2u7iu061901ph15n55v2e/tiles/256/{z}/{x}/{y}@2x?access_token=${ process.env.REACT_APP_MAPBOX_TOKEN }` } />
}
<DefaultLayers/>
</MapContainer>
);
Expand Down
10 changes: 7 additions & 3 deletions src/components/sidebar/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Fragment, useCallback, useState } from 'react';
import {
List,
Sheet,
useTheme,
} from '@mui/joy';
import { Tray } from './tray';
import { MenuItem } from './menu-item';
import SidebarTrays from '../trays';

export const Sidebar = () => {
const [activeIndex, setActiveIndex] = useState(-1);
const theme = useTheme();
const [activeIndex, setActiveIndex] = useState(0);

const handleClickMenuItem = useCallback(newIndex => {
// if the incoming new index equals the old index,
Expand All @@ -34,13 +36,15 @@ export const Sidebar = () => {
maxWidth: '68px',
overflow: 'hidden',
p: 0,
backgroundColor: activeIndex === -1 ? '#f0f4f899' : '#f0f4f8',
backgroundColor: activeIndex === -1
? `rgba(${ theme.palette.mainChannel } / 0.2)`
: `rgba(${ theme.palette.mainChannel } / 1.0)`,
// a drop shadow looks nice. we'll remove it if a tray is open,
// as they should appear on the same plane.
filter: activeIndex === -1 ? 'drop-shadow(0 0 8px rgba(0, 0, 0, 0.2))' : 'drop-shadow(1px 0 0 rgba(0, 0, 0, 0.2))',
// similarly, here.
'&:hover': {
backgroundColor: '#f0f4f8',
backgroundColor: `rgba(${ theme.palette.mainChannel } / 1.0)`,
transition: 'max-width 250ms, filter 250ms, background-color 150ms',
},
// we'll add a delay to this exit animation to give ample time
Expand Down
4 changes: 3 additions & 1 deletion src/components/sidebar/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
KeyboardDoubleArrowLeft as CloseTrayIcon,
} from '@mui/icons-material';

const TRAY_WIDTH = '500px';

export const Tray = ({ active, Contents, title, closeHandler }) => {
return (
<Sheet
Expand All @@ -23,7 +25,7 @@ export const Tray = ({ active, Contents, title, closeHandler }) => {
transform: active ? 'translateX(0)' : 'translateX(-120%)',
transition: 'transform 250ms',
height: '100vh',
width: '450px',
width: TRAY_WIDTH,
zIndex: 998,
filter: 'drop-shadow(0 0 8px rgba(0, 0, 0, 0.2))',
overflowX: 'hidden',
Expand Down
46 changes: 46 additions & 0 deletions src/components/trays/layers/layer-card-actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Divider } from '@mui/joy';
import {
DeleteForever as RemoveIcon,
Opacity as OpacityIcon,
Palette as ColorRampIcon,
DataObject as RawDataIcon,
} from '@mui/icons-material';
import { useLayers } from '@context';
import { ActionButton } from '@components/buttons';
import { ActionButtonMenu } from '@components/buttons';

export const LayerActions = ({ layerId = 0 }) => {
const { removeLayer } = useLayers();

return (
<ActionButtonMenu>
<ActionButton disabled>
<RawDataIcon />
</ActionButton>

<ActionButton disabled>
<OpacityIcon />
</ActionButton>

<ActionButton disabled>
<ColorRampIcon />
</ActionButton>

<Divider orientation="vertical" />

<ActionButton
variant="solid"
color="warning"
onClick={ () => removeLayer(layerId) }
>
<RemoveIcon />
</ActionButton>
</ActionButtonMenu>
);
};

LayerActions.propTypes = {
layerId: PropTypes.string.isRequired,
};
157 changes: 157 additions & 0 deletions src/components/trays/layers/layer-card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
Accordion,
AccordionDetails,
Avatar,
Box,
ButtonGroup,
Stack,
Switch,
Typography,
} from '@mui/joy';
import {
KeyboardArrowDown as ExpandIcon,
ArrowDropUp as MoveUpArrow,
ArrowDropDown as MoveDownArrow,
Schedule as ClockIcon,
} from '@mui/icons-material';
import { useLayers } from '@context';
import { useToggleState } from '@hooks';
import { LayerActions } from './layer-card-actions';
import { ActionButton } from '@components/buttons';

export const LayerCard = ({ index, layer }) => {
const {
layerTypes,
swapLayers,
toggleLayerVisibility,
} = useLayers();
const expanded = useToggleState(false);
const isVisible = layer.state.visible;
const LayerIcon = layerTypes[layer.properties.product_type].icon;

return (
<Accordion
expanded={ expanded.enabled }
onChange={ expanded.toggle }
sx={{ p: 0 }}
>
{/*
the usual AccordionSummary component results in a button,
but we want some buttons _inside_ the accordion summary,
so we'll build a custom component here.
*/}
<Stack
direction="row"
gap={ 1 }
sx={{
p: 1,
borderLeft: '6px solid',
// borderLeftColor: isVisible
// ? `rgba(${ theme.palette.primary.mainChannel }) / 1.0`
// : `rgba(${ theme.palette.primary.mainChannel }) / 0.2`,
borderLeftColor: isVisible
? `primary.plainColor`
: `primary.plainDisabledColor`,
'.action-button': { filter: 'opacity(0.1)', transition: 'filter 250ms' },
'&:hover .action-button': { filter: 'opacity(0.5)' },
'& .action-button:hover': { filter: 'opacity(1.0)' },
}}
>
<Stack direction="column" sx={{ flex: 1 }}>
<Stack direction="row" alignItems="center" gap={ 2 } sx={{
filter: isVisible ? 'opacity(1.0)' : 'opacity(0.75)',
transition: 'filter 250ms',
}}>
<Avatar variant="outlined">
<LayerIcon size="lg" color="primary" />
</Avatar>
<Typography level="title-md">
{layerTypes[layer.properties.product_type].name}
</Typography>
<Switch
size="sm"
checked={ isVisible }
onChange={ () => toggleLayerVisibility(layer.id) }
className="action-button"
/>
</Stack>

<Stack
direction="row"
justifyContent="space-between"
alignItems="stretch"
gap={ 2 }
sx={{ flex: 1, pl: '50px' }}
>
<Typography level="body-sm" sx={{ display: 'inline-flex', alignItems: 'center' }}>
<ClockIcon sx={{ transform: 'scale(0.66)' }} /> { new Date(layer.properties.run_date).toLocaleString() }
</Typography>
<Typography level="body-xs" sx={{ display: 'inline-flex', alignItems: 'center' }}>
Cycle { layer.properties.cycle }
</Typography>
</Stack>
</Stack>

<ButtonGroup
size="sm"
orientation="vertical"
sx={{
transform: 'scaleX(0.75)',
'.MuiActionButton-root': { flex: 1 }
}}
>
<ActionButton
variant="outlined"
onClick={ () => swapLayers(index, index - 1) }
><MoveUpArrow /></ActionButton>
<ActionButton
variant="outlined"
onClick={ () => swapLayers(index, index + 1) }
><MoveDownArrow /></ActionButton>
</ButtonGroup>

<ActionButton
onClick={ expanded.toggle }
>
<ExpandIcon
fontSize="sm"
sx={{
transform: expanded.enabled ? 'rotate(180deg)' : 'rotate(0)',
transition: 'transform 100ms',
}}
/>
</ActionButton>
</Stack>
<AccordionDetails sx={{
backgroundColor: 'background.surface',
position: 'relative',
// remove default margin that doesn't work well in our situation.
marginInline: 0,
'.MuiAccordionDetails-content': {
paddingInline: 0,
paddingBlock: 0,
},
}}>
<LayerActions layerId={ layer.id } />
<Box component="pre" sx={{
fontSize: '75%',
color: 'text.primary',
backgroundColor: 'transparent',
overflowX: 'auto',
p: 1,
}}>
{ JSON.stringify(layer.properties, null, 2) }
</Box>
</AccordionDetails>
</Accordion>

);
};

LayerCard.propTypes = {
index: PropTypes.number.isRequired,
layer: PropTypes.object.isRequired,
};

Loading

0 comments on commit bd53023

Please sign in to comment.