Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed Configure modal for Course Unit page #1452

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: 1 addition & 1 deletion src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ describe('<CourseUnit />', () => {
axiosMock
.onPost(getXBlockBaseApiUrl(courseUnitIndexMock.id), {
publish: null,
metadata: { visible_to_staff_only: true, group_access: { 50: [2] } },
metadata: { visible_to_staff_only: true, group_access: { 50: [2] }, discussion_enabled: true },
})
.reply(200, { dummy: 'value' });
axiosMock
Expand Down
3 changes: 2 additions & 1 deletion src/course-unit/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,14 @@ export async function createCourseXblock({
* @param {boolean} groupAccess - Access group key set.
* @returns {Promise<any>} A promise that resolves with the response data.
*/
export async function handleCourseUnitVisibilityAndData(unitId, type, isVisible, groupAccess) {
export async function handleCourseUnitVisibilityAndData(unitId, type, isVisible, groupAccess, isDiscussionEnabled) {
const body = {
publish: groupAccess ? null : type,
...(type === PUBLISH_TYPES.republish ? {
metadata: {
visible_to_staff_only: isVisible ? true : null,
group_access: groupAccess || null,
discussion_enabled: isDiscussionEnabled,
},
} : {}),
};
Expand Down
19 changes: 16 additions & 3 deletions src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,28 @@ export function editCourseItemQuery(itemId, displayName, sequenceId) {
};
}

export function editCourseUnitVisibilityAndData(itemId, type, isVisible, groupAccess, isModalView, blockId = itemId) {
export function editCourseUnitVisibilityAndData(
itemId,
type,
isVisible,
groupAccess,
isDiscussionEnabled,
blockId = itemId,
) {
return async (dispatch) => {
dispatch(updateSavingStatus({ status: RequestStatus.PENDING }));
dispatch(updateQueryPendingStatus(true));
const notification = getNotificationMessage(type, isVisible, isModalView);
const notification = getNotificationMessage(type, isVisible, true);
dispatch(showProcessingNotification(notification));

try {
await handleCourseUnitVisibilityAndData(itemId, type, isVisible, groupAccess).then(async (result) => {
await handleCourseUnitVisibilityAndData(
itemId,
type,
isVisible,
groupAccess,
isDiscussionEnabled,
).then(async (result) => {
if (result) {
const courseUnit = await getCourseUnitData(blockId);
dispatch(fetchCourseItemSuccess(courseUnit));
Expand Down
11 changes: 9 additions & 2 deletions src/course-unit/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,15 @@ export const useCourseUnit = ({ courseId, blockId }) => {
dispatch(changeEditTitleFormOpen(!isTitleEditFormOpen));
};

const handleConfigureSubmit = (id, isVisible, groupAccess, closeModalFn) => {
dispatch(editCourseUnitVisibilityAndData(id, PUBLISH_TYPES.republish, isVisible, groupAccess, true, blockId));
const handleConfigureSubmit = (id, isVisible, groupAccess, isDiscussionEnabled, closeModalFn) => {
dispatch(editCourseUnitVisibilityAndData(
id,
PUBLISH_TYPES.republish,
isVisible,
groupAccess,
isDiscussionEnabled,
blockId,
));
closeModalFn();
};

Expand Down
8 changes: 8 additions & 0 deletions src/generic/configure-modal/ConfigureModal.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ describe('<ConfigureModal /> for Unit', () => {

expect(getByRole('button', { name: messages.cancelButton.defaultMessage })).toBeInTheDocument();
expect(getByRole('button', { name: messages.saveButton.defaultMessage })).toBeInTheDocument();

expect(queryByText(messages.discussionEnabledSectionTitle.defaultMessage)).toBeInTheDocument();
expect(queryByText(messages.discussionEnabledCheckbox.defaultMessage)).toBeInTheDocument();
expect(queryByText(messages.discussionEnabledDescription.defaultMessage)).toBeInTheDocument();
});
});

Expand Down Expand Up @@ -278,5 +282,9 @@ describe('<ConfigureModal /> for XBlock', () => {

expect(getByRole('button', { name: messages.cancelButton.defaultMessage })).toBeInTheDocument();
expect(getByRole('button', { name: messages.saveButton.defaultMessage })).toBeInTheDocument();

expect(queryByText(messages.discussionEnabledSectionTitle.defaultMessage)).not.toBeInTheDocument();
expect(queryByText(messages.discussionEnabledCheckbox.defaultMessage)).not.toBeInTheDocument();
expect(queryByText(messages.discussionEnabledDescription.defaultMessage)).not.toBeInTheDocument();
});
});
16 changes: 10 additions & 6 deletions src/generic/configure-modal/UnitTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,16 @@ const UnitTab = ({
)}
</Form.Group>
)}
<h4 className="mt-4"><FormattedMessage {...messages.discussionEnabledSectionTitle} /></h4>
<hr />
<Form.Checkbox checked={discussionEnabled} onChange={handleDiscussionChange}>
<FormattedMessage {...messages.discussionEnabledCheckbox} />
</Form.Checkbox>
<p className="x-small font-weight-bold"><FormattedMessage {...messages.discussionEnabledDescription} /></p>
{!isXBlockComponent && (
<>
<h4 className="mt-4"><FormattedMessage {...messages.discussionEnabledSectionTitle} /></h4>
<hr />
<Form.Checkbox checked={discussionEnabled} onChange={handleDiscussionChange}>
<FormattedMessage {...messages.discussionEnabledCheckbox} />
</Form.Checkbox>
<p className="x-small font-weight-bold"><FormattedMessage {...messages.discussionEnabledDescription} /></p>
</>
)}
</>
);
};
Expand Down