Skip to content

Commit

Permalink
use set_view() in builtin view operations
Browse files Browse the repository at this point in the history
  • Loading branch information
brimoor committed Dec 21, 2024
1 parent b5a1aab commit a28b518
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions fiftyone/operators/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1769,15 +1769,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
Expand All @@ -1803,9 +1813,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()
Expand Down Expand Up @@ -1895,7 +1910,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",
Expand All @@ -1916,8 +1931,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
Expand Down Expand Up @@ -2366,6 +2385,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)
Expand Down

0 comments on commit a28b518

Please sign in to comment.