-
Notifications
You must be signed in to change notification settings - Fork 7
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 #4655 from beyondessential/waitp-1287-dashboard-dr…
…opdown WAITP-1287: Dashboard dropdown
- Loading branch information
Showing
14 changed files
with
179 additions
and
49 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
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,24 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import { useQuery } from 'react-query'; | ||
import { Dashboard } from '@tupaia/types'; | ||
import { get } from '../api'; | ||
|
||
type DashboardRecord = Dashboard & { | ||
items: { childId: string }[]; | ||
}; | ||
|
||
type DashboardsResponse = DashboardRecord[]; | ||
export const useDashboards = (projectCode?: string, entityCode?: string) => { | ||
return useQuery( | ||
['dashboards', projectCode, entityCode], | ||
async (): Promise<DashboardsResponse> => { | ||
return await get('dashboards', { | ||
params: { entityCode, projectCode }, | ||
}); | ||
}, | ||
{ enabled: !!entityCode && !!projectCode }, | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
|
||
export const TRANSPARENT_BLACK = 'rgba(43, 45, 56, 0.94)'; | ||
|
||
export const FORM_COLORS = { | ||
BORDER: '#d9d9d9', | ||
}; |
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 |
---|---|---|
|
@@ -13,4 +13,5 @@ export const Breadcrumbs = styled.div` | |
max-width: 220px; | ||
background: #efefefaa; | ||
height: 15px; | ||
z-index: 1; | ||
`; |
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,82 @@ | ||
/* | ||
* Tupaia | ||
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
import React, { useState } from 'react'; | ||
import { useLocation, Link, useParams } from 'react-router-dom'; | ||
import ArrowDropDownIcon from '@material-ui/icons/ArrowDropDown'; | ||
import { ButtonBase, Menu, MenuItem } from '@material-ui/core'; | ||
import { Dashboard } from '@tupaia/types'; | ||
import styled from 'styled-components'; | ||
import { useDashboards } from '../../api/queries'; | ||
import { DashboardCode } from '../../types'; | ||
|
||
const MenuButton = styled(ButtonBase)` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
background-color: ${({ theme }) => theme.panel.secondaryBackground}; | ||
width: 100%; | ||
padding: 1rem; | ||
font-size: 1rem; | ||
`; | ||
|
||
interface DashboardMenuItemProps { | ||
dashboardName: Dashboard['name']; | ||
dashboardCode: DashboardCode; | ||
onClose: () => void; | ||
} | ||
|
||
const DashboardMenuItem = ({ dashboardName, dashboardCode, onClose }: DashboardMenuItemProps) => { | ||
const location = useLocation(); | ||
const { projectCode, entityCode } = useParams(); | ||
|
||
const link = { ...location, pathname: `/${projectCode}/${entityCode}/${dashboardCode}` }; | ||
|
||
return ( | ||
<MenuItem to={link} onClick={onClose} component={Link}> | ||
{dashboardName} | ||
</MenuItem> | ||
); | ||
}; | ||
|
||
export const DashboardMenu = () => { | ||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
const { projectCode, entityCode, '*': dashboardCode } = useParams(); | ||
const { data: dashboards } = useDashboards(projectCode, entityCode); | ||
|
||
const handleClickListItem = (event: React.MouseEvent<HTMLElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const selectedOption = dashboards?.find(({ code }) => code === dashboardCode); | ||
|
||
return ( | ||
<> | ||
<MenuButton onClick={handleClickListItem}> | ||
{selectedOption?.name} | ||
<ArrowDropDownIcon /> | ||
</MenuButton> | ||
<Menu | ||
id="dashboards-menu" | ||
anchorEl={anchorEl} | ||
open={Boolean(anchorEl)} | ||
onClose={handleClose} | ||
variant="menu" | ||
> | ||
{dashboards?.map(({ name, code }) => ( | ||
<DashboardMenuItem | ||
key={code} | ||
dashboardName={name} | ||
dashboardCode={code} | ||
onClose={handleClose} | ||
/> | ||
))} | ||
</Menu> | ||
</> | ||
); | ||
}; |
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
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
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