fix: FileBrowser bug when navigating to path root#707
fix: FileBrowser bug when navigating to path root#707maartenbreddels merged 2 commits intowidgetti:masterfrom
Conversation
|
I have a use case where I want to run an app on a server and show files/folders on the server in a given directory. However, the user should not be able to navigate to parent directories above the starting directory. I've currently implemented it as: @solara.component
def Page():
my_dir = Path.cwd()
def browser_filter(path: Path) -> bool:
if path.is_dir():
return path not in my_dir.parents
return True
MyFileBrowser(directory=my_dir, directory_first=True, filter=browser_filter)Which then requires an additional check on new_dir = current_dir.value.parent
if not filter(new_dir):
returnI can add this to this PR or make another one if you think it would be more generally useful. |
|
beautifull fix! |
|
here is the link to pycafe the fix in the issue you mention does indeed work. However, given that the function of |
|
I don't think I fully understand the problem, can you show an example that does not work? |
import solara
from pathlib import Path
BASE_PATH = Path.cwd()
@solara.component
def Page():
directory = solara.use_reactive(BASE_PATH)
def protect_filter(path: Path) -> bool:
if path.is_dir():
return path not in BASE_PATH.parents
return True
solara.FileBrowser(directory, filter=protect_filter)In this example, based on how you interpret the docstring of |
Fixes #688
The PR changes the type of paths used internally in
FileBrowserfromstrtopathlib.Pathsuch that the correct parent is always returned.Also fixed optional kwargs typing