From 049667b8e5cc9031538cdce67329702467eb4e32 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Fri, 25 Oct 2024 12:08:28 -0700 Subject: [PATCH 1/2] add skip prompt --- app/packages/operators/src/built-in-operators.ts | 4 +++- fiftyone/operators/executor.py | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/packages/operators/src/built-in-operators.ts b/app/packages/operators/src/built-in-operators.ts index ae210641fd..9babd7529c 100644 --- a/app/packages/operators/src/built-in-operators.ts +++ b/app/packages/operators/src/built-in-operators.ts @@ -1027,6 +1027,7 @@ class PromptUserForOperation extends Operator { inputs.obj("params", { label: "Params" }); inputs.str("on_success", { label: "On success" }); inputs.str("on_error", { label: "On error" }); + inputs.str("skip_prompt", { label: "Skip prompt", default: false }); return new types.Property(inputs); } useHooks(ctx: ExecutionContext): {} { @@ -1037,11 +1038,12 @@ class PromptUserForOperation extends Operator { const { params, operator_uri, on_success, on_error } = ctx.params; const { triggerEvent } = ctx.hooks; const panelId = ctx.getCurrentPanelId(); + const shouldPrompt = !params.skip_prompt; triggerEvent(panelId, { operator: operator_uri, params, - prompt: true, + prompt: shouldPrompt, callback: (result: OperatorResult) => { if (result.error) { triggerEvent(panelId, { diff --git a/fiftyone/operators/executor.py b/fiftyone/operators/executor.py index 50c177f423..9ff9d46d69 100644 --- a/fiftyone/operators/executor.py +++ b/fiftyone/operators/executor.py @@ -744,6 +744,7 @@ def prompt( params=None, on_success=None, on_error=None, + skip_prompt=False, ): """Prompts the user to execute the operator with the given URI. @@ -753,6 +754,7 @@ def prompt( on_success (None): a callback to invoke if the user successfully executes the operator on_error (None): a callback to invoke if the execution fails + skip_prompt (False): whether to skip the prompt Returns: a :class:`fiftyone.operators.message.GeneratedMessage` containing From 1285df767cff179a8447e473821a9e2dd2cfb6d1 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Mon, 28 Oct 2024 14:17:31 -0700 Subject: [PATCH 2/2] skip_prompt fixes --- .../operators/src/built-in-operators.ts | 24 +++++++++++-------- fiftyone/operators/executor.py | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/packages/operators/src/built-in-operators.ts b/app/packages/operators/src/built-in-operators.ts index 9babd7529c..99d99b1d46 100644 --- a/app/packages/operators/src/built-in-operators.ts +++ b/app/packages/operators/src/built-in-operators.ts @@ -1027,7 +1027,7 @@ class PromptUserForOperation extends Operator { inputs.obj("params", { label: "Params" }); inputs.str("on_success", { label: "On success" }); inputs.str("on_error", { label: "On error" }); - inputs.str("skip_prompt", { label: "Skip prompt", default: false }); + inputs.bool("skip_prompt", { label: "Skip prompt", default: false }); return new types.Property(inputs); } useHooks(ctx: ExecutionContext): {} { @@ -1038,7 +1038,7 @@ class PromptUserForOperation extends Operator { const { params, operator_uri, on_success, on_error } = ctx.params; const { triggerEvent } = ctx.hooks; const panelId = ctx.getCurrentPanelId(); - const shouldPrompt = !params.skip_prompt; + const shouldPrompt = !ctx.params.skip_prompt; triggerEvent(panelId, { operator: operator_uri, @@ -1046,15 +1046,19 @@ class PromptUserForOperation extends Operator { prompt: shouldPrompt, callback: (result: OperatorResult) => { if (result.error) { - triggerEvent(panelId, { - operator: on_error, - params: { error: result.error }, - }); + if (on_error) { + triggerEvent(panelId, { + operator: on_error, + params: { error: result.error }, + }); + } } else { - triggerEvent(panelId, { - operator: on_success, - params: { result: result.result }, - }); + if (on_success) { + triggerEvent(panelId, { + operator: on_success, + params: { result: result.result }, + }); + } } }, }); diff --git a/fiftyone/operators/executor.py b/fiftyone/operators/executor.py index 9ff9d46d69..40a43eb07f 100644 --- a/fiftyone/operators/executor.py +++ b/fiftyone/operators/executor.py @@ -769,6 +769,7 @@ def prompt( "params": params, "on_success": on_success, "on_error": on_error, + "skip_prompt": skip_prompt, } ), )