-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WAITP-1287: Dashboard dropdown #4655
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9a3135e
setup dashboards fetch
tcaiger 23b0206
build dashboard dropdown
tcaiger 16c0214
types
tcaiger 17dd14b
move state to url
tcaiger 6a67b36
refactor dropdown menu
tcaiger cf764eb
Update Sidebar.tsx
tcaiger bfe5e8e
move camel case keys to server
tcaiger 65afea4
add theme color
tcaiger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A dashboard attached to an entity can also appear on any of that entity's children (depending on the existence of dashboard items which are usually specific to entity types) which is why I was checking against ancestors.
This route handler needs another fix-up pass anyway so I'm happy to pick that up in a separate PR