Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use set_view() in builtin view operations #4960

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions plugins/operators/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1766,15 +1766,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 @@ -1800,9 +1810,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 @@ -1892,7 +1907,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 @@ -1913,8 +1928,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 @@ -2363,6 +2382,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
Loading