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
};

0 commit comments

Comments
 (0)