From 91ba00346ced01b49930c3eb49fbf0dfbf767528 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Wed, 29 Nov 2023 13:44:15 -0500 Subject: [PATCH] feat: add auto scroll to new sections when created fix: rename util function and remove unused eslint comment fix: fix tests by mocking scrollIntoView function test: add assertion for checking call to mock function --- src/course-outline/CourseOutline.jsx | 9 ++++++++- src/course-outline/CourseOutline.test.jsx | 3 +++ src/course-outline/section-card/SectionCard.jsx | 15 ++++++++++----- src/course-outline/utils.jsx | 5 +++++ 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/course-outline/CourseOutline.jsx b/src/course-outline/CourseOutline.jsx index dd9c5f65d..ccdd7fce0 100644 --- a/src/course-outline/CourseOutline.jsx +++ b/src/course-outline/CourseOutline.jsx @@ -1,4 +1,4 @@ -import React from 'react'; +import { React, useEffect, useRef } from 'react'; import PropTypes from 'prop-types'; import { useIntl } from '@edx/frontend-platform/i18n'; import { @@ -34,8 +34,10 @@ import ConfigureModal from './configure-modal/ConfigureModal'; import DeleteModal from './delete-modal/DeleteModal'; import { useCourseOutline } from './hooks'; import messages from './messages'; +import { scrollToElement } from './utils'; const CourseOutline = ({ courseId }) => { + const listRef = useRef(null); const intl = useIntl(); const { @@ -77,6 +79,10 @@ const CourseOutline = ({ courseId }) => { handleNewSectionSubmit, } = useCourseOutline({ courseId }); + useEffect(() => { + scrollToElement(listRef); + }, [sectionsList]); + const { isShow: isShowProcessingNotification, title: processingNotificationTitle, @@ -155,6 +161,7 @@ const CourseOutline = ({ courseId }) => { onEditSectionSubmit={handleEditSectionSubmit} onDuplicateSubmit={handleDuplicateSectionSubmit} isSectionsExpanded={isSectionsExpanded} + ref={listRef} /> ))}