Commit f842c42e authored by Duggan, John's avatar Duggan, John
Browse files

Clean up expand_directory and reset expanded list properly

parent a2ed058e
Loading
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -30,18 +30,23 @@ class DataSelectorViewModel:
        if paths[-1] in self.expanded:
            return

        # TODO: refactor/clean this up as it's confusing
        # Query for the new subdirectories to display in the view
        new_directories = self.model.get_directories(Path(paths[-1]))
        current_level: Any = self.directories

        # Find the entry in the existing directories that corresponds to the directory to expand
        current_level: Dict[str, Any] = {}
        children: List[Dict[str, Any]] = self.directories
        for current_path in paths:
            if isinstance(current_level, Dict):
                current_level = current_level["children"]
            if current_level:
                children = current_level["children"]

            for entry in current_level:
            for entry in children:
                if current_path == entry["path"]:
                    current_level = entry
                    break
        current_level["children"] = new_directories

        # Mark this directory as expanded and display the new content
        self.expanded.append(paths[-1])
        self.directories_bind.update_in_view(self.directories)

@@ -56,6 +61,7 @@ class DataSelectorViewModel:
    def reset(self) -> None:
        self.model.set_directory("")
        self.directories = self.model.get_directories()
        self.expanded = []
        self.reset_bind.update_in_view(None)

    def on_state_updated(self, results: Dict[str, Any]) -> None: