From 36a19593b3cb7418635330fc2d96c380578c812e Mon Sep 17 00:00:00 2001 From: brimoor Date: Mon, 21 Oct 2024 22:40:58 -0400 Subject: [PATCH] use set_view() in builtin view operations --- fiftyone/operators/builtin.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/fiftyone/operators/builtin.py b/fiftyone/operators/builtin.py index 57783f0842..66bff01c27 100644 --- a/fiftyone/operators/builtin.py +++ b/fiftyone/operators/builtin.py @@ -1690,15 +1690,25 @@ def execute(self, ctx): name = ctx.params.get("name", None) description = ctx.params.get("description", None) color = ctx.params.get("color", None) + view = ctx.params.get("view", None) + + curr_view = view is None + if curr_view: + view = ctx.view + else: + view = _parse_view(ctx, view) ctx.dataset.save_view( name, - ctx.view, + view, description=description, color=color, overwrite=True, ) + if curr_view: + ctx.ops.set_view(name=name) + class EditSavedViewInfo(foo.Operator): @property @@ -1724,9 +1734,14 @@ def execute(self, ctx): description = ctx.params.get("description", None) color = ctx.params.get("color", None) + curr_name = ctx.view.name info = dict(name=new_name, description=description, color=color) + ctx.dataset.update_saved_view_info(name, info) + if curr_name is not None and curr_name != new_name: + ctx.ops.set_view(name=new_name) + def _edit_saved_view_info_inputs(ctx, inputs): saved_views = ctx.dataset.list_saved_views() @@ -1816,7 +1831,7 @@ def resolve_input(self, ctx): inputs.enum( "name", saved_view_selector.values(), - default=None, + default=ctx.view.name, required=True, label="Saved view", description="The saved view to delete", @@ -1837,8 +1852,12 @@ def resolve_input(self, ctx): def execute(self, ctx): name = ctx.params["name"] + curr_view = name == ctx.view.name ctx.dataset.delete_saved_view(name) + if curr_view: + ctx.ops.set_view(view=ctx.dataset.view()) + class ListWorkspaces(foo.Operator): @property @@ -2287,6 +2306,13 @@ def _get_non_default_frame_fields(dataset): return schema +def _parse_view(ctx, view): + if isinstance(view, str): + view = json.loads(view) + + return fo.DatasetView._build(ctx.dataset, view) + + def _parse_spaces(ctx, spaces): if isinstance(spaces, str): spaces = json.loads(spaces)