Skip to content

Commit

Permalink
fix: don't change folder when new folder is parent of root. closes #862
Browse files Browse the repository at this point in the history
  • Loading branch information
dfguerrerom committed Aug 7, 2023
1 parent b26c7d6 commit 9a2b8ca
Showing 1 changed file with 7 additions and 22 deletions.
29 changes: 7 additions & 22 deletions sepal_ui/sepalwidgets/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
reason="Empty v_model will be treated as empty string: :code:`v_model=''`.",
)
class DatePicker(v.Layout, SepalWidget):

menu: Optional[v.Menu] = None
"the menu widget to display the datepicker"

Expand Down Expand Up @@ -178,7 +177,6 @@ def is_valid_date(date: str) -> bool:


class FileInput(v.Flex, SepalWidget):

extensions: List[str] = []
"list: the extensions list"

Expand Down Expand Up @@ -330,7 +328,6 @@ def reset(self, *args) -> Self:
# do nothing if nothing is set to avoids extremely long waiting
# time when multiple fileInput are reset at the same time as in the aoiView
if self.v_model is not None:

# move to root
self._on_file_select({"new": Path.home()})

Expand Down Expand Up @@ -369,7 +366,10 @@ def _on_file_select(self, change: dict) -> Self:

if new_value.is_dir():
self.folder = new_value
self._change_folder()

# don't change folder if the folder is the parent of the root
if not self.folder == Path(self.root).parent:
self._change_folder()

elif new_value.is_file():
self.file = str(new_value)
Expand Down Expand Up @@ -410,7 +410,6 @@ def _get_items(self) -> List[v.ListItem]:
file_list = []

for el in list_dir:

if el.is_dir():
icon = self.ICON_STYLE[""]["icon"]
color = self.ICON_STYLE[""]["color"][v.theme.dark]
Expand Down Expand Up @@ -439,10 +438,7 @@ def _get_items(self) -> List[v.ListItem]:

folder_list = humansorted(folder_list, key=lambda x: x.value)
file_list = humansorted(file_list, key=lambda x: x.value)
folder_list.extend(file_list)

# add the parent item if root is set and is not reached yet
# if root is not set then we always display it
parent_item = v.ListItem(
value=str(folder.parent),
children=[
Expand All @@ -459,16 +455,13 @@ def _get_items(self) -> List[v.ListItem]:
),
],
)
root_folder = Path(self.root)
if self.root == "":
folder_list.insert(0, parent_item)
elif root_folder in folder.parents:
folder_list.insert(0, parent_item)

folder_list.extend(file_list)
folder_list.insert(0, parent_item)

return folder_list

def _on_reload(self, *args) -> None:

# force the update of the current folder
self._change_folder()

Expand All @@ -484,7 +477,6 @@ def close_menu(self, change: dict) -> None:


class LoadTableField(v.Col, SepalWidget):

fileInput: Optional[FileInput] = None
"The file input to select the .csv or .txt file"

Expand Down Expand Up @@ -638,7 +630,6 @@ def _set_v_model(self, key: str, value: Any) -> None:


class AssetSelect(v.Combobox, SepalWidget):

TYPES: dict = {
"IMAGE": ms.widgets.asset_select.types[0],
"TABLE": ms.widgets.asset_select.types[1],
Expand Down Expand Up @@ -723,7 +714,6 @@ def _validate(self, change: dict) -> None:
self.v_model = self.v_model.strip()

if change["new"]:

# check that the asset can be accessed
try:
self.asset_info = ee.data.getAsset(self.v_model)
Expand All @@ -735,7 +725,6 @@ def _validate(self, change: dict) -> None:
)

except Exception:

self.error_messages = ms.widgets.asset_select.no_access

self.valid = self.error_messages is None
Expand All @@ -745,13 +734,11 @@ def _validate(self, change: dict) -> None:

@sd.switch("loading", "disabled")
def _get_items(self, *args) -> Self:

# init the item list
items = []

# add the default values if needed
if self.default_asset:

if isinstance(self.default_asset, str):
self.default_asset = [self.default_asset]

Expand Down Expand Up @@ -828,7 +815,6 @@ def _toggle_pwd(self, *args) -> None:


class NumberField(v.TextField, SepalWidget):

max_: t.Int = t.Int(10).tag(sync=True)
"Maximum selectable number."

Expand Down Expand Up @@ -879,7 +865,6 @@ def decrement(self, *args) -> None:


class VectorField(v.Col, SepalWidget):

original_gdf: Optional[gpd.GeoDataFrame] = None
"The originally selected dataframe"

Expand Down

0 comments on commit 9a2b8ca

Please sign in to comment.