Skip to content

Commit

Permalink
fix: fixed Configure modal for unit page (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang authored Nov 18, 2024
1 parent 0706a09 commit ba48a27
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,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 @@ -99,13 +99,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 @@ -117,15 +117,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 @@ -65,8 +65,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

0 comments on commit ba48a27

Please sign in to comment.