This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new 51a08ae92 feat: support hide custom type toast in operator (#6879)
51a08ae92 is described below
commit 51a08ae92f342bd351ecd581e325eb3a30f57be5
Author: 青湛 <[email protected]>
AuthorDate: Fri Jan 26 18:31:06 2024 +1300
feat: support hide custom type toast in operator (#6879)
---
config-ui/src/utils/operator.ts | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/config-ui/src/utils/operator.ts b/config-ui/src/utils/operator.ts
index 1f570bb02..e14263b4f 100644
--- a/config-ui/src/utils/operator.ts
+++ b/config-ui/src/utils/operator.ts
@@ -23,6 +23,8 @@ export type OperateConfig = {
formatMessage?: () => string;
formatReason?: (err: unknown) => string;
hideToast?: boolean;
+ hideSuccessToast?: boolean;
+ hideErrorToast?: boolean;
};
/**
@@ -32,6 +34,9 @@ export type OperateConfig = {
* @param config.setOperating -> Control the status of the request
* @param config.formatMessage -> Show the message for the success
* @param config.formatReason -> Show the reason for the failure
+ * @param config.hideToast -> Hide all the toast
+ * @param config.hideSuccessToast -> Hide the success toast
+ * @param config.hideErrorToast -> Hide the error toast
* @returns
*/
export const operator = async <T>(request: () => Promise<T>, config?:
OperateConfig): Promise<[boolean, any?]> => {
@@ -41,14 +46,14 @@ export const operator = async <T>(request: () =>
Promise<T>, config?: OperateCon
setOperating?.(true);
const res = await request();
const content = formatMessage?.() ?? 'Operation successfully completed';
- if (!config?.hideToast) {
+ if (!config?.hideToast || !config?.hideSuccessToast) {
message.success(content);
}
return [true, res];
} catch (err) {
console.error('Operation failed.', err);
const reason = formatReason?.(err) ?? (err as any).response?.data?.message
?? 'Operation failed.';
- if (!config?.hideToast) {
+ if (!config?.hideToast || !config?.hideErrorToast) {
message.error(reason);
}