Skip to content

Commit

Permalink
fix: [AXIMST-516] fixed paste alerts view (#189)
Browse files Browse the repository at this point in the history
refactor: code refactoring

refactor: code refactoring
  • Loading branch information
PKulkoRaccoonGang committed Mar 10, 2024
1 parent f771654 commit af87165
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/course-unit/CourseUnit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ const CourseUnit = ({ courseId }) => {
icon={WarningIcon}
/>
)}
<PasteNotificationAlert
staticFileNotices={staticFileNotices}
courseId={courseId}
/>
{staticFileNotices && (
<PasteNotificationAlert
staticFileNotices={staticFileNotices}
courseId={courseId}
/>
)}
<Stack gap={4} className="mb-4">
{courseVerticalChildren.children.map(({ name, blockId: id, shouldScroll }) => (
<CourseXBlock
Expand Down
5 changes: 4 additions & 1 deletion src/course-unit/CourseUnit.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('<CourseUnit />', () => {
roles: [],
},
});

global.localStorage.clear();
store = initializeStore();
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock
Expand Down Expand Up @@ -1156,6 +1156,7 @@ describe('<CourseUnit />', () => {
...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');
Expand Down Expand Up @@ -1219,6 +1220,7 @@ describe('<CourseUnit />', () => {
...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');
Expand Down Expand Up @@ -1282,6 +1284,7 @@ describe('<CourseUnit />', () => {
...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');
Expand Down
1 change: 0 additions & 1 deletion src/course-unit/data/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 3 additions & 2 deletions src/course-unit/data/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit af87165

Please sign in to comment.