Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [Breadcrumbs] Double scroll when selecting the last project #337

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const JobWizardFunctionSelection = ({
const [functionsRequestErrorMessage, setFunctionsRequestErrorMessage] = useState('')
const [hubFunctionsRequestErrorMessage, setHubFunctionsRequestErrorMessage] = useState('')
const selectedActiveTab = useRef(null)
const functionSelectionRef = useRef(null)
const functionsContainerRef = useRef(null)
const hubFunctionLoadedRef = useRef(false)

const filtersStoreHubCategories = useSelector(
Expand Down Expand Up @@ -362,14 +362,14 @@ const JobWizardFunctionSelection = ({
const isTabActive = selectedActiveTab.current && selectedActiveTab.current === activeTab

if (stepIsActive && isTabActive) {
scrollToElement(functionSelectionRef, '.selected')
scrollToElement(functionsContainerRef, '.selected')
} else if (!stepIsActive && !isTabActive) {
setActiveTab(selectedActiveTab.current)
}
}, [stepIsActive, activeTab, setActiveTab, selectedActiveTab])

return (
<div ref={functionSelectionRef} className="job-wizard__function-selection">
<div className="job-wizard__function-selection">
<div className="form-row">
<h5 className="form-step-title">Function selection</h5>
</div>
Expand Down Expand Up @@ -404,7 +404,7 @@ const JobWizardFunctionSelection = ({
isEmpty(functions)) ? (
<NoData message={functionsRequestErrorMessage} />
) : (
<div className="functions-list">
<div className="functions-list" ref={functionsContainerRef}>
{(filteredFunctions.length > 0 ? filteredFunctions : functions)
.sort((prevFunc, nextFunc) => prevFunc.name.localeCompare(nextFunc.name))
.map(functionData => {
Expand Down Expand Up @@ -455,7 +455,7 @@ const JobWizardFunctionSelection = ({
isEmpty(templates)) ? (
<NoData message={hubFunctionsRequestErrorMessage} />
) : (
<div className="functions-list">
<div className="functions-list" ref={functionsContainerRef}>
{filteredTemplates
.sort((prevTemplate, nextTemplate) =>
prevTemplate.metadata.name.localeCompare(nextTemplate.metadata.name)
Expand Down
23 changes: 18 additions & 5 deletions src/utils/scroll.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,23 @@ export const scrollToElement = (
shouldScrollToTop
? parentRef.current.scrollTo({ top: 0, left: 0, behavior: 'smooth' })
: setTimeout(() => {
selectedElement.scrollIntoView({
behavior: 'smooth',
block: 'center',
inline: 'start'
})
scrollToCenter(parentRef?.current, selectedElement)
}, timeoutDuration)
}

const scrollToCenter = (container, element) => {
const containerRect = container.getBoundingClientRect()
const elementRect = element.getBoundingClientRect()

const scrollTop =
container.scrollTop +
elementRect.top -
containerRect.top -
container.clientHeight / 2 +
elementRect.height / 2

container.scrollTo({
top: scrollTop,
behavior: 'smooth'
})
}
Loading