diff --git a/src/commons/application/ApplicationTypes.ts b/src/commons/application/ApplicationTypes.ts index e6c4978ba3..10a3ab8877 100644 --- a/src/commons/application/ApplicationTypes.ts +++ b/src/commons/application/ApplicationTypes.ts @@ -498,7 +498,6 @@ export const defaultSession: SessionState = { collectibles: {} }, xp: 0, - allUserXp: undefined, story: { story: '', playStory: false diff --git a/src/commons/application/actions/SessionActions.ts b/src/commons/application/actions/SessionActions.ts index 239016cd62..ea2dfbd624 100644 --- a/src/commons/application/actions/SessionActions.ts +++ b/src/commons/application/actions/SessionActions.ts @@ -22,7 +22,6 @@ import { DELETE_TIME_OPTIONS, DELETE_USER_COURSE_REGISTRATION, FETCH_ADMIN_PANEL_COURSE_REGISTRATIONS, - FETCH_ALL_USER_XP, FETCH_ASSESSMENT, FETCH_ASSESSMENT_ADMIN, FETCH_ASSESSMENT_CONFIGS, @@ -65,7 +64,6 @@ import { TimeOption, Tokens, UNSUBMIT_SUBMISSION, - UPDATE_ALL_USER_XP, UPDATE_ASSESSMENT, UPDATE_ASSESSMENT_CONFIGS, UPDATE_ASSESSMENT_OVERVIEWS, @@ -103,8 +101,6 @@ export const fetchTotalXp = () => action(FETCH_TOTAL_XP); export const fetchTotalXpAdmin = (courseRegId: number) => action(FETCH_TOTAL_XP_ADMIN, courseRegId); -export const fetchAllUserXp = () => action(FETCH_ALL_USER_XP); - export const fetchGrading = (submissionId: number) => action(FETCH_GRADING, submissionId); /** @@ -209,8 +205,6 @@ export const updateAssessmentOverviews = (overviews: AssessmentOverview[]) => export const updateTotalXp = (totalXp: number) => action(UPDATE_TOTAL_XP, totalXp); -export const updateAllUserXp = (allUserXp: string[][]) => action(UPDATE_ALL_USER_XP, allUserXp); - export const updateAssessment = (assessment: Assessment) => action(UPDATE_ASSESSMENT, assessment); export const updateGradingOverviews = (overviews: GradingOverview[]) => diff --git a/src/commons/application/reducers/SessionsReducer.ts b/src/commons/application/reducers/SessionsReducer.ts index 32491eadd6..5bc4f9ef5b 100644 --- a/src/commons/application/reducers/SessionsReducer.ts +++ b/src/commons/application/reducers/SessionsReducer.ts @@ -22,7 +22,6 @@ import { SET_NOTIFICATION_CONFIGS, SET_TOKENS, SET_USER, - UPDATE_ALL_USER_XP, UPDATE_ASSESSMENT, UPDATE_ASSESSMENT_OVERVIEWS, UPDATE_GRADING, @@ -112,8 +111,6 @@ export const SessionsReducer: Reducer = ( }; case UPDATE_TOTAL_XP: return { ...state, xp: action.payload }; - case UPDATE_ALL_USER_XP: - return { ...state, allUserXp: action.payload }; case UPDATE_GRADING: const newGradings = new Map(state.gradings); newGradings.set(action.payload.submissionId, action.payload.grading); diff --git a/src/commons/application/types/SessionTypes.ts b/src/commons/application/types/SessionTypes.ts index f2806898ef..464d8149f3 100644 --- a/src/commons/application/types/SessionTypes.ts +++ b/src/commons/application/types/SessionTypes.ts @@ -18,7 +18,6 @@ export const FETCH_COURSE_CONFIG = 'FETCH_COURSE_CONFIG'; export const FETCH_ASSESSMENT = 'FETCH_ASSESSMENT'; export const FETCH_ASSESSMENT_ADMIN = 'FETCH_ASSESSMENT_ADMIN'; export const FETCH_ASSESSMENT_OVERVIEWS = 'FETCH_ASSESSMENT_OVERVIEWS'; -export const FETCH_ALL_USER_XP = 'FETCH_ALL_USER_XP'; export const FETCH_TOTAL_XP = 'FETCH_TOTAL_XP'; export const FETCH_TOTAL_XP_ADMIN = 'FETCH_TOTAL_XP_ADMIN'; export const FETCH_GRADING = 'FETCH_GRADING'; @@ -48,7 +47,6 @@ export const REMOVE_GITHUB_OCTOKIT_OBJECT_AND_ACCESS_TOKEN = export const UNSUBMIT_SUBMISSION = 'UNSUBMIT_SUBMISSION'; export const UPDATE_ASSESSMENT_OVERVIEWS = 'UPDATE_ASSESSMENT_OVERVIEWS'; export const UPDATE_TOTAL_XP = 'UPDATE_TOTAL_XP'; -export const UPDATE_ALL_USER_XP = 'UPDATE_ALL_USER_XP'; export const UPDATE_ASSESSMENT = 'UPDATE_ASSESSMENT'; export const UPDATE_GRADING_OVERVIEWS = 'UPDATE_GRADING_OVERVIEWS'; export const UPDATE_GRADING = 'UPDATE_GRADING'; @@ -93,7 +91,6 @@ export type SessionState = { readonly gameState: GameState; readonly courseId?: number; readonly xp: number; - readonly allUserXp: string[][] | undefined; readonly story: Story; // Course Configuration diff --git a/src/commons/navigationBar/subcomponents/AcademyNavigationBar.tsx b/src/commons/navigationBar/subcomponents/AcademyNavigationBar.tsx index 40c0591912..fb3e495e85 100644 --- a/src/commons/navigationBar/subcomponents/AcademyNavigationBar.tsx +++ b/src/commons/navigationBar/subcomponents/AcademyNavigationBar.tsx @@ -120,13 +120,6 @@ const getStaffNavlinkInfo = ({ disabled: !isStaffOrAdmin, hiddenInBreakpoints: ['xs', 'sm', 'md'] }, - { - to: `/courses/${courseId}/xpcalculation`, - icon: IconNames.CALCULATOR, - text: 'XP Calculation', - disabled: !isAdmin, - hiddenInBreakpoints: ['xs', 'sm', 'md', 'lg'] - }, { to: `/courses/${courseId}/adminpanel`, icon: IconNames.SETTINGS, diff --git a/src/commons/navigationBar/subcomponents/__tests__/AcademyNavigationBar.tsx b/src/commons/navigationBar/subcomponents/__tests__/AcademyNavigationBar.tsx index c8007e762d..f4c464f7fc 100644 --- a/src/commons/navigationBar/subcomponents/__tests__/AcademyNavigationBar.tsx +++ b/src/commons/navigationBar/subcomponents/__tests__/AcademyNavigationBar.tsx @@ -12,7 +12,7 @@ const useSelectorMock = useSelector as jest.Mock; const assessmentTypes = ['Missions', 'Quests', 'Paths', 'Contests', 'Others']; const staffRoutes = ['grading', 'groundcontrol', 'sourcereel', 'storysimulator', 'dashboard']; -const adminRoutes = ['adminpanel', 'xpcalculation']; +const adminRoutes = ['adminpanel']; const courseId = 0; const createCoursePath = (path: string) => `/courses/${courseId}/${path}`; @@ -71,7 +71,7 @@ test('MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard and G validateAdminPaths(tree, false); }); -test('MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard, Grading, XP Calculation and AdminPanel NavLinks render for Role.Admin', () => { +test('MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard, Grading and AdminPanel NavLinks render for Role.Admin', () => { useSelectorMock.mockReturnValueOnce({ role: Role.Admin, courseId diff --git a/src/commons/navigationBar/subcomponents/__tests__/__snapshots__/AcademyNavigationBar.tsx.snap b/src/commons/navigationBar/subcomponents/__tests__/__snapshots__/AcademyNavigationBar.tsx.snap index 2d48fe1df1..7f2e757576 100644 --- a/src/commons/navigationBar/subcomponents/__tests__/__snapshots__/AcademyNavigationBar.tsx.snap +++ b/src/commons/navigationBar/subcomponents/__tests__/__snapshots__/AcademyNavigationBar.tsx.snap @@ -346,7 +346,7 @@ exports[`MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard, G `; -exports[`MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard, Grading, XP Calculation and AdminPanel NavLinks render for Role.Admin 1`] = ` +exports[`MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard, Grading and AdminPanel NavLinks render for Role.Admin 1`] = ` @@ -541,22 +541,6 @@ exports[`MissionControl, GroundControl, Sourcereel, StorySimulator, Dashboard, G Game Simulator - - -
- XP Calculation -
-
=> { - const resp = await request(`${courseId()}/admin/users/total_xp`, 'GET', { - ...tokens - }); - if (!resp || !resp.ok) { - return null; // invalid accessToken _and_ refreshToken - } - const totalXp = await resp.json(); - return totalXp; -}; - /** * GET /courses/{courseId}/admin/users/{course_reg_id}/assessments */ diff --git a/src/pages/academy/Academy.tsx b/src/pages/academy/Academy.tsx index 8d375d7436..d7ad0cb13a 100644 --- a/src/pages/academy/Academy.tsx +++ b/src/pages/academy/Academy.tsx @@ -27,7 +27,6 @@ import GroundControl from './groundControl/GroundControlContainer'; import NotiPreference from './notiPreference/NotiPreference'; import Sourcereel from './sourcereel/Sourcereel'; import StorySimulator from './storySimulator/StorySimulator'; -import XpCalculation from './xpCalculation/XpCalculation'; const Academy: React.FC<{}> = () => { const dispatch = useDispatch(); @@ -42,10 +41,9 @@ const Academy: React.FC<{}> = () => { ? [ } key={0} />, } key={1} />, - } key={2} />, - } key={3} />, - } key={4} />, - } key={5} /> + } key={2} />, + } key={3} />, + } key={4} /> ] : null; return ( diff --git a/src/pages/academy/xpCalculation/XpCalculation.tsx b/src/pages/academy/xpCalculation/XpCalculation.tsx deleted file mode 100644 index 383df0cb88..0000000000 --- a/src/pages/academy/xpCalculation/XpCalculation.tsx +++ /dev/null @@ -1,233 +0,0 @@ -import 'ag-grid-community/styles/ag-grid.css'; -import 'ag-grid-community/styles/ag-theme-balham.css'; - -import { Button, Divider, NonIdealState, Spinner, SpinnerSize } from '@blueprintjs/core'; -import { IconNames } from '@blueprintjs/icons'; -import { GridApi, GridReadyEvent } from 'ag-grid-community'; -import { AgGridReact } from 'ag-grid-react'; -import { useCallback, useEffect, useState } from 'react'; -import { useDispatch } from 'react-redux'; -import { fetchAllUserXp } from 'src/commons/application/actions/SessionActions'; -import ContentDisplay from 'src/commons/ContentDisplay'; -import { useTypedSelector } from 'src/commons/utils/Hooks'; - -type RowData = { - name: string; - 'NUS Net ID': string; - 'Assessment Xp': string; - 'Achievement Xp': string; -}; - -type PageState = { - currPage: number; - maxPages: number; - rowCountString: string; - isBackDisabled: boolean; - isForwardDisabled: boolean; -}; - -const columnDefs = [ - { field: 'name' }, - { field: 'NUS Net ID' }, - { field: 'Assessment Xp' }, - { field: 'Achievement Xp' } -]; - -const defaultColDef = { - resizable: true, - sortable: true -}; - -const XpCalculation: React.FC = () => { - const dispatch = useDispatch(); - const allUserXp = useTypedSelector(state => state.session.allUserXp); - - const [rowData, setRowData] = useState([]); - const [gridApi, setGridApi] = useState(); - const [pageState, setPageState] = useState({ - currPage: 1, - maxPages: 1, - rowCountString: '(none)', - isBackDisabled: true, - isForwardDisabled: true - }); - - useEffect(() => { - if (allUserXp) { - const rowData = allUserXp.map(data => { - const [name, nusNetId, assessmentXp, achievementXp] = data; - return { - name: name ?? '', - 'NUS Net ID': nusNetId ?? '', - 'Assessment Xp': assessmentXp ?? '0', - 'Achievement Xp': achievementXp ?? '0' - }; - }); - setRowData(rowData); - } - }, [allUserXp]); - - const exportCSV = useCallback(() => { - if (gridApi) { - gridApi.exportDataAsCsv({ - fileName: `SA XP Count (${new Date().toISOString()}).csv`, - // Explicitly declare exported columns to avoid exporting trash columns - columnKeys: ['name', 'NUS Net ID', 'Assessment Xp', 'Achievement Xp'] - }); - } - }, [gridApi]); - - // Forcibly resizes columns to fit the width of the datagrid - prevents datagrid - // from needing to render a horizontal scrollbar when columns overflow grid width - const resizeGrid = useCallback(() => { - if (gridApi) { - gridApi.sizeColumnsToFit(); - } - }, [gridApi]); - - const changePaginationView = useCallback( - (type: string) => { - return () => { - if (gridApi) { - switch (type) { - case 'first': - return gridApi.paginationGoToFirstPage(); - case 'prev': - return gridApi.paginationGoToPreviousPage(); - case 'next': - return gridApi.paginationGoToNextPage(); - case 'last': - return gridApi.paginationGoToLastPage(); - default: - } - } - }; - }, - [gridApi] - ); - - const updatePaginationState = useCallback(() => { - if (gridApi) { - const newTotalPages = gridApi.paginationGetTotalPages(); - const newCurrPage = newTotalPages === 0 ? 0 : gridApi.paginationGetCurrentPage() + 1; - setPageState({ - currPage: newCurrPage, - maxPages: newTotalPages, - rowCountString: formatRowCountString( - 25, - newCurrPage, - newTotalPages, - gridApi.paginationGetRowCount() - ), - isBackDisabled: newTotalPages === 0 || newCurrPage === 1, - isForwardDisabled: newTotalPages === 0 || newCurrPage === newTotalPages - }); - } - }, [gridApi, setPageState]); - - const onGridReady = useCallback( - (params: GridReadyEvent) => { - setGridApi(params.api); - updatePaginationState(); - }, - [setGridApi, updatePaginationState] - ); - - const Controls = () => { - return ( -
-
-
-
- -
-
- -
-
-
- ); - }; /* Display either a loading screen or a table with overviews. */ - const LoadingDisplay = ( - } - /> - ); - - const Content = ( -
- - - -
- ); - - return ( - dispatch(fetchAllUserXp())} - display={!allUserXp ? LoadingDisplay : Content} - fullWidth={false} - /> - ); -}; - -const formatRowCountString = ( - pageSize: number, - currPage: number, - maxPages: number, - totalRows: number -) => { - return maxPages === 0 - ? '(none)' - : currPage !== maxPages - ? `(#${pageSize * currPage - 19} - #${pageSize * currPage})` - : `(#${pageSize * currPage - 19} - #${totalRows})`; -}; - -export default XpCalculation;