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 <ruben@windmill.dev>
This commit is contained in:
Faton Ramadani
2024-02-05 17:20:47 +01:00
committed by GitHub
parent 41ec53eb9a
commit f4ef424c37
2 changed files with 10 additions and 3 deletions
@@ -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<any> {
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)
}
)
}
+4 -1
View File
@@ -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;
`
: ''
}