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 authored Mar 1, 2024
1 parent 2d2073a commit 6c8f4ca
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 @@ -140,10 +140,12 @@ const CourseUnit = ({ courseId }) => {
icon={WarningIcon}
/>
)}
<PasteNotificationAlert
staticFileNotices={staticFileNotices}
courseId={courseId}
/>
{staticFileNotices && (
<PasteNotificationAlert
staticFileNotices={staticFileNotices}
courseId={courseId}
/>
)}
<Stack gap={4} className="mb-4 course-unit__xblocks">
<DraggableList
itemList={unitXBlocks}
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 @@ -97,7 +97,7 @@ describe('<CourseUnit />', () => {
roles: [],
},
});

global.localStorage.clear();
store = initializeStore();
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock
Expand Down Expand Up @@ -1159,6 +1159,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 @@ -1222,6 +1223,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 @@ -1285,6 +1287,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 @@ -10,4 +10,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 @@ -76,9 +76,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 @@ -166,7 +167,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 6c8f4ca

Please sign in to comment.