Skip to content

Commit

Permalink
Merge branch 'main' into ft/climatemapped-visualisation-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinkipruto committed Oct 23, 2024
2 parents 79b13a1 + 736d0f3 commit c60ddaf
Show file tree
Hide file tree
Showing 29 changed files with 705 additions and 654 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function ExplorePage({ panelProps, profile: profileProp, apiUri, ...props }) {
position: "absolute",
right: 0,
top: theme.typography.pxToRem(52),
zIndex: theme.zIndex.appBar,
zIndex: theme.zIndex.appBar - 1,
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { Box, Drawer } from "@mui/material";
import { useTour } from "@reactour/tour";
import PropTypes from "prop-types";
import React, { useCallback, useState } from "react";

import PanelButtons from "./PanelButtons";
import PanelItem from "./PanelItem";

function DesktopPanel({ sx, ...props }) {
const [value, setValue] = useState();
const { isOpen: tutorialOpen } = useTour();

const closeDrawer = () => {
setValue(undefined);
};
const handleValueChange = useCallback((newValue) => {
// toggle value if the same
setValue((oldValue) => (oldValue !== newValue ? newValue : undefined));
}, []);

const open = value === "rich-data" && !tutorialOpen;
return (
<Box sx={sx}>
<Drawer
// variant="persistent"
anchor="left"
onClose={closeDrawer}
open={open}
sx={({ typography }) => ({
display: "flex",
height: "100%",
minWidth: typography.pxToRem(1050),
maxWidth: "max-content",
overflowY: "visible",
position: "relative",
})}
// This needs to match panel button open/close duration
transitionDuration={200}
ModalProps={{
sx: {
overflowY: "scroll",
overscrollBehaviorBlock: "none",
top: 104, // Toolbar height
},
}}
PaperProps={{
elevation: 0,
square: true,
sx: {
background: "transparent",
border: "none",
display: "flex",
flexDirection: "row",
height: "100%",
overflowY: "visible",
position: "absolute",
},
}}
>
<Box
sx={{
display: "flex",
height: "100%",
}}
>
<PanelItem {...props} item={{ value: "rich-data" }} />
</Box>
</Drawer>
<PanelButtons
{...props}
onValueChange={handleValueChange}
open={open}
value={value}
/>
</Box>
);
}

DesktopPanel.propTypes = {
isCompare: PropTypes.bool,
isPinning: PropTypes.bool,
onClickPin: PropTypes.func,
onClickUnpin: PropTypes.func,
panelItems: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.string,
children: PropTypes.node,
tree: PropTypes.shape({}),
}),
),
primaryProfile: PropTypes.shape({
items: PropTypes.arrayOf(PropTypes.shape({})),
}),
};

export default DesktopPanel;
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
import { useTour } from "@reactour/tour";
import clsx from "clsx";
import PropTypes from "prop-types";
import React, { useEffect, useState } from "react";

import useStyles from "./useStyles";

import PanelButtonGroup from "@/climatemappedafrica/components/HURUmap/PanelButtonGroup";

function PanelButtons({
isPinning,
isCompare,
onClickPin,
onClickUnpin,
onValueChange,
open,
panelItems: panelItemsProp,
primaryProfile,
secondaryProfile,
drawerRef,
...props
value,
}) {
const [value, setValue] = useState();
const [pins, setPins] = useState([]);
const [panelItems, setPanelItems] = useState([]);
const classes = useStyles({ ...props });
const { isOpen: tutorialOpen } = useTour();

useEffect(() => {
if (primaryProfile.items.length || secondaryProfile?.items?.length) {
const timeoutId = setTimeout(() => setValue("rich-data"), 200);
if (
(primaryProfile.items.length || secondaryProfile?.items?.length) &&
onValueChange
) {
const timeoutId = setTimeout(() => onValueChange("rich-data"), 200);
return () => {
clearTimeout(timeoutId);
};
}
// useEffect requires a return statement
return () => {};
}, [primaryProfile.items, secondaryProfile?.items]);
}, [onValueChange, primaryProfile.items, secondaryProfile?.items]);

useEffect(() => {
const pItems =
Expand Down Expand Up @@ -86,13 +82,14 @@ function PanelButtons({
}
}, [isPinning, isCompare]);

if (!panelItems?.length) {
return null;
}

const isPin = (current) => {
const found = panelItems.find((item) => item.value === current);
return !!found?.pin;
};
if (!panelItems?.length) {
return null;
}

function addOrRemovePin(array, pin) {
const newArray = [...array];
Expand All @@ -118,44 +115,44 @@ function PanelButtons({
setPins([]);
}

setValue(nextValue);
if (onValueChange) {
onValueChange(nextValue);
}
};

const open = value === "rich-data" && !tutorialOpen;
/* eslint-disable no-param-reassign */
if (open) {
drawerRef.current.style.visibility = "visible";
} else {
drawerRef.current.style.visibility = "hidden";
}

return (
<PanelButtonGroup
onChange={handleChange}
items={panelItems}
value={open ? value : undefined}
value={value}
pins={pins}
classes={{
root: clsx(classes.panelButtons, {
[classes.panelButtonsOpen]: open,
sx={[
({ typography, transitions, zIndex }) => ({
marginTop: typography.pxToRem(52),
width: typography.pxToRem(44),
position: "fixed",
left: 0,
zIndex: zIndex.drawer + 1,
transition: transitions.create(["left"], {
duration: transitions.duration.shorter, // average-ish of entering & leaving screen
}),
}),
}}
({ widths }) =>
open && {
left: `max(calc((100vw - ${widths.values.lg}px)/2 + 833px),1100px)`,
},
]}
/>
);
}

PanelButtons.propTypes = {
drawerRef: PropTypes.shape({
current: PropTypes.shape({
style: PropTypes.shape({
visibility: PropTypes.string,
}),
}),
}),
isCompare: PropTypes.bool,
isPinning: PropTypes.bool,
onClickPin: PropTypes.func,
onClickUnpin: PropTypes.func,
onValueChange: PropTypes.func,
open: PropTypes.bool,
panelItems: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.string,
Expand All @@ -169,6 +166,7 @@ PanelButtons.propTypes = {
secondaryProfile: PropTypes.shape({
items: PropTypes.arrayOf(PropTypes.shape({})),
}),
value: PropTypes.string,
};

export default PanelButtons;
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Paper } from "@mui/material";
import PropTypes from "prop-types";
import React, { useRef } from "react";

Expand All @@ -15,7 +16,17 @@ function RichData({ primaryProfile, ...props }) {
};

return (
<>
<Paper
elevation={0}
square
sx={({ palette }) => ({
bgcolor: "background.paper",
border: `1px solid ${palette.grey.main}`,
borderLeft: "none",
borderRight: "none",
scrollMargin: "40px",
})}
>
<TreeView
items={primaryProfile.items}
onLabelClick={handleLabelClick}
Expand All @@ -24,7 +35,7 @@ function RichData({ primaryProfile, ...props }) {
minWidth: theme.typography.pxToRem(300),
paddingTop: theme.typography.pxToRem(76),
flexShrink: 0,
top: theme.typography.pxToRem(110),
top: theme.typography.pxToRem(104),
bottom: 0,
position: "fixed",
left: 0,
Expand All @@ -34,9 +45,10 @@ function RichData({ primaryProfile, ...props }) {
{...props}
categories={primaryProfile.items}
primaryProfile={primaryProfile}
sx={{}}
ref={profileRef}
/>
</>
</Paper>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,3 @@
import { Drawer } from "@mui/material";
import PropTypes from "prop-types";
import React, { useRef } from "react";

import PanelButtons from "./PanelButtons";
import PanelItem from "./PanelItem";
import useStyles from "./useStyles";

function DesktopPanel(props) {
const classes = useStyles(props);
const paperRef = useRef();

return (
<>
<Drawer
variant="permanent"
anchor="left"
open
classes={{
root: classes.root,
paper: classes.paper,
}}
PaperProps={{ ref: paperRef }}
>
<div className={classes.tabPanel}>
<PanelItem {...props} item={{ value: "rich-data" }} />
</div>
</Drawer>
<PanelButtons {...props} drawerRef={paperRef} />
</>
);
}

DesktopPanel.propTypes = {
isCompare: PropTypes.bool,
isPinning: PropTypes.bool,
onClickPin: PropTypes.func,
onClickUnpin: PropTypes.func,
panelItems: PropTypes.arrayOf(
PropTypes.shape({
value: PropTypes.string,
children: PropTypes.node,
tree: PropTypes.shape({}),
}),
),
primaryProfile: PropTypes.shape({
items: PropTypes.arrayOf(PropTypes.shape({})),
}),
};
import DesktopPanel from "./DesktopPanel";

export default DesktopPanel;

This file was deleted.

Loading

0 comments on commit c60ddaf

Please sign in to comment.