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 skip_prompt #4992

Merged
merged 2 commits into from
Oct 28, 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
24 changes: 15 additions & 9 deletions app/packages/operators/src/built-in-operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@
unlisted: true,
});
}
useHooks(ctx: ExecutionContext): {} {

Check warning on line 815 in app/packages/operators/src/built-in-operators.ts

View workflow job for this annotation

GitHub Actions / lint / eslint

'ctx' is defined but never used. Allowed unused args must match /^_/u
return { updatePanelState: useUpdatePanelStatePartial() };
}
async execute(ctx: ExecutionContext): Promise<void> {
Expand Down Expand Up @@ -1027,6 +1027,7 @@
inputs.obj("params", { label: "Params" });
inputs.str("on_success", { label: "On success" });
inputs.str("on_error", { label: "On error" });
inputs.bool("skip_prompt", { label: "Skip prompt", default: false });
return new types.Property(inputs);
}
useHooks(ctx: ExecutionContext): {} {
Expand All @@ -1037,22 +1038,27 @@
const { params, operator_uri, on_success, on_error } = ctx.params;
const { triggerEvent } = ctx.hooks;
const panelId = ctx.getCurrentPanelId();
const shouldPrompt = !ctx.params.skip_prompt;

triggerEvent(panelId, {
operator: operator_uri,
params,
prompt: true,
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 },
});
}
}
},
});
Expand Down
3 changes: 3 additions & 0 deletions fiftyone/operators/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand All @@ -767,6 +769,7 @@ def prompt(
"params": params,
"on_success": on_success,
"on_error": on_error,
"skip_prompt": skip_prompt,
}
),
)
Expand Down
Loading