Skip to content

Commit 4422d9b

Browse files
authored
Merge pull request #1218 from topcoder-platform/PM-1504_edit-create-scorecard
PM-1504 edit create scorecard - sort scorecard data by sortOrder
2 parents 95cf7a2 + 1ae2533 commit 4422d9b

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

src/apps/review/src/lib/hooks/useFetchScorecard.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { toast } from 'react-toastify'
2+
import { sortBy } from 'lodash'
23
import useSWR, { SWRResponse } from 'swr'
34

45
import { EnvironmentConfig } from '~/config'
@@ -38,6 +39,15 @@ export function useFetchScorecard(id: string | undefined, shouldRetry: boolean):
3839
return {
3940
error,
4041
isValidating,
41-
scorecard: data,
42+
scorecard: data ? {
43+
...data,
44+
scorecardGroups: sortBy(data.scorecardGroups.map(group => ({
45+
...group,
46+
sections: sortBy(group.sections.map(section => ({
47+
...section,
48+
questions: sortBy(section.questions, 'sortOrder'),
49+
})), 'sortOrder'),
50+
})), 'sortOrder'),
51+
} : data,
4252
}
4353
}

src/apps/review/src/pages/scorecards/EditScorecardPage/EditScorecardPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ const EditScorecardPage: FC = () => {
5555
try {
5656
const response = await saveScorecard(value)
5757
toast.info('Scorecard saved successfully!')
58-
if (response.id && !params.scorecardId) {
59-
navigate(`${rootRoute}/scorecard/${response.id}`)
58+
if (response.id || value.id) {
59+
navigate(`${rootRoute}/scorecard/${response.id || value.id}`)
6060
}
6161
} catch (e: any) {
6262
toast.error(`Couldn't save scorecard! ${e.message}`)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,18 @@ export const reviewRoutes: ReadonlyArray<PlatformRoute> = [
113113
authRequired: true,
114114
element: <EditScorecardPage />,
115115
id: 'edit-scorecard-page',
116+
rolesRequired: [
117+
UserRole.administrator,
118+
],
116119
route: ':scorecardId/edit',
117120
},
118121
{
119122
authRequired: true,
120123
element: <EditScorecardPage />,
121124
id: 'new-scorecard-page',
125+
rolesRequired: [
126+
UserRole.administrator,
127+
],
122128
route: 'new',
123129
},
124130
{

0 commit comments

Comments
 (0)