Skip to content
Closed
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: 17 additions & 7 deletions client/packages/lowcoder/src/comps/hooks/toastComp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { JSONObject } from "../../util/jsonTypes";
import { trans } from "i18n";
import { notificationInstance } from "lowcoder-design";
import type { ArgsProps, NotificationPlacement } from "antd/es/notification/interface";
import { executeQueryAction, routeByNameAction } from "lowcoder-core";
import type { DispatchType } from "lowcoder-core";

const params: ParamsConfig = [
{ name: "text", type: "string" },
Expand All @@ -14,24 +16,32 @@ const params: ParamsConfig = [

const showNotification = (
params: EvalParamType[],
level: "open" | "info" | "success" | "warning" | "error"
level: "open" | "info" | "success" | "warning" | "error",
dispatch?: DispatchType
) => {
const text = params?.[0] as string;
const options = (params?.[1] as JSONObject) || {};

const { message , duration, id, placement, dismissible } = options;
const { message, duration, id, placement, dismissible, onClose } = options;

const closeIcon: boolean | undefined = dismissible === true ? undefined : (dismissible === false ? false : undefined);

const durationNumberOrNull: number | null = typeof duration === 'number' ? duration : null;

const onCloseCallback = (): void => {
if (onClose && typeof onClose === 'string' && dispatch) {
dispatch(routeByNameAction(onClose, executeQueryAction({})));
}
};

const notificationArgs: ArgsProps = {
message: text,
description: message as React.ReactNode,
duration: durationNumberOrNull ?? 3,
key: id as React.Key,
placement: placement as NotificationPlacement ?? "bottomRight",
closeIcon: closeIcon as boolean,
onClose: onCloseCallback,
};

// Use notificationArgs to trigger the notification
Expand Down Expand Up @@ -63,31 +73,31 @@ ToastComp = withMethodExposing(ToastComp, [
{
method: { name: "open", description: trans("toastComp.info"), params: params },
execute: (comp, params) => {
showNotification(params, "open");
showNotification(params, "open", comp.dispatch);
},
},
{
method: { name: "info", description: trans("toastComp.info"), params: params },
execute: (comp, params) => {
showNotification(params, "info");
showNotification(params, "info", comp.dispatch);
},
},
{
method: { name: "success", description: trans("toastComp.success"), params: params },
execute: (comp, params) => {
showNotification(params, "success");
showNotification(params, "success", comp.dispatch);
},
},
{
method: { name: "warn", description: trans("toastComp.warn"), params: params },
execute: (comp, params) => {
showNotification(params, "warning");
showNotification(params, "warning", comp.dispatch);
},
},
{
method: { name: "error", description: trans("toastComp.error"), params: params },
execute: (comp, params) => {
showNotification(params, "error");
showNotification(params, "error", comp.dispatch);
},
},
]);
Expand Down
Loading