From af87165041d3cc2988e93e1680ce3fa4b9fc2bbe Mon Sep 17 00:00:00 2001 From: Peter Kulko <93188219+PKulkoRaccoonGang@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:38:56 +0200 Subject: [PATCH] fix: [AXIMST-516] fixed paste alerts view (#189) refactor: code refactoring refactor: code refactoring --- src/course-unit/CourseUnit.jsx | 10 ++++++---- src/course-unit/CourseUnit.test.jsx | 5 ++++- src/course-unit/data/selectors.js | 1 - src/course-unit/data/thunk.js | 5 +++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/course-unit/CourseUnit.jsx b/src/course-unit/CourseUnit.jsx index 04168858bf..6394a1b1ac 100644 --- a/src/course-unit/CourseUnit.jsx +++ b/src/course-unit/CourseUnit.jsx @@ -111,10 +111,12 @@ const CourseUnit = ({ courseId }) => { icon={WarningIcon} /> )} - + {staticFileNotices && ( + + )} {courseVerticalChildren.children.map(({ name, blockId: id, shouldScroll }) => ( ', () => { roles: [], }, }); - + global.localStorage.clear(); store = initializeStore(); axiosMock = new MockAdapter(getAuthenticatedHttpClient()); axiosMock @@ -1156,6 +1156,7 @@ describe('', () => { ...updatedCourseSectionVerticalData, }); + global.localStorage.setItem('staticFileNotices', JSON.stringify(clipboardMockResponse.staticFileNotices)); await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch); await executeThunk(createNewCourseXBlock(camelCaseObject(postXBlockBody), null, blockId), store.dispatch); const newFilesAlert = getByTestId('has-new-files-alert'); @@ -1219,6 +1220,7 @@ describe('', () => { ...updatedCourseSectionVerticalData, }); + global.localStorage.setItem('staticFileNotices', JSON.stringify(clipboardMockResponse.staticFileNotices)); await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch); await executeThunk(createNewCourseXBlock(camelCaseObject(postXBlockBody), null, blockId), store.dispatch); const conflictingErrorsAlert = getByTestId('has-conflicting-errors-alert'); @@ -1282,6 +1284,7 @@ describe('', () => { ...updatedCourseSectionVerticalData, }); + global.localStorage.setItem('staticFileNotices', JSON.stringify(clipboardMockResponse.staticFileNotices)); await executeThunk(fetchCourseSectionVerticalData(blockId), store.dispatch); await executeThunk(createNewCourseXBlock(camelCaseObject(postXBlockBody), null, blockId), store.dispatch); const errorFilesAlert = getByTestId('has-error-files-alert'); diff --git a/src/course-unit/data/selectors.js b/src/course-unit/data/selectors.js index f5365d0fa9..da28174293 100644 --- a/src/course-unit/data/selectors.js +++ b/src/course-unit/data/selectors.js @@ -11,4 +11,3 @@ export const getCourseId = state => state.courseDetail.courseId; export const getSequenceId = state => state.courseUnit.sequenceId; export const getCourseVerticalChildren = state => state.courseUnit.courseVerticalChildren; export const getClipboardData = state => state.courseUnit.clipboardData; -export const getCourseUnitEnableCopyPaste = state => state.courseUnit.unit.enableCopyPasteUnits; diff --git a/src/course-unit/data/thunk.js b/src/course-unit/data/thunk.js index c42deb52d0..f3f39b0c80 100644 --- a/src/course-unit/data/thunk.js +++ b/src/course-unit/data/thunk.js @@ -74,9 +74,10 @@ export function fetchCourseSectionVerticalData(courseId, sequenceId) { modelType: 'units', models: courseSectionVerticalData.units, })); + dispatch(fetchStaticFileNoticesSuccess(JSON.parse(localStorage.getItem('staticFileNotices')))); + localStorage.removeItem('staticFileNotices'); dispatch(updateClipboardData(courseSectionVerticalData.userClipboard)); dispatch(fetchSequenceSuccess({ sequenceId })); - dispatch(fetchStaticFileNoticesSuccess([])); return true; } catch (error) { dispatch(updateLoadingCourseSectionVerticalDataStatus({ status: RequestStatus.FAILED })); @@ -164,7 +165,7 @@ export function createNewCourseXBlock(body, callback, blockId) { dispatch(fetchCourseSectionVerticalDataSuccess(courseSectionVerticalData)); } if (body.stagedContent) { - dispatch(fetchStaticFileNoticesSuccess(formattedResult.staticFileNotices)); + localStorage.setItem('staticFileNotices', JSON.stringify(formattedResult.staticFileNotices)); } const courseVerticalChildrenData = await getCourseVerticalChildren(blockId); dispatch(updateCourseVerticalChildren(courseVerticalChildrenData));