From c433bc0f97d003d288dc00188fe946e676f4cc66 Mon Sep 17 00:00:00 2001 From: PKulkoRaccoonGang Date: Tue, 7 May 2024 16:30:06 +0300 Subject: [PATCH] refactor: code refactoring --- src/course-unit/CourseUnit.jsx | 5 +-- src/course-unit/CourseUnit.test.jsx | 31 ------------------- .../course-xblock/CourseXBlock.jsx | 2 +- src/course-unit/data/api.js | 4 ++- src/course-unit/data/slice.js | 1 + src/course-unit/data/thunk.js | 2 ++ 6 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/course-unit/CourseUnit.jsx b/src/course-unit/CourseUnit.jsx index 5ebf803b85..dc7a4bae5a 100644 --- a/src/course-unit/CourseUnit.jsx +++ b/src/course-unit/CourseUnit.jsx @@ -73,7 +73,8 @@ const CourseUnit = ({ courseId }) => { const initialXBlocksData = useMemo(() => courseVerticalChildren.children ?? [], [courseVerticalChildren.children]); const [unitXBlocks, setUnitXBlocks] = useState(initialXBlocksData); - + // const unitData = useSelector(state => state.courseUnit); + // console.log('unitData ===>', unitData); useEffect(() => { document.title = getPageHeadTitle('', unitTitle); }, [unitTitle]); @@ -98,7 +99,7 @@ const CourseUnit = ({ courseId }) => { ); } - + console.log('movedXBlockParams =======>', movedXBlockParams); const finalizeXBlockOrder = () => (newXBlocks) => { handleXBlockDragAndDrop(newXBlocks.map(xBlock => xBlock.id), () => { setUnitXBlocks(initialXBlocksData); diff --git a/src/course-unit/CourseUnit.test.jsx b/src/course-unit/CourseUnit.test.jsx index 4127058189..1eeb02823d 100644 --- a/src/course-unit/CourseUnit.test.jsx +++ b/src/course-unit/CourseUnit.test.jsx @@ -1513,37 +1513,6 @@ describe('', () => { }); }); - it('should expand xblocks when "Expand all" button is clicked', async () => { - const { getByRole, getAllByTestId } = render(); - - axiosMock - .onGet(getCourseVerticalChildrenApiUrl(blockId)) - .reply(200, courseVerticalChildrenMock); - - await executeThunk(fetchCourseVerticalChildrenData(blockId), store.dispatch); - - const expandAllXBlocksBtn = getByRole('button', { name: messages.expandAllButton.defaultMessage }); - const unitXBlocks = getAllByTestId('course-xblock'); - - unitXBlocks.forEach((unitXBlock) => { - const unitXBlockContentSections = unitXBlock.querySelectorAll('.pgn__card-section'); - expect(unitXBlockContentSections).toHaveLength(0); - }); - - userEvent.click(expandAllXBlocksBtn); - - await waitFor(() => { - const collapseAllXBlocksBtn = getByRole('button', { name: messages.collapseAllButton.defaultMessage }); - expect(collapseAllXBlocksBtn).toBeInTheDocument(); - - unitXBlocks.forEach((unitXBlock) => { - const unitXBlockContentSections = unitXBlock.querySelectorAll('.pgn__card-section'); - // xblock content appears inside the xblock element - expect(unitXBlockContentSections.length).toBeGreaterThan(0); - }); - }); - }); - describe('Edit and move modals', () => { it('should close the edit modal when the close button is clicked', async () => { const { getByTitle, getAllByTestId } = render(); diff --git a/src/course-unit/course-xblock/CourseXBlock.jsx b/src/course-unit/course-xblock/CourseXBlock.jsx index 0cad179471..7ae4f25710 100644 --- a/src/course-unit/course-xblock/CourseXBlock.jsx +++ b/src/course-unit/course-xblock/CourseXBlock.jsx @@ -48,7 +48,7 @@ const CourseXBlock = ({ useEffect(() => { const handleMessage = (event) => { const { method, params } = event.data; - + console.log('method ===>', method); if (method === 'close_modal') { toggleLegacyEditModal(false); dispatch(fetchCourseVerticalChildrenData(blockId)); diff --git a/src/course-unit/data/api.js b/src/course-unit/data/api.js index dd1a2e42c8..e0a03698d3 100644 --- a/src/course-unit/data/api.js +++ b/src/course-unit/data/api.js @@ -19,9 +19,10 @@ export const postXBlockBaseApiUrl = () => `${getStudioBaseUrl()}/xblock/`; * @returns {Promise} */ export async function getCourseUnitData(unitId) { + const { data } = await getAuthenticatedHttpClient() .get(getCourseUnitApiUrl(unitId)); - + console.log('getCourseUnitData', data); return camelCaseObject(data); } @@ -156,6 +157,7 @@ export async function duplicateUnitItem(itemId, XBlockId) { * @returns {Promise} - A promise that resolves to the response data from the server. */ export async function rollbackUnitItem(itemId, xblockId) { + console.log('HELLOOOOOOOOO'); const { data } = await getAuthenticatedHttpClient() .patch(postXBlockBaseApiUrl(), { parent_locator: itemId, diff --git a/src/course-unit/data/slice.js b/src/course-unit/data/slice.js index c967517a2b..881fb5f6ba 100644 --- a/src/course-unit/data/slice.js +++ b/src/course-unit/data/slice.js @@ -9,6 +9,7 @@ const slice = createSlice({ savingStatus: '', isQueryPending: false, isTitleEditFormOpen: false, + canEdit: true, movedXBlockParams: { isSuccess: false, isUndo: false, diff --git a/src/course-unit/data/thunk.js b/src/course-unit/data/thunk.js index ce4108c964..323e820644 100644 --- a/src/course-unit/data/thunk.js +++ b/src/course-unit/data/thunk.js @@ -261,11 +261,13 @@ export function rollbackUnitItemQuery(itemId, xblockId, title) { const newCourseVerticalChildren = await getCourseVerticalChildren(itemId); dispatch(updateCourseVerticalChildren(newCourseVerticalChildren)); const courseUnit = await getCourseUnitData(itemId); + dispatch(fetchCourseItemSuccess(courseUnit)); dispatch(hideProcessingNotification()); dispatch(updateSavingStatus({ status: RequestStatus.SUCCESSFUL })); dispatch(updateMovedXBlockParams({ title, isSuccess: true, isUndo: true })); } catch (error) { + console.log('HEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEYHEY', error); dispatch(hideProcessingNotification()); dispatch(updateSavingStatus({ status: RequestStatus.FAILED })); }