From 91106987d3dd85d2eedc22045196f24d729df31d Mon Sep 17 00:00:00 2001 From: mufazalov Date: Wed, 4 Jun 2025 20:51:39 +0300 Subject: [PATCH] feat(createToast): allow more props from uikit --- src/containers/Operations/columns.tsx | 4 ++-- .../QueryEditorControls.tsx | 2 +- .../useQueryInfoMenuItems.tsx | 2 +- src/containers/Tenant/utils/schemaActions.tsx | 4 ++-- src/utils/createToast.tsx | 21 ++++++------------- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/containers/Operations/columns.tsx b/src/containers/Operations/columns.tsx index fa3843134..d6dc6e3d2 100644 --- a/src/containers/Operations/columns.tsx +++ b/src/containers/Operations/columns.tsx @@ -176,7 +176,7 @@ function OperationsActions({operation, database, refreshTable}: OperationsAction createToast({ name: 'Forgotten', title: i18n('text_forgotten', {id}), - type: 'success', + theme: 'success', }); refreshTable(); }) @@ -200,7 +200,7 @@ function OperationsActions({operation, database, refreshTable}: OperationsAction createToast({ name: 'Cancelled', title: i18n('text_cancelled', {id}), - type: 'success', + theme: 'success', }); refreshTable(); }) diff --git a/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx b/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx index 73391de7e..796cb358e 100644 --- a/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx +++ b/src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx @@ -101,7 +101,7 @@ export const QueryEditorControls = ({ name: 'stop-error', title: '', content: i18n('toaster.stop-error'), - type: 'error', + theme: 'danger', autoHiding: STOP_AUTO_HIDE_TIMEOUT, }); setCancelQueryError(true); diff --git a/src/containers/Tenant/Query/QueryResult/components/QueryInfoDropdown/useQueryInfoMenuItems.tsx b/src/containers/Tenant/Query/QueryResult/components/QueryInfoDropdown/useQueryInfoMenuItems.tsx index 9b02ed9da..df8f46b5b 100644 --- a/src/containers/Tenant/Query/QueryResult/components/QueryInfoDropdown/useQueryInfoMenuItems.tsx +++ b/src/containers/Tenant/Query/QueryResult/components/QueryInfoDropdown/useQueryInfoMenuItems.tsx @@ -89,7 +89,7 @@ export function useQueryInfoMenuItems({ createToast({ title: i18n('text_error-plan-svg', {error: errorMessage}), name: 'plan-svg-error', - type: 'error', + theme: 'danger', }); return null; }); diff --git a/src/containers/Tenant/utils/schemaActions.tsx b/src/containers/Tenant/utils/schemaActions.tsx index 02a1cfb40..241e94c72 100644 --- a/src/containers/Tenant/utils/schemaActions.tsx +++ b/src/containers/Tenant/utils/schemaActions.tsx @@ -127,13 +127,13 @@ const bindActions = ( createToast({ name: 'Copied', title: i18n('actions.copied'), - type: 'success', + theme: 'success', }); } catch { createToast({ name: 'Not copied', title: i18n('actions.notCopied'), - type: 'error', + theme: 'danger', }); } }, diff --git a/src/utils/createToast.tsx b/src/utils/createToast.tsx index 4d91fbbde..efc31eb14 100644 --- a/src/utils/createToast.tsx +++ b/src/utils/createToast.tsx @@ -1,25 +1,16 @@ +import type {ToastProps} from '@gravity-ui/uikit'; import {toaster} from '@gravity-ui/uikit/toaster-singleton-react-18'; export {toaster}; -interface CreateToastProps { - name?: string; - title?: string; - content?: string; - type: 'error' | 'success'; - autoHiding?: number | false; - className?: string; -} - -function createToast({name, title, type, content, autoHiding, className}: CreateToastProps) { +function createToast({name, title, theme, isClosable, autoHiding, ...restProps}: ToastProps) { return toaster.add({ name: name ?? 'Request succeeded', title: title ?? 'Request succeeded', - theme: type === 'error' ? 'danger' : 'success', - content: content, - isClosable: true, - autoHiding: autoHiding ?? (type === 'success' ? 5000 : false), - className, + theme: theme ?? 'success', + isClosable: isClosable ?? true, + autoHiding: autoHiding ?? (theme === 'success' ? 5000 : false), + ...restProps, }); }