From 26665b9e9fed5684dae9df2c437df67b1bad5ade Mon Sep 17 00:00:00 2001 From: brimoor Date: Tue, 10 Dec 2024 10:18:05 -0500 Subject: [PATCH] add_path_to_sidebar_group util --- fiftyone/core/dataset.py | 37 +++++++---------------------------- fiftyone/core/odm/dataset.py | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/fiftyone/core/dataset.py b/fiftyone/core/dataset.py index 9db20ee4c44..638ec5ed3f9 100644 --- a/fiftyone/core/dataset.py +++ b/fiftyone/core/dataset.py @@ -46,7 +46,7 @@ import fiftyone.core.media as fom import fiftyone.core.metadata as fome from fiftyone.core.odm.dataset import SampleFieldDocument -from fiftyone.core.odm.dataset import DatasetAppConfig, SidebarGroupDocument +from fiftyone.core.odm.dataset import DatasetAppConfig import fiftyone.migrations as fomi import fiftyone.core.odm as foo import fiftyone.core.sample as fos @@ -1866,35 +1866,12 @@ def create_summary_field( if sidebar_group is None: sidebar_group = "summaries" - if self.app_config.sidebar_groups is None: - sidebar_groups = DatasetAppConfig.default_sidebar_groups(self) - self.app_config.sidebar_groups = sidebar_groups - else: - sidebar_groups = self.app_config.sidebar_groups - - index_group = None - for group in sidebar_groups: - if group.name == sidebar_group: - index_group = group - else: - if field_name in group.paths: - group.paths.remove(field_name) - - if index_group is None: - index_group = SidebarGroupDocument(name=sidebar_group) - - insert_after = None - for i, group in enumerate(sidebar_groups): - if group.name == "labels": - insert_after = i - - if insert_after is None: - sidebar_groups.append(index_group) - else: - sidebar_groups.insert(insert_after + 1, index_group) - - if field_name not in index_group.paths: - index_group.paths.append(field_name) + self.app_config._add_path_to_sidebar_group( + field_name, + sidebar_group, + after_group="labels", + dataset=self, + ) if create_index: for _field_name in index_fields: diff --git a/fiftyone/core/odm/dataset.py b/fiftyone/core/odm/dataset.py index bb25a907c04..559306e5c6f 100644 --- a/fiftyone/core/odm/dataset.py +++ b/fiftyone/core/odm/dataset.py @@ -624,6 +624,44 @@ def _rename_paths(self, paths, new_paths): for path, new_path in zip(paths, new_paths): self._rename_path(path, new_path) + def _add_path_to_sidebar_group( + self, + path, + sidebar_group, + after_group=None, + dataset=None, + ): + if self.sidebar_groups is None: + if dataset is None: + return + + self.sidebar_groups = self.default_sidebar_groups(dataset) + + index_group = None + for group in self.sidebar_groups: + if group.name == sidebar_group: + index_group = group + else: + if path in group.paths: + group.paths.remove(path) + + if index_group is None: + index_group = SidebarGroupDocument(name=sidebar_group) + + insert_after = None + if after_group is not None: + for i, group in enumerate(self.sidebar_groups): + if group.name == after_group: + insert_after = i + + if insert_after is None: + self.sidebar_groups.append(index_group) + else: + self.sidebar_groups.insert(insert_after + 1, index_group) + + if path not in index_group.paths: + index_group.paths.append(path) + def _make_default_sidebar_groups(sample_collection): # Possible sidebar groups