-
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
tweak(tupaiaWeb): RN-1420: Use dashboard codes in URLs #5884
Open
alexd-bes
wants to merge
10
commits into
dev
Choose a base branch
from
rn-1420-dashboard-code-urls
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d937dae
Initial working redirects
alexd-bes 914549a
Update RequestProjectAccessModal.tsx
alexd-bes 0ec4cbc
Fix default routes
alexd-bes da66d66
Remove unused code
alexd-bes 67b60f1
Remove unused vars
alexd-bes 4fba613
rename route
alexd-bes 132aca5
Merge branch 'dev' into rn-1420-dashboard-code-urls
alexd-bes b229613
Merge branch 'dev' into rn-1420-dashboard-code-urls
alexd-bes 0cc402a
Merge branch 'dev' into rn-1420-dashboard-code-urls
tcaiger 52931e3
Update Dashboard.tsx
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
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 |
---|---|---|
|
@@ -3,17 +3,17 @@ | |
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import React, { useState } from 'react'; | ||
import styled from 'styled-components'; | ||
import { useLocation, useNavigate, useParams } from 'react-router-dom'; | ||
import { useParams } from 'react-router-dom'; | ||
import { Typography } from '@material-ui/core'; | ||
import { DEFAULT_BOUNDS } from '@tupaia/ui-map-components'; | ||
import { ErrorBoundary, SpinningLoader } from '@tupaia/ui-components'; | ||
import { MatrixConfig } from '@tupaia/types'; | ||
import { MOBILE_BREAKPOINT } from '../../constants'; | ||
import { useDashboards, useEntity, useProject } from '../../api/queries'; | ||
import { DashboardItem as DashboardItemType } from '../../types'; | ||
import { gaEvent, getDefaultDashboard } from '../../utils'; | ||
import { gaEvent } from '../../utils'; | ||
import { DashboardItem } from '../DashboardItem'; | ||
import { EnlargedDashboardItem } from '../EnlargedDashboardItem'; | ||
import { ExpandButton } from './ExpandButton'; | ||
|
@@ -34,7 +34,9 @@ const Panel = styled.div<{ | |
}>` | ||
position: relative; | ||
background-color: ${({ theme }) => theme.palette.background.paper}; | ||
transition: width 0.3s ease, max-width 0.3s ease; | ||
transition: | ||
width 0.3s ease, | ||
max-width 0.3s ease; | ||
width: 100%; | ||
overflow: visible; | ||
min-height: 100%; | ||
|
@@ -106,54 +108,21 @@ const DashboardItemsWrapper = styled.div<{ | |
`; | ||
|
||
export const Dashboard = () => { | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
const { projectCode, entityCode } = useParams(); | ||
const { data: project, isLoading: isLoadingProject } = useProject(projectCode); | ||
const { data: project } = useProject(projectCode); | ||
|
||
const { activeDashboard } = useDashboard(); | ||
const { | ||
data: dashboards, | ||
isLoading: isLoadingDashboards, | ||
isError, | ||
isFetched, | ||
} = useDashboards(projectCode, entityCode); | ||
const { isLoading: isLoadingDashboards } = useDashboards(projectCode, entityCode); | ||
const [isExpanded, setIsExpanded] = useState(false); | ||
|
||
const { data: entity } = useEntity(projectCode, entityCode); | ||
const bounds = entity?.bounds || DEFAULT_BOUNDS; | ||
|
||
// we don't want useEntityLink to take care of this because useEntityLink gets called for all child entities on the map, meaning lots of extra queries when we don't need them. Instead the redirect will be taken care of in the useEffect below, as needed | ||
const defaultDashboardName = getDefaultDashboard( | ||
project, | ||
dashboards, | ||
isLoadingDashboards, | ||
isError, | ||
); | ||
|
||
const toggleExpanded = () => { | ||
setIsExpanded(!isExpanded); | ||
gaEvent('Pages', 'Toggle Info Panel'); | ||
}; | ||
|
||
// check for valid dashboard name, and if not valid and not still loading, redirect to default dashboard | ||
const dashboardNotFound = | ||
isFetched && | ||
!isError && | ||
!isLoadingDashboards && | ||
!isLoadingProject && | ||
project?.code === projectCode && | ||
!activeDashboard; | ||
|
||
useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bonus to replace this but of code I reckon |
||
if (dashboardNotFound) { | ||
navigate({ | ||
...location, | ||
pathname: `/${projectCode}/${entityCode}/${defaultDashboardName}`, | ||
}); | ||
} | ||
}, [dashboardNotFound, defaultDashboardName]); | ||
|
||
// Filter out drill down items from the dashboard items | ||
const visibleDashboards = | ||
(activeDashboard?.items as DashboardItemType[])?.reduce( | ||
|
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
Oops, something went wrong.
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.
This is pretty minor but I was initially confused by the naming of DashboardNameToCodeRedirect as I didn't realise that it included the Dashboard component. Maybe it should be just called DashboardRoute or DashboardCodeRoute or something?