Skip to content

Commit

Permalink
Merge pull request #5251 from voxel51/add-path-to-sidebar-group
Browse files Browse the repository at this point in the history
Utility for adding a path to a sidebar group
  • Loading branch information
brimoor authored Dec 12, 2024
2 parents 9fae650 + fe56fb3 commit c4df037
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 31 deletions.
38 changes: 7 additions & 31 deletions fiftyone/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
import fiftyone.core.labels as fol
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
Expand Down Expand Up @@ -1866,35 +1865,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:
Expand Down
38 changes: 38 additions & 0 deletions fiftyone/core/odm/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4df037

Please sign in to comment.