Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/commons/application/actions/__tests__/SessionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ test('setCourseConfiguration generates correct action object', () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
Expand Down Expand Up @@ -612,6 +613,7 @@ test('updateCourseConfig generates correct action object', () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ test('SET_COURSE_CONFIGURATION works correctly', () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
Expand Down
2 changes: 2 additions & 0 deletions src/commons/application/types/SessionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export type SessionState = {
readonly enableGame?: boolean;
readonly enableAchievements?: boolean;
readonly enableSourcecast?: boolean;
readonly enableStories?: boolean;
readonly sourceChapter?: number;
readonly sourceVariant?: Variant;
readonly moduleHelpText?: string;
Expand Down Expand Up @@ -168,6 +169,7 @@ export type CourseConfiguration = {
enableGame: boolean;
enableAchievements: boolean;
enableSourcecast: boolean;
enableStories: boolean;
sourceChapter: Chapter;
sourceVariant: Variant;
moduleHelpText: string;
Expand Down
13 changes: 13 additions & 0 deletions src/commons/dropdown/DropdownCreateCourse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const DropdownCreateCourse: React.FC<DialogProps> = props => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: ''
Expand Down Expand Up @@ -222,6 +223,18 @@ const DropdownCreateCourse: React.FC<DialogProps> = props => {
})
}
/>

<Switch
checked={courseConfig.enableStories}
inline
label="Enable Stories"
onChange={e =>
setCourseConfig({
...courseConfig,
enableStories: (e.target as HTMLInputElement).checked
})
}
/>
</div>
</div>
<div>
Expand Down
2 changes: 2 additions & 0 deletions src/commons/mocks/UserMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const mockCourseConfigurations: CourseConfiguration[] = [
enableGame: false,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: '',
Expand All @@ -142,6 +143,7 @@ export const mockCourseConfigurations: CourseConfiguration[] = [
enableGame: false,
enableAchievements: false,
enableSourcecast: false,
enableStories: false,
sourceChapter: Chapter.SOURCE_2,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help Text!',
Expand Down
30 changes: 19 additions & 11 deletions src/commons/navigationBar/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const NavigationBar: React.FC = () => {
courseShortName,
enableAchievements,
enableSourcecast,
enableStories,
assessmentConfigurations
} = useSession();
const assessmentTypes = useMemo(
Expand Down Expand Up @@ -180,14 +181,21 @@ const NavigationBar: React.FC = () => {
disabled: !(isEnrolledInACourse && enableAchievements)
},
{
to: '/stories',
to: `/courses/${courseId}/stories`,
icon: IconNames.GIT_REPO,
text: 'Stories',
// TODO: Enable when stories are implemented
disabled: true && !isLoggedIn
// TODO: Enable for public deployment
disabled: !(isEnrolledInACourse && enableStories)
}
];
}, [isLoggedIn, isEnrolledInACourse, courseId, enableSourcecast, enableAchievements]);
}, [
courseId,
isEnrolledInACourse,
enableSourcecast,
enableStories,
isLoggedIn,
enableAchievements
]);

const fullAcademyMobileNavbarLeftAdditionalInfo = useMemo(
() => getAcademyNavbarRightInfo({ isEnrolledInACourse, courseId, role }),
Expand Down Expand Up @@ -359,14 +367,14 @@ const playgroundOnlyNavbarLeftInfo: NavbarEntryInfo[] = [
to: '/sicpjs',
icon: IconNames.BOOK,
text: 'SICP JS'
},
{
to: '/stories',
icon: IconNames.GIT_REPO,
text: 'Stories',
// TODO: Enable when stories are implemented
disabled: true
}
// {
// to: '/stories',
// icon: IconNames.GIT_REPO,
// text: 'Stories',
// // TODO: Enable for public deployment
// disabled: true
// }
];

export const renderNavlinksFromInfo = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,20 +347,6 @@ exports[`NavigationBar Renders correctly for student with course 1`] = `
Achievements
</div>
</NavLink>
<NavLink
className={[Function]}
title="Stories"
to="/stories"
>
<Blueprint4.Icon
icon="git-repo"
/>
<div
className=""
>
Stories
</div>
</NavLink>
</Blueprint4.NavbarGroup>
<Blueprint4.NavbarGroup
align="right"
Expand Down Expand Up @@ -518,20 +504,6 @@ exports[`NavigationBar Renders correctly for student without course 1`] = `
SICP JS
</div>
</NavLink>
<NavLink
className={[Function]}
title="Stories"
to="/stories"
>
<Blueprint4.Icon
icon="git-repo"
/>
<div
className=""
>
Stories
</div>
</NavLink>
</Blueprint4.NavbarGroup>
<Blueprint4.NavbarGroup
align="right"
Expand Down
46 changes: 38 additions & 8 deletions src/commons/sagas/BackendSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ function* BackendSaga(): SagaIterator {
yield put(actions.setCourseConfiguration(courseConfiguration));
yield put(actions.setAssessmentConfigurations(assessmentConfigurations));

yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
if (courseConfiguration.enableStories) {
yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
} else {
yield put(actions.clearStoriesUserAndGroup());
}
}
/**
* NOTE: Navigation logic is now handled in <Login /> component.
Expand Down Expand Up @@ -245,8 +249,12 @@ function* BackendSaga(): SagaIterator {
yield put(actions.setCourseConfiguration(courseConfiguration));
yield put(actions.setAssessmentConfigurations(assessmentConfigurations));

yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
if (courseConfiguration.enableStories) {
yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
} else {
yield put(actions.clearStoriesUserAndGroup());
}
}
}
);
Expand All @@ -257,8 +265,12 @@ function* BackendSaga(): SagaIterator {
if (config) {
yield put(actions.setCourseConfiguration(config));

yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
if (config.enableStories) {
yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
} else {
yield put(actions.clearStoriesUserAndGroup());
}
}
});

Expand Down Expand Up @@ -724,8 +736,12 @@ function* BackendSaga(): SagaIterator {
yield put(actions.setAssessmentConfigurations(assessmentConfigurations));
yield put(actions.setCourseRegistration(courseRegistration));

yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
if (courseConfiguration.enableStories) {
yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
} else {
yield put(actions.clearStoriesUserAndGroup());
}

yield call(showSuccessMessage, `Switched to ${courseConfiguration.courseName}!`, 5000);
}
Expand All @@ -742,6 +758,13 @@ function* BackendSaga(): SagaIterator {
return yield handleResponseError(resp);
}

if (courseConfig.enableStories) {
yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
} else {
yield put(actions.clearStoriesUserAndGroup());
}

yield put(actions.setCourseConfiguration(courseConfig));
yield call(showSuccessMessage, 'Updated successfully!', 1000);
}
Expand Down Expand Up @@ -945,6 +968,13 @@ function* BackendSaga(): SagaIterator {
yield put(actions.setUser(user));
yield put(actions.setCourseRegistration({ role: Role.Student }));

if (courseConfiguration.enableStories) {
yield put(actions.getStoriesUser());
// TODO: Fetch associated stories group ID
} else {
yield put(actions.clearStoriesUserAndGroup());
}

const placeholderAssessmentConfig = [
{
type: 'Missions',
Expand Down
4 changes: 4 additions & 0 deletions src/commons/sagas/__tests__/BackendSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ const mockCourseConfiguration1: CourseConfiguration = {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
Expand Down Expand Up @@ -203,6 +204,7 @@ const mockCourseConfiguration2: CourseConfiguration = {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_4,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help text',
Expand Down Expand Up @@ -887,6 +889,7 @@ describe('Test UPDATE_COURSE_CONFIG action', () => {
enableGame: false,
enableAchievements: false,
enableSourcecast: false,
enableStories: false,
sourceChapter: Chapter.SOURCE_4,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help',
Expand Down Expand Up @@ -984,6 +987,7 @@ describe('Test CREATE_COURSE action', () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help Text'
Expand Down
1 change: 1 addition & 0 deletions src/features/academy/__tests__/AcademyActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ test('createCourse generates correct action object', () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
sourceChapter: Chapter.SOURCE_1,
sourceVariant: Variant.DEFAULT,
moduleHelpText: 'Help Text'
Expand Down
3 changes: 3 additions & 0 deletions src/features/stories/StoriesActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { action } from 'typesafe-actions';

import {
ADD_STORY_ENV,
CLEAR_STORIES_USER_AND_GROUP,
CLEAR_STORY_ENV,
CREATE_STORY,
DELETE_STORY,
Expand Down Expand Up @@ -78,3 +79,5 @@ export const setCurrentStoriesGroup = (
name: string | undefined,
role: StoriesRole | undefined
) => action(SET_CURRENT_STORIES_GROUP, { id, name, role });
// Helper/wrapper actions
export const clearStoriesUserAndGroup = () => action(CLEAR_STORIES_USER_AND_GROUP);
10 changes: 10 additions & 0 deletions src/features/stories/StoriesReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { SourceActionType } from '../../commons/utils/ActionsHelper';
import { DEFAULT_ENV } from './storiesComponents/UserBlogContent';
import {
ADD_STORY_ENV,
CLEAR_STORIES_USER_AND_GROUP,
CLEAR_STORY_ENV,
EVAL_STORY,
EVAL_STORY_ERROR,
Expand Down Expand Up @@ -212,6 +213,15 @@ export const StoriesReducer: Reducer<StoriesState> = (
...state,
currentStory: action.payload
};
case CLEAR_STORIES_USER_AND_GROUP:
return {
...state,
userId: undefined,
userName: undefined,
groupId: undefined,
groupName: undefined,
role: undefined
};
case SET_CURRENT_STORIES_USER:
return {
...state,
Expand Down
1 change: 1 addition & 0 deletions src/features/stories/StoriesTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const SAVE_STORY = 'SAVE_STORY';
export const DELETE_STORY = 'DELETE_STORY';
// Auth-related actions
export const GET_STORIES_USER = 'GET_STORIES_USER';
export const CLEAR_STORIES_USER_AND_GROUP = 'CLEAR_STORIES_USER_AND_GROUP';
// TODO: Investigate possibility of combining the two actions
export const SET_CURRENT_STORIES_USER = 'SET_CURRENT_STORIES_USER';
export const SET_CURRENT_STORIES_GROUP = 'SET_CURRENT_STORIES_GROUP';
Expand Down
1 change: 1 addition & 0 deletions src/pages/__tests__/localStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const mockShortDefaultState: SavedState = {
enableGame: defaultState.session.enableGame,
enableAchievements: defaultState.session.enableAchievements,
enableSourcecast: defaultState.session.enableSourcecast,
enableStories: defaultState.session.enableStories,
moduleHelpText: defaultState.session.moduleHelpText,
assetsPrefix: defaultState.session.assetsPrefix,
assessmentConfigurations: defaultState.session.assessmentConfigurations
Expand Down
2 changes: 2 additions & 0 deletions src/pages/academy/adminPanel/AdminPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const AdminPanel: React.FC = () => {
enableGame: true,
enableAchievements: true,
enableSourcecast: true,
enableStories: false,
moduleHelpText: ''
});

Expand Down Expand Up @@ -84,6 +85,7 @@ const AdminPanel: React.FC = () => {
enableGame: session.enableGame,
enableAchievements: session.enableAchievements,
enableSourcecast: session.enableSourcecast,
enableStories: session.enableStories,
moduleHelpText: session.moduleHelpText
});

Expand Down
Loading