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

add set_spaces operation #4381

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion app/packages/operators/src/built-in-operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import * as fos from "@fiftyone/state";
import * as types from "./types";

import { LOAD_WORKSPACE_OPERATOR } from "@fiftyone/spaces/src/components/Workspaces/constants";
import { toSlug } from "@fiftyone/utilities";
import copyToClipboard from "copy-to-clipboard";
import { useSetRecoilState } from "recoil";
Expand Down Expand Up @@ -771,7 +772,14 @@ class SetSpaces extends Operator {
return { setSessionSpacesState };
}
async execute(ctx: ExecutionContext) {
ctx.hooks.setSessionSpacesState(ctx.params.spaces);
const { name, spaces } = ctx.params || {};
if (spaces) {
ctx.hooks.setSessionSpacesState(spaces);
} else if (name) {
executeOperator(LOAD_WORKSPACE_OPERATOR, { name }, { skipOutput: true });
} else {
throw new Error('Param "spaces" or "name" is required to set a space');
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions fiftyone/operators/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,7 @@ def resolve_input(self, ctx):

def execute(self, ctx):
name = ctx.params.get("name", None)
spaces = ctx.dataset.load_workspace(name)
ctx.trigger("set_spaces", {"spaces": spaces.to_dict()})
ctx.ops.set_spaces(name=name)
return {}


Expand Down
16 changes: 16 additions & 0 deletions fiftyone/operators/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
| `voxel51.com <https://voxel51.com/>`_
|
"""

import json

from bson import json_util
Expand Down Expand Up @@ -316,6 +317,21 @@ def clear_selected_labels(self):
"""Clear the selected labels in the App."""
return self._ctx.trigger("clear_selected_labels")

def set_spaces(self, spaces=None, name=None):
"""Set space in the App by name or :class:`fiftyone.core.odm.workspace.Space`.
Args:
spaces: the spaces (:class:`fiftyone.core.odm.workspace.Space`) to load
name: the name of the workspace to load
"""
params = {}
if spaces is not None:
params["spaces"] = spaces.to_dict()
elif name is not None:
params["spaces"] = self._ctx.dataset.load_workspace(name).to_dict()

return self._ctx.trigger("set_spaces", params=params)


def _serialize_view(view):
return json.loads(json_util.dumps(view._serialize()))
Loading