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

Feature/7600 - Scroll to newly created folder #9145

Merged
merged 3 commits into from
Jul 25, 2023

Conversation

pascalwengerter
Copy link
Contributor

@pascalwengerter pascalwengerter commented Jun 1, 2023

Description

Upstreams a CERN commit by @elizavetaRa which originates from before some major refactorings. It also reduces the scrollToResource arguments from a full resource where only the id would be used to a string/number.

Related Issue

@@ -66,12 +68,14 @@ export const useFileActionsCreateNewFolder = ({
resource.indicators = getIndicators({ resource, ancestorMetaData: unref(ancestorMetaData) })
}

store.commit('Files/UPSERT_RESOURCE', resource)
await store.commit('Files/UPSERT_RESOURCE', resource)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My IDE suggests there's no difference when using await here, however the scrolling only happens if you put it there 🤷🏽

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get that either... commit is a synchronous call / doesn't return a promise, so await makes no sense at all...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://stackoverflow.com/a/55263084

What you actually want is probably await nextTick()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thx for the hint!

const fileListWrapperElement = document.getElementsByClassName('files-view-wrapper')[0]
fileListWrapperElement.scrollBy(0, -resourceElement.offsetHeight)
}
resourceElement.scrollIntoView({ behavior: 'smooth', block: 'center' })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why all the other code was necessary tbh - scrolling to a resource and centering it on screen seems pretty straightforward, and if we need a "scroll to top" we should implement it explicitly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't work with active pagination though. if you're on page 3 and a just created folder is sorted into page 17 you would need to navigate to that page before trying to scroll...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah damn, I knew there was something I was missing (because otherwise that issue would've been resolved long ago already I suppose)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fine to split it into two issues btw. for this PR: assume that using scrollToResource is sufficient and declare it not checking pagination as bug. Then solve using pagination in scrollToResource as a separate PR.

Copy link
Contributor

@JammingBen JammingBen Jun 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why all the other code was necessary tbh - scrolling to a resource and centering it on screen seems pretty straightforward, and if we need a "scroll to top" we should implement it explicitly?

It was there for the keyboard navigation. Now when navigating via keyboard, it always immediately scrolls to the next resource. Before, it only scrolled when the resource was outside of the viewport. Both works, but I actually like the latter because it does not feel so "floaty". Maybe we can handling things a bit differently when working with keyboard navigation? Pass a param like forceScroll to the method which is false in case of keyboard navigation?

@elizavetaRa
Copy link
Member

Adding some opinion: scrolling to resource would also make sense when uploading a resource and even when creating new file that opens in new tab

@sonarcloud
Copy link

sonarcloud bot commented Jul 25, 2023

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 1 Bug
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

70.0% 70.0% Coverage
12.5% 12.5% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@pascalwengerter
Copy link
Contributor Author

Sonarcloud failure is unrelated to my changes? 🤔

Copy link
Contributor

@JammingBen JammingBen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@@ -46,6 +50,8 @@ describe('useFileActionsCreateNewFolder', () => {
title: '"myfolder" was created successfully'
})
)

// expect scrolltoresource to have been called
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something for a follow-up I propose 🙂

@JammingBen JammingBen merged commit 6aabd53 into owncloud:master Jul 25, 2023
@pascalwengerter pascalwengerter deleted the feature/7600 branch July 25, 2023 18:07
@elizavetaRa
Copy link
Member

@pascalwengerter @dschmidt it doesn't scroll when new folder is on another page

saw-jan pushed a commit that referenced this pull request Jul 27, 2023
* Fix #7600 && #7601

* Fix useFileActionsCreateNewFolder.spec.ts

* Fix unit tests

---------

Co-authored-by: Dominik Schmidt <[email protected]>
@JammingBen
Copy link
Contributor

@pascalwengerter @dschmidt it doesn't scroll when new folder is on another page

I've created #9494 to keep track of this. It's a bit more complex to achieve that.

AlexAndBear pushed a commit that referenced this pull request Aug 15, 2023
* Fix #7600 && #7601

* Fix useFileActionsCreateNewFolder.spec.ts

* Fix unit tests

---------

Co-authored-by: Dominik Schmidt <[email protected]>
AlexAndBear pushed a commit that referenced this pull request Dec 13, 2023
* Fix #7600 && #7601

* Fix useFileActionsCreateNewFolder.spec.ts

* Fix unit tests

---------

Co-authored-by: Dominik Schmidt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ScrollToResource function not working as expected No scrolling to just created folder
7 participants