Skip to content

Commit

Permalink
refactor: code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
PKulkoRaccoonGang committed May 7, 2024
1 parent cc0f5d6 commit c433bc0
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -98,7 +99,7 @@ const CourseUnit = ({ courseId }) => {
</Container>
);
}

console.log('movedXBlockParams =======>', movedXBlockParams);

Check warning on line 102 in src/course-unit/CourseUnit.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
const finalizeXBlockOrder = () => (newXBlocks) => {
handleXBlockDragAndDrop(newXBlocks.map(xBlock => xBlock.id), () => {
setUnitXBlocks(initialXBlocksData);
Expand Down
31 changes: 0 additions & 31 deletions src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1513,37 +1513,6 @@ describe('<CourseUnit />', () => {
});
});

it('should expand xblocks when "Expand all" button is clicked', async () => {
const { getByRole, getAllByTestId } = render(<RootWrapper />);

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(<RootWrapper />);
Expand Down
2 changes: 1 addition & 1 deletion src/course-unit/course-xblock/CourseXBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const CourseXBlock = ({
useEffect(() => {
const handleMessage = (event) => {
const { method, params } = event.data;

console.log('method ===>', method);

Check warning on line 51 in src/course-unit/course-xblock/CourseXBlock.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
if (method === 'close_modal') {
toggleLegacyEditModal(false);
dispatch(fetchCourseVerticalChildrenData(blockId));
Expand Down
4 changes: 3 additions & 1 deletion src/course-unit/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ export const postXBlockBaseApiUrl = () => `${getStudioBaseUrl()}/xblock/`;
* @returns {Promise<Object>}
*/
export async function getCourseUnitData(unitId) {

Check failure on line 21 in src/course-unit/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Block must not be padded by blank lines

const { data } = await getAuthenticatedHttpClient()
.get(getCourseUnitApiUrl(unitId));

console.log('getCourseUnitData', data);

Check warning on line 25 in src/course-unit/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
return camelCaseObject(data);
}

Expand Down Expand Up @@ -156,6 +157,7 @@ export async function duplicateUnitItem(itemId, XBlockId) {
* @returns {Promise<any>} - A promise that resolves to the response data from the server.
*/
export async function rollbackUnitItem(itemId, xblockId) {
console.log('HELLOOOOOOOOO');

Check warning on line 160 in src/course-unit/data/api.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
const { data } = await getAuthenticatedHttpClient()
.patch(postXBlockBaseApiUrl(), {
parent_locator: itemId,
Expand Down
1 change: 1 addition & 0 deletions src/course-unit/data/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const slice = createSlice({
savingStatus: '',
isQueryPending: false,
isTitleEditFormOpen: false,
canEdit: true,
movedXBlockParams: {
isSuccess: false,
isUndo: false,
Expand Down
2 changes: 2 additions & 0 deletions src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check warning on line 270 in src/course-unit/data/thunk.js

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
dispatch(hideProcessingNotification());
dispatch(updateSavingStatus({ status: RequestStatus.FAILED }));
}
Expand Down

0 comments on commit c433bc0

Please sign in to comment.