Skip to content

Commit 10d5a83

Browse files
authored
Merge branch 'master' into game-quiz2
2 parents 6de3681 + 6250475 commit 10d5a83

File tree

67 files changed

+527
-875
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+527
-875
lines changed
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { createAction } from '@reduxjs/toolkit';
21
import { Router } from '@remix-run/router';
2+
import { createActions } from 'src/commons/redux/utils';
33

4-
import { LOG_OUT, UPDATE_REACT_ROUTER } from '../types/CommonsTypes';
4+
const CommonsActions = createActions('commons', {
5+
logOut: () => ({}),
6+
updateReactRouter: (updatedRouter: Router) => updatedRouter
7+
});
58

6-
export const logOut = createAction(LOG_OUT, () => ({ payload: {} }));
7-
export const updateReactRouter = createAction(UPDATE_REACT_ROUTER, (updatedRouter: Router) => ({
8-
payload: updatedRouter
9-
}));
9+
// For compatibility with existing code (reducer)
10+
export const { logOut, updateReactRouter } = CommonsActions;
11+
12+
// For compatibility with existing code (actions helper)
13+
export default CommonsActions;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { LOG_OUT } from '../../types/CommonsTypes';
2-
import { logOut } from '../CommonsActions';
1+
import CommonsActions from '../CommonsActions';
32

43
test('logOut generates correct action object', () => {
5-
const action = logOut();
4+
const action = CommonsActions.logOut();
65
expect(action).toEqual({
7-
type: LOG_OUT,
6+
type: CommonsActions.logOut.type,
87
payload: {}
98
});
109
});

src/commons/application/reducers/SessionsReducer.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { createReducer } from '@reduxjs/toolkit';
22
import { Reducer } from 'redux';
3-
import {
4-
remoteExecUpdateDevices,
5-
remoteExecUpdateSession
6-
} from 'src/features/remoteExecution/RemoteExecutionActions';
3+
import RemoteExecutionActions from 'src/features/remoteExecution/RemoteExecutionActions';
74

85
import { SourceActionType } from '../../utils/ActionsHelper';
96
import { logOut } from '../actions/CommonsActions';
@@ -84,10 +81,10 @@ const newSessionsReducer = createReducer(defaultSession, builder => {
8481
.addCase(SessionActions.updateTeamFormationOverview, (state, action) => {
8582
state.teamFormationOverview = action.payload;
8683
})
87-
.addCase(remoteExecUpdateDevices, (state, action) => {
84+
.addCase(RemoteExecutionActions.remoteExecUpdateDevices, (state, action) => {
8885
state.remoteExecutionDevices = action.payload;
8986
})
90-
.addCase(remoteExecUpdateSession, (state, action) => {
87+
.addCase(RemoteExecutionActions.remoteExecUpdateSession, (state, action) => {
9188
state.remoteExecutionSession = action.payload;
9289
})
9390
.addCase(SessionActions.removeGitHubOctokitObjectAndAccessToken, (state, action) => {

src/commons/application/reducers/__tests__/SessionReducer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import {
88
ProgressStatuses
99
} from '../../../assessment/AssessmentTypes';
1010
import { Notification } from '../../../notificationBadge/NotificationBadgeTypes';
11+
import CommonsActions from '../../actions/CommonsActions';
1112
import SessionActions from '../../actions/SessionActions';
1213
import { defaultSession, GameState, Role, Story } from '../../ApplicationTypes';
13-
import { LOG_OUT } from '../../types/CommonsTypes';
1414
import { SessionState } from '../../types/SessionTypes';
1515
import { SessionsReducer } from '../SessionsReducer';
1616

1717
test('LOG_OUT works correctly on default session', () => {
1818
const action = {
19-
type: LOG_OUT,
19+
type: CommonsActions.logOut.type,
2020
payload: {}
2121
} as const;
2222
const result: SessionState = SessionsReducer(defaultSession, action);
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
import { Router } from '@remix-run/router';
22

3-
export const LOG_OUT = 'LOG_OUT';
4-
export const UPDATE_REACT_ROUTER = 'UPDATE_REACT_ROUTER';
5-
63
export type RouterState = Router | null;
Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,29 @@
1-
import { createAction } from '@reduxjs/toolkit';
2-
1+
import { createActions } from '../redux/utils';
32
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
4-
import {
5-
SET_EDITOR_SESSION_ID,
6-
SET_SESSION_DETAILS,
7-
SET_SHAREDB_CONNECTED
8-
} from './CollabEditingTypes';
9-
10-
export const setEditorSessionId = createAction(
11-
SET_EDITOR_SESSION_ID,
12-
(workspaceLocation: WorkspaceLocation, editorSessionId: string) => ({
13-
payload: { workspaceLocation, editorSessionId }
14-
})
15-
);
163

17-
export const setSessionDetails = createAction(
18-
SET_SESSION_DETAILS,
19-
(
4+
const CollabEditingActions = createActions('collabEditing', {
5+
setEditorSessionId: (workspaceLocation: WorkspaceLocation, editorSessionId: string) => ({
6+
workspaceLocation,
7+
editorSessionId
8+
}),
9+
setSessionDetails: (
2010
workspaceLocation: WorkspaceLocation,
2111
sessionDetails: { docId: string; readOnly: boolean } | null
22-
) => ({
23-
payload: { workspaceLocation, sessionDetails }
12+
) => ({ workspaceLocation, sessionDetails }),
13+
/**
14+
* Sets ShareDB connection status.
15+
*
16+
* @param workspaceLocation the workspace to be reset
17+
* @param connected whether we are connected to ShareDB
18+
*/
19+
setSharedbConnected: (workspaceLocation: WorkspaceLocation, connected: boolean) => ({
20+
workspaceLocation,
21+
connected
2422
})
25-
);
23+
});
2624

27-
/**
28-
* Sets ShareDB connection status.
29-
*
30-
* @param workspaceLocation the workspace to be reset
31-
* @param connected whether we are connected to ShareDB
32-
*/
33-
export const setSharedbConnected = createAction(
34-
SET_SHAREDB_CONNECTED,
35-
(workspaceLocation: WorkspaceLocation, connected: boolean) => ({
36-
payload: { workspaceLocation, connected }
37-
})
38-
);
25+
// For compatibility with existing code (reducer)
26+
export const { setEditorSessionId, setSessionDetails, setSharedbConnected } = CollabEditingActions;
27+
28+
// For compatibility with existing code (actions helper)
29+
export default CollabEditingActions;

src/commons/collabEditing/CollabEditingTypes.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/commons/collabEditing/__tests__/CollabEditingActions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { WorkspaceLocation } from '../../workspace/WorkspaceTypes';
22
import { setEditorSessionId, setSharedbConnected } from '../CollabEditingActions';
3-
import { SET_EDITOR_SESSION_ID, SET_SHAREDB_CONNECTED } from '../CollabEditingTypes';
43

54
const gradingWorkspace: WorkspaceLocation = 'grading';
65
const playgroundWorkspace: WorkspaceLocation = 'playground';
@@ -9,7 +8,7 @@ test('setEditorSessionId generates correct action object', () => {
98
const editorSessionId = 'test-editor-session-id';
109
const action = setEditorSessionId(gradingWorkspace, editorSessionId);
1110
expect(action).toEqual({
12-
type: SET_EDITOR_SESSION_ID,
11+
type: setEditorSessionId.type,
1312
payload: {
1413
workspaceLocation: gradingWorkspace,
1514
editorSessionId
@@ -21,7 +20,7 @@ test('setSharedbConnected generates correct action object', () => {
2120
const connected = false;
2221
const action = setSharedbConnected(playgroundWorkspace, connected);
2322
expect(action).toEqual({
24-
type: SET_SHAREDB_CONNECTED,
23+
type: setSharedbConnected.type,
2524
payload: {
2625
workspaceLocation: playgroundWorkspace,
2726
connected

src/commons/dropdown/DropdownCreateCourse.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { IconNames } from '@blueprintjs/icons';
1616
import { Chapter, Variant } from 'js-slang/dist/types';
1717
import React from 'react';
1818
import { useDispatch } from 'react-redux';
19-
import { createCourse } from 'src/features/academy/AcademyActions';
19+
import AcademyActions from 'src/features/academy/AcademyActions';
2020

2121
import { CourseHelpTextEditorTab } from '../../pages/academy/adminPanel/subcomponents/CourseConfigPanel';
2222
import { sourceLanguages } from '../application/ApplicationTypes';
@@ -71,7 +71,7 @@ const DropdownCreateCourse: React.FC<Props> = props => {
7171
showWarningMessage('Course Name cannot be empty!');
7272
return;
7373
}
74-
dispatch(createCourse(courseConfig));
74+
dispatch(AcademyActions.createCourse(courseConfig));
7575
props.onClose();
7676
};
7777

src/commons/fileSystemView/FileSystemViewDirectoryNode.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import classes from 'src/styles/FileSystemView.module.scss';
88

99
import { rmdirRecursively } from '../fileSystem/utils';
1010
import { showSimpleConfirmDialog, showSimpleErrorDialog } from '../utils/DialogHelper';
11-
import { removeEditorTabsForDirectory } from '../workspace/WorkspaceActions';
11+
import WorkspaceActions from '../workspace/WorkspaceActions';
1212
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
1313
import FileSystemViewContextMenu from './FileSystemViewContextMenu';
1414
import FileSystemViewFileName from './FileSystemViewFileName';
@@ -78,7 +78,7 @@ const FileSystemViewDirectoryNode: React.FC<Props> = ({
7878
return;
7979
}
8080

81-
dispatch(removeEditorTabsForDirectory(workspaceLocation, fullPath));
81+
dispatch(WorkspaceActions.removeEditorTabsForDirectory(workspaceLocation, fullPath));
8282
rmdirRecursively(fileSystem, fullPath).then(refreshParentDirectory);
8383
});
8484
};

src/commons/fileSystemView/FileSystemViewFileName.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import { useDispatch } from 'react-redux';
55
import classes from 'src/styles/FileSystemView.module.scss';
66

77
import { showSimpleErrorDialog } from '../utils/DialogHelper';
8-
import {
9-
renameEditorTabForFile,
10-
renameEditorTabsForDirectory
11-
} from '../workspace/WorkspaceActions';
8+
import WorkspaceActions from '../workspace/WorkspaceActions';
129
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
1310

1411
type Props = {
@@ -69,9 +66,11 @@ const FileSystemViewFileName: React.FC<Props> = ({
6966
}
7067

7168
if (isDirectory) {
72-
dispatch(renameEditorTabsForDirectory(workspaceLocation, oldPath, newPath));
69+
dispatch(
70+
WorkspaceActions.renameEditorTabsForDirectory(workspaceLocation, oldPath, newPath)
71+
);
7372
} else {
74-
dispatch(renameEditorTabForFile(workspaceLocation, oldPath, newPath));
73+
dispatch(WorkspaceActions.renameEditorTabForFile(workspaceLocation, oldPath, newPath));
7574
}
7675
refreshDirectory();
7776
});

src/commons/fileSystemView/FileSystemViewFileNode.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { useDispatch } from 'react-redux';
77
import classes from 'src/styles/FileSystemView.module.scss';
88

99
import { showSimpleConfirmDialog } from '../utils/DialogHelper';
10-
import { addEditorTab, removeEditorTabForFile } from '../workspace/WorkspaceActions';
10+
import WorkspaceActions from '../workspace/WorkspaceActions';
1111
import { WorkspaceLocation } from '../workspace/WorkspaceTypes';
1212
import FileSystemViewContextMenu from './FileSystemViewContextMenu';
1313
import FileSystemViewFileName from './FileSystemViewFileName';
@@ -44,7 +44,7 @@ const FileSystemViewFileNode: React.FC<Props> = ({
4444
throw new Error('File contents are undefined.');
4545
}
4646

47-
dispatch(addEditorTab(workspaceLocation, fullPath, fileContents));
47+
dispatch(WorkspaceActions.addEditorTab(workspaceLocation, fullPath, fileContents));
4848
});
4949
};
5050

@@ -74,7 +74,7 @@ const FileSystemViewFileNode: React.FC<Props> = ({
7474
console.error(err);
7575
}
7676

77-
dispatch(removeEditorTabForFile(workspaceLocation, fullPath));
77+
dispatch(WorkspaceActions.removeEditorTabForFile(workspaceLocation, fullPath));
7878
refreshDirectory();
7979
});
8080
});

src/commons/mocks/BackendMocks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SagaIterator } from 'redux-saga';
22
import { call, put, select, takeEvery } from 'redux-saga/effects';
3+
import DashboardActions from 'src/features/dashboard/DashboardActions';
34

4-
import { FETCH_GROUP_GRADING_SUMMARY } from '../../features/dashboard/DashboardTypes';
55
import {
66
GradingOverviews,
77
GradingQuery,
@@ -450,7 +450,7 @@ export function* mockBackendSaga(): SagaIterator {
450450
}
451451
);
452452

453-
yield takeEvery(FETCH_GROUP_GRADING_SUMMARY, function* () {
453+
yield takeEvery(DashboardActions.fetchGroupGradingSummary.type, function* () {
454454
yield put(actions.updateGroupGradingSummary({ ...mockGradingSummary }));
455455
});
456456
}

src/commons/navigationBar/subcomponents/NavigationBarLangSelectButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from 'src/commons/application/ApplicationTypes';
1515
import SimpleDropdown from 'src/commons/SimpleDropdown';
1616
import { useTypedSelector } from 'src/commons/utils/Hooks';
17-
import { chapterSelect } from 'src/commons/workspace/WorkspaceActions';
17+
import WorkspaceActions from 'src/commons/workspace/WorkspaceActions';
1818
import { playgroundConfigLanguage } from 'src/features/playground/PlaygroundActions';
1919

2020
// TODO: Hardcoded to use the first sublanguage for each language
@@ -35,7 +35,7 @@ const NavigationBarLangSelectButton = () => {
3535
const selectLang = (language: SupportedLanguage) => {
3636
const { chapter, variant } = defaultSublanguages[language];
3737
dispatch(playgroundConfigLanguage(getLanguageConfig(chapter, variant)));
38-
dispatch(chapterSelect(chapter, variant, 'playground'));
38+
dispatch(WorkspaceActions.chapterSelect(chapter, variant, 'playground'));
3939
setIsOpen(false);
4040
};
4141

0 commit comments

Comments
 (0)