Skip to content

Commit 12ea744

Browse files
Merge pull request #1183 from topcoder-platform/pm-1503
feat(PM-1503): Route modifications in scorecard
2 parents d978668 + 6480aba commit 12ea744

File tree

12 files changed

+78
-4
lines changed

12 files changed

+78
-4
lines changed

src/apps/review/src/config/routes.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export const openOpportunitiesRouteId = 'open-opportunities'
1313
export const pastReviewAssignmentsRouteId = 'past-review-assignments'
1414
export const challengeDetailRouteId = ':challengeId'
1515
export const scorecardRouteId = 'scorecard'
16+
export const viewScorecardRouteId = ':scorecardId'

src/apps/review/src/lib/components/TableScorecards/TableScorecards.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const TableScorecards: FC<Props> = (props: Props) => {
4545
label: 'Scorecard',
4646
propertyName: 'name',
4747
renderer: (data: Scorecard) => (
48-
<Link to={`${data.id}/details`}>
48+
<Link to={`${data.id}`}>
4949
{data.name}
5050
</Link>
5151
),
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* The router outlet.
3+
*/
4+
5+
import { FC, PropsWithChildren, useContext, useEffect, useMemo } from 'react'
6+
import { Outlet, Routes, useLocation } from 'react-router-dom'
7+
8+
import { routerContext, RouterContextData } from '~/libs/core'
9+
10+
import { reviewRoutes } from '../../review-app.routes'
11+
import { scorecardRouteId } from '../../config/routes.config'
12+
13+
export const ScorecardsContainer: FC<PropsWithChildren> = () => {
14+
const location = useLocation()
15+
const childRoutes = useChildRoutes()
16+
17+
useEffect(() => {
18+
window.scrollTo(0, 0)
19+
}, [location.pathname])
20+
21+
return (
22+
<>
23+
<Outlet />
24+
<Routes>{childRoutes}</Routes>
25+
</>
26+
)
27+
}
28+
29+
function useChildRoutes(): Array<JSX.Element> | undefined {
30+
const { getRouteElement }: RouterContextData = useContext(routerContext)
31+
const childRoutes = useMemo(
32+
() => reviewRoutes[0].children
33+
?.find(r => r.id === scorecardRouteId)
34+
?.children?.map(getRouteElement),
35+
[getRouteElement],
36+
)
37+
return childRoutes
38+
}
39+
40+
export default ScorecardsContainer

src/apps/review/src/pages/scorecards/ScorecardsListPage.tsx renamed to src/apps/review/src/pages/scorecards/ScorecardsListPage/ScorecardsListPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { FC, useCallback, useMemo, useState } from 'react'
33
import { PageTitle } from '~/libs/ui'
44
import { TableLoading } from '~/apps/admin/src/lib'
55

6-
import { PageWrapper, ScorecardsFilter, TableNoRecord, TableScorecards } from '../../lib'
7-
import { ScorecardsResponse, useFetchScorecards } from '../../lib/hooks'
6+
import { PageWrapper, ScorecardsFilter, TableNoRecord, TableScorecards } from '../../../lib'
7+
import { ScorecardsResponse, useFetchScorecards } from '../../../lib/hooks'
88

99
import styles from './ScorecardsListPage.module.scss'
1010

src/apps/review/src/pages/scorecards/ViewScorecardPage/ViewScorecardPage.module.scss

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { FC } from 'react'
2+
3+
const ViewScorecardPage: FC = () => (
4+
<div>View scorecard</div>
5+
)
6+
7+
export default ViewScorecardPage
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ViewScorecardPage } from './ViewScorecardPage'

src/apps/review/src/review-app.routes.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,21 @@ const ScorecardDetailsPage: LazyLoadedComponent = lazyLoad(
3737
'ScorecardDetailsPage',
3838
)
3939

40+
const ScorecardsContainer: LazyLoadedComponent = lazyLoad(
41+
() => import('./pages/scorecards/ScorecardsContainer'),
42+
'ScorecardsContainer',
43+
)
44+
4045
const ScorecardsListPage: LazyLoadedComponent = lazyLoad(
4146
() => import('./pages/scorecards/ScorecardsListPage'),
4247
'ScorecardsListPage',
4348
)
4449

50+
const ViewScorecardPage: LazyLoadedComponent = lazyLoad(
51+
() => import('./pages/scorecards/ViewScorecardPage'),
52+
'ViewScorecardPage',
53+
)
54+
4555
export const toolTitle: string = ToolTitle.review
4656

4757
export const reviewRoutes: ReadonlyArray<PlatformRoute> = [
@@ -85,7 +95,20 @@ export const reviewRoutes: ReadonlyArray<PlatformRoute> = [
8595
route: activeReviewAssigmentsRouteId,
8696
},
8797
{
88-
element: <ScorecardsListPage />,
98+
children: [
99+
{
100+
element: <ScorecardsListPage />,
101+
id: 'list-scorecards-page',
102+
route: '',
103+
},
104+
{
105+
element: <ViewScorecardPage />,
106+
id: 'view-scorecard-page',
107+
route: ':scorecardId',
108+
},
109+
110+
],
111+
element: <ScorecardsContainer />,
89112
id: scorecardRouteId,
90113
route: scorecardRouteId,
91114
},

0 commit comments

Comments
 (0)