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
Filebrowser paging draft #539
base: main
Are you sure you want to change the base?
Conversation
Thanks for submitting your first pull request! You are awesome! 🤗 |
@@ -106,9 +106,13 @@ async def get(self, path=''): | |||
if content not in {'0', '1'}: | |||
raise web.HTTPError(400, u'Content %r is invalid' % content) | |||
content = int(content) | |||
|
|||
page = self.get_query_argument('page', default='1') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably be more backwards compatible if it defaulted to not being paginated if the page argument is not given.
|
||
if len_contents > MAX_NUM_CONTENTS_PAGE: | ||
# round up the max number of pages | ||
max_page = int(len_contents / MAX_NUM_CONTENTS_PAGE) + (len_contents % MAX_NUM_CONTENTS_PAGE > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there'a handy function for calculating both div and mod.
pages, contents_remainder = divmod(len_contents, MAX_NUM_CONTENTS_PAGE)
max_page = pages + contents_remainder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the divmod function! The value of max_page
should be the same as math.ceil(len_contents / MAX_NUM_CONTENTS_PAGE)
, so max_page = pages + contents_remainder
isn't correct actually.
# round up the max number of pages | ||
max_page = int(len_contents / MAX_NUM_CONTENTS_PAGE) + (len_contents % MAX_NUM_CONTENTS_PAGE > 0) | ||
model["max_page"] = max_page | ||
if page and (1 <= page) and (page <= max_page) : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a way to combine the comparison operators.
It's also good to explicitly check if page is None because page = 0 can silently return False in this case.
if page is not None and 1 <= page <= max_page:
Hi @cnydw, any updates on this? It'd be great to make the filebrowser experience more performant. |
I made a simple update, however I feel my paging design is far from ideal. The paging design like #538 (comment) isn't very intuitive. Most file browsers don't have pages, instead they only utilize the scrollbar. A better design would probably abandon the page selection, and will look just like the original file browser. When opening a folder, It will display a small number of files, and when the scrollbar moves to the end, it activates loading more items (if there is any). However this scrollbar activated design will probably not work with my current simple implementation in the jupyter_server backend. More discussion with JupyterLab side is probably needed. |
Addressing issue #538
Added a
page
parameter to the request, to select the pages.The updated API is not mature , would love to hear suggestions.