From f4ef424c37d34517abaaa79ef0f92cc5f0acc7e5 Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Mon, 5 Feb 2024 17:20:47 +0100 Subject: [PATCH] feat(frontend): add support for toasts in frontend scripts (#3147) * feat(frontend): add support for toast in frontend scripts * feat(frontend): add support for toast in frontend scripts * feat(frontend): fix comment * Update eval.ts * Update eval.ts * Update utils.ts * Update utils.ts --------- Co-authored-by: Ruben Fiszel --- .../src/lib/components/apps/components/helpers/eval.ts | 8 ++++++-- frontend/src/lib/components/apps/utils.ts | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/apps/components/helpers/eval.ts b/frontend/src/lib/components/apps/components/helpers/eval.ts index b59e05364c..19b21a57cc 100644 --- a/frontend/src/lib/components/apps/components/helpers/eval.ts +++ b/frontend/src/lib/components/apps/components/helpers/eval.ts @@ -20,7 +20,7 @@ export function computeGlobalContext(world: World | undefined, extraContext: any function create_context_function_template(eval_string: string, context, noReturn: boolean) { return ` -return async function (context, state, goto, setTab, recompute, getAgGrid, setValue, setSelectedIndex, openModal, closeModal, open, close, validate, invalidate, validateAll, clearFiles) { +return async function (context, state, goto, setTab, recompute, getAgGrid, setValue, setSelectedIndex, openModal, closeModal, open, close, validate, invalidate, validateAll, clearFiles, showToast) { "use strict"; ${ Object.keys(context).length > 0 @@ -56,7 +56,8 @@ function make_context_evaluator( validate, invalidate, validateAll, - clearFiles + clearFiles, + showToast ) => Promise { let template = create_context_function_template(eval_string, context, noReturn) let functor = Function(template) @@ -192,6 +193,9 @@ export async function eval_like( }, (id) => { controlComponents[id]?.clearFiles?.() + }, + (message, error) => { + sendUserToast(message, error) } ) } diff --git a/frontend/src/lib/components/apps/utils.ts b/frontend/src/lib/components/apps/utils.ts index d91bf298c9..dca1bf7cd5 100644 --- a/frontend/src/lib/components/apps/utils.ts +++ b/frontend/src/lib/components/apps/utils.ts @@ -199,7 +199,6 @@ declare function recompute(id: string): void; */ declare function getAgGrid(id: string): {api: any, columnApi: any} | undefined; - /** set value of a component * @param id component's id * @param value value to set @@ -245,6 +244,10 @@ declare function validateAll(id: string, key: number): void; */ declare function clearFiles(id: string): void; +/** Display a toast message + * @param message message to display + */ +declare function showToast(message: string, error: boolean): void; ` : '' }