diff --git a/src/api/logStream.ts b/src/api/logStream.ts index f2f9910d..00bc4906 100644 --- a/src/api/logStream.ts +++ b/src/api/logStream.ts @@ -22,7 +22,7 @@ export const getLogStreamAlerts = (streamName: string) => { }; export const putLogStreamAlerts = (streamName: string, data: any) => { - return Axios().put(LOG_STREAMS_ALERTS_URL(streamName), JSON.parse(data)); + return Axios().put(LOG_STREAMS_ALERTS_URL(streamName), data); }; export const getLogStreamRetention = (streamName: string) => { @@ -30,7 +30,7 @@ export const getLogStreamRetention = (streamName: string) => { }; export const putLogStreamRetention = (streamName: string, data: any) => { - return Axios().put(LOG_STREAMS_RETRNTION_URL(streamName), JSON.parse(data)); + return Axios().put(LOG_STREAMS_RETRNTION_URL(streamName), data); }; export const getLogStreamStats = (streamName: string) => { diff --git a/src/components/Navbar/UserModal.tsx b/src/components/Navbar/UserModal.tsx index 40d1b3a4..c1192653 100644 --- a/src/components/Navbar/UserModal.tsx +++ b/src/components/Navbar/UserModal.tsx @@ -36,7 +36,7 @@ const UserModal = (props: UserModalProps) => { Roles: {Object.entries(userRoles).map(([key, value], index) => { return ( - + {index + 1}. {key} ({value[0].privilege}) ); diff --git a/src/hooks/useAlertsEditor.tsx b/src/hooks/useAlertsEditor.tsx index 3b4ed70c..78a04042 100644 --- a/src/hooks/useAlertsEditor.tsx +++ b/src/hooks/useAlertsEditor.tsx @@ -1,60 +1,39 @@ import { useMutation, useQuery } from 'react-query'; import { getLogStreamAlerts, putLogStreamAlerts } from '@/api/logStream'; -import { IconFileAlert } from '@tabler/icons-react'; -import { notifications } from '@mantine/notifications'; -import useMountedState from './useMountedState'; -import { Dayjs } from 'dayjs'; +import { notifyError, notifySuccess } from '@/utils/notification'; +import { AxiosError, isAxiosError } from 'axios'; -export const useAlertsEditor = (streamName: string, fetchStartTime?: Dayjs) => { - const [alertQuery, setAlertQuery] = useMountedState(''); +export const useAlertsEditor = (streamName: string) => { + const { mutate: updateLogStreamAlerts } = useMutation((data: any) => putLogStreamAlerts(streamName, data), { + onSuccess: () => notifySuccess({ message: 'Updated Successfully' }), + onError: (data: AxiosError) => { + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } else if (data.message && typeof data.message === 'string') { + notifyError({ message: data.message }); + } + }, + }); - const { - mutate: updateLogStreamAlerts, - data: alertQueryData, - isSuccess: updateLogStreamIsSuccess, - } = useMutation((data: string) => putLogStreamAlerts(streamName, data), {}); + return { + updateLogStreamAlerts, + }; +}; +export const useGetAlerts = (streamName: string) => { const { data: getLogAlertData, isError: getLogAlertIsError, isSuccess: getLogAlertIsSuccess, isLoading: getLogAlertIsLoading, - } = useQuery(['fetch-log-stream-alert', streamName, updateLogStreamIsSuccess, fetchStartTime], () => getLogStreamAlerts(streamName), { - onSuccess: (data) => { - setAlertQuery(JSON.stringify(data?.data)); - }, + } = useQuery(['fetch-log-stream-alert', streamName], () => getLogStreamAlerts(streamName), { retry: false, enabled: streamName !== '', + refetchOnWindowFocus: false, }); - const handleAlertQueryChange = (value: string | undefined) => setAlertQuery(value); - - const submitAlertQuery = () => { - try { - if (alertQuery) { - JSON.parse(alertQuery); - updateLogStreamAlerts(alertQuery); - } else { - throw new Error('Invalid JSON'); - } - } catch (e) { - notifications.show({ - id: 'load-data', - loading: false, - color: 'red', - title: 'Error occurred', - message: `Error occurred, please check your query and try again ${e}`, - icon: , - autoClose: 3000, - }); - } - }; - return { - alertQuery, - handleAlertQueryChange, - submitAlertQuery, - alertQueryData, getLogAlertData, getLogAlertIsError, getLogAlertIsSuccess, diff --git a/src/hooks/useCacheToggle.tsx b/src/hooks/useCacheToggle.tsx index 7c384a09..262883da 100644 --- a/src/hooks/useCacheToggle.tsx +++ b/src/hooks/useCacheToggle.tsx @@ -13,6 +13,7 @@ export const useCacheToggle = (streamName: string) => { { retry: false, enabled: streamName !== '', + refetchOnWindowFocus: false }, ); diff --git a/src/hooks/useRetentionEditor.tsx b/src/hooks/useRetentionEditor.tsx index 408f065b..416e5d16 100644 --- a/src/hooks/useRetentionEditor.tsx +++ b/src/hooks/useRetentionEditor.tsx @@ -1,64 +1,39 @@ import { useMutation, useQuery } from 'react-query'; import { getLogStreamRetention, putLogStreamRetention } from '@/api/logStream'; -import { IconFileAlert } from '@tabler/icons-react'; -import { notifications } from '@mantine/notifications'; -import useMountedState from './useMountedState'; -import { Dayjs } from 'dayjs'; +import { notifyError, notifySuccess } from '@/utils/notification'; +import { AxiosError, isAxiosError } from 'axios'; -export const useRetentionEditor = (streamName: string, fetchStartTime?: Dayjs) => { - const [retentionQuery, setRetentionQuery] = useMountedState(''); +export const useRetentionEditor = (streamName: string) => { + const { mutate: updateLogStreamRetention } = useMutation((data: any) => putLogStreamRetention(streamName, data), { + onSuccess: () => notifySuccess({ message: 'Updated Successfully' }), + onError: (data: AxiosError) => { + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } else if (data.message && typeof data.message === 'string') { + notifyError({ message: data.message }); + } + }, + }); - const { - mutate: updateLogStreamRetention, - data: retentionEditorData, - isSuccess: updateLogRetentionIsSuccess, - } = useMutation((data: string) => putLogStreamRetention(streamName, data), {}); + return { + updateLogStreamRetention, + }; +}; +export const useGetRetention = (streamName: string) => { const { data: getLogRetentionData, isError: getLogRetentionIsError, isLoading: getLogRetentionIsLoading, isSuccess: getLogRetentionIsSuccess, - } = useQuery( - ['fetch-log-stream-retention', streamName, updateLogRetentionIsSuccess, fetchStartTime], - () => getLogStreamRetention(streamName), - { - onSuccess: (data) => { - setRetentionQuery(JSON.stringify(data?.data)); - }, - retry: false, - enabled: streamName !== '', - }, - ); - - const handleRetentionQueryChange = (value: string | undefined) => setRetentionQuery(value); - - const submitRetentionQuery = () => { - try { - if (retentionQuery) { - JSON.parse(retentionQuery); - updateLogStreamRetention(retentionQuery); - } else { - throw new Error('Invalid JSON'); - } - } catch (e) { - notifications.show({ - id: 'load-data', - loading: false, - color: 'red', - title: 'Error occurred', - message: `Error occurred, please check your query and try again ${e}`, - icon: , - autoClose: 3000, - }); - } - }; - + } = useQuery(['fetch-log-stream-retention', streamName], () => getLogStreamRetention(streamName), { + onSuccess: () => {}, + retry: false, + enabled: streamName !== '', + refetchOnWindowFocus: false, + }); return { - retentionQuery, - handleRetentionQueryChange, - submitRetentionQuery, - retentionEditorData, getLogRetentionData, getLogRetentionIsLoading, getLogRetentionIsError, diff --git a/src/hooks/useRole.tsx b/src/hooks/useRole.tsx index 0922a84a..ee4ca6aa 100644 --- a/src/hooks/useRole.tsx +++ b/src/hooks/useRole.tsx @@ -1,6 +1,8 @@ import { useMutation, useQuery, useQueryClient } from 'react-query'; import { deleteRole, getDefaultRole, getRole, getRoles, putDeafultRole, putRole } from '@/api/roles'; import Cookies from 'js-cookie'; +import { AxiosError, isAxiosError } from 'axios'; +import { notifyError } from '@/utils/notification'; export const useRole = () => { const queryClient = useQueryClient(); @@ -12,7 +14,16 @@ export const useRole = () => { isError: updateRoleIsError, isLoading: updateRoleIsLoading, data: updateRoleData, - } = useMutation((data: { userName: string; privilege: object[] }) => putRole(data.userName, data.privilege), {}); + } = useMutation((data: { userName: string; privilege: object[] }) => putRole(data.userName, data.privilege), { + onError: (data: AxiosError) => { + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } else if (data.message && typeof data.message === 'string') { + notifyError({ message: data.message }); + } + }, + }); const { mutate: deleteRoleMutation, @@ -20,8 +31,14 @@ export const useRole = () => { isError: deleteRoleIsError, isLoading: deleteRoleIsLoading, } = useMutation((data: { roleName: string }) => deleteRole(data.roleName), { - onError: () => { + onError: (data: AxiosError) => { queryClient.invalidateQueries(['fetch-roles']); + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } else if (data.message && typeof data.message === 'string') { + notifyError({ message: data.message }); + } }, }); @@ -54,6 +71,14 @@ export const useRole = () => { mutate: updateDefaultRoleMutation, } = useMutation((data: { roleName: string }) => putDeafultRole(data?.roleName), { retry: false, + onError: (data: AxiosError) => { + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } else if (data.message && typeof data.message === 'string') { + notifyError({ message: data.message }); + } + }, }); const { diff --git a/src/hooks/useUser.tsx b/src/hooks/useUser.tsx index 296a5b91..55dd4d2e 100644 --- a/src/hooks/useUser.tsx +++ b/src/hooks/useUser.tsx @@ -2,6 +2,7 @@ import { useMutation, useQuery } from 'react-query'; import { deleteUser, getUserRoles, getUsers, postUser, postUserResetPassword, putUserRoles } from '@/api/users'; import { isAxiosError, AxiosError } from 'axios'; import useMountedState from './useMountedState'; +import { notifyError } from '@/utils/notification'; export const useUser = () => { const [resetPasswordError, setResetPasswordError] = useMountedState(''); @@ -21,6 +22,7 @@ export const useUser = () => { if (isAxiosError(data) && data.response) { const error = data.response.data as string; setCreateUserError(error); + typeof error === 'string' && notifyError({ message: error }); } }, onSuccess: (_data, variables) => { @@ -35,7 +37,17 @@ export const useUser = () => { isError: deleteUserIsError, isLoading: deleteUserIsLoading, data: deleteUserData, - } = useMutation((data: { userName: string }) => deleteUser(data.userName), {}); + } = useMutation((data: { userName: string; onSuccess?: () => void }) => deleteUser(data.userName), { + onSuccess: (_data, variables) => { + variables.onSuccess && variables.onSuccess(); + }, + onError: (data: AxiosError) => { + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } + }, + }); const { mutate: updateUserMutation, @@ -43,7 +55,14 @@ export const useUser = () => { isError: updateUserIsError, isLoading: updateUserIsLoading, data: udpateUserData, - } = useMutation((data: { userName: string; roles: string[] }) => putUserRoles(data.userName, data.roles), {}); + } = useMutation((data: { userName: string; roles: string[] }) => putUserRoles(data.userName, data.roles), { + onError: (data: AxiosError) => { + if (isAxiosError(data) && data.response) { + const error = data.response?.data as string; + typeof error === 'string' && notifyError({ message: error }); + } + }, + }); const { mutate: updateUserPasswordMutation, @@ -56,6 +75,7 @@ export const useUser = () => { if (isAxiosError(data) && data.response) { const error = data.response.data as string; setResetPasswordError(error); + typeof error === 'string' && notifyError({ message: error }); } }, }); @@ -111,6 +131,7 @@ export const useGetUser = () => { refetch: getUserRefetch, } = useQuery(['fetch-user'], () => getUsers(), { retry: false, + refetchOnWindowFocus: false }); return { getUserRefetch, diff --git a/src/pages/AccessManagement/PrivilegeTR.tsx b/src/pages/AccessManagement/PrivilegeTR.tsx index 74aeacf8..c2e2ec32 100644 --- a/src/pages/AccessManagement/PrivilegeTR.tsx +++ b/src/pages/AccessManagement/PrivilegeTR.tsx @@ -265,7 +265,7 @@ const PrivilegeTR: FC = (props) => { ) : ( - Error + <> )} diff --git a/src/pages/AccessManagement/RoleTR.tsx b/src/pages/AccessManagement/RoleTR.tsx index 808f0b2d..52b7a5ad 100644 --- a/src/pages/AccessManagement/RoleTR.tsx +++ b/src/pages/AccessManagement/RoleTR.tsx @@ -27,7 +27,7 @@ interface RoleTRProps { id: string; method: string; }; - deleteUserMutation: (data: { userName: string }) => void; + deleteUserMutation: (data: { userName: string, onSuccess?: () => void; }) => void; updateUserPasswordIsError: boolean; getUserRolesIsError: boolean; getUserRolesIsLoading: boolean; @@ -35,6 +35,7 @@ interface RoleTRProps { updateUserPasswordIsLoading: boolean; udpateUserPasswordData: AxiosResponse | undefined; resetPasswordError: string; + getUserRefetch: () => void; } const RoleTR: FC = (props) => { @@ -117,7 +118,7 @@ const RoleTR: FC = (props) => { }; const handleDelete = () => { - deleteUserMutation({ userName: user.id }); + deleteUserMutation({ userName: user.id, onSuccess: props.getUserRefetch }); closeDelete(); setUserInput(''); }; @@ -173,7 +174,7 @@ const RoleTR: FC = (props) => { ) : getUserRolesIsLoading ? ( 'loading..' ) : getUserRolesData?.data ? ( - + {getBadges()} = (props) => { ) : ( - Error + <> )} diff --git a/src/pages/AccessManagement/Users.tsx b/src/pages/AccessManagement/Users.tsx index 1483d129..816ee207 100644 --- a/src/pages/AccessManagement/Users.tsx +++ b/src/pages/AccessManagement/Users.tsx @@ -74,6 +74,7 @@ const Users: FC = () => { updateUserPasswordIsLoading={updateUserPasswordIsLoading} udpateUserPasswordData={udpateUserPasswordData} resetPasswordError={resetPasswordError} + getUserRefetch={getUserRefetch} /> ); }) diff --git a/src/pages/Home/index.tsx b/src/pages/Home/index.tsx index 37e07281..654fd62e 100644 --- a/src/pages/Home/index.tsx +++ b/src/pages/Home/index.tsx @@ -4,7 +4,6 @@ import { IconChevronRight, IconExternalLink } from '@tabler/icons-react'; import { useEffect, type FC, useCallback } from 'react'; import { useNavigate } from 'react-router-dom'; import { useDocumentTitle } from '@mantine/hooks'; -import { useLogStream } from '@/hooks/useLogStream'; import { useGetStreamMetadata } from '@/hooks/useGetStreamMetadata'; import { HumanizeNumber, formatBytes } from '@/utils/formatBytes'; import { LogStreamRetention, LogStreamStat } from '@/@types/parseable/api/stream'; @@ -35,29 +34,24 @@ const Home: FC = () => { useDocumentTitle('Parseable | Streams'); const classes = homeStyles; const { container } = classes; - const { getLogStreamListData, getLogStreamListIsLoading, getLogStreamListIsError } = useLogStream(); const { methods: { streamChangeCleanup }, + state: { userSpecficStreams } } = useHeaderContext(); const navigate = useNavigate(); const { getStreamMetadata, metaData } = useGetStreamMetadata(); - const streams = Array.isArray(getLogStreamListData?.data) - ? getLogStreamListData?.data.map((stream) => stream.name) || [] - : []; - useEffect(() => { - if (streams.length === 0) return; - getStreamMetadata(streams); - }, [getLogStreamListData?.data]); + if (!Array.isArray(userSpecficStreams) || userSpecficStreams.length === 0) return; + getStreamMetadata(userSpecficStreams.map((stream) => stream.name)); + }, [userSpecficStreams]); const navigateToStream = useCallback((stream: string) => { streamChangeCleanup(stream); navigate(`/${stream}/logs`); }, []); - if (getLogStreamListIsError || getLogStreamListIsLoading) return null; // implement loading state - if (streams.length === 0) return ; + if (Array.isArray(userSpecficStreams) && userSpecficStreams.length === 0) return ; return ( diff --git a/src/pages/Logs/AlertsModal.tsx b/src/pages/Logs/AlertsModal.tsx index be9b1f5e..285d221d 100644 --- a/src/pages/Logs/AlertsModal.tsx +++ b/src/pages/Logs/AlertsModal.tsx @@ -3,23 +3,44 @@ import { useLogsPageContext } from './logsContextProvider'; import { Text } from '@mantine/core'; import classes from './styles/Logs.module.css'; import { Editor } from '@monaco-editor/react'; +import { useCallback, useEffect, useState } from 'react'; +import { useAlertsEditor, useGetAlerts } from '@/hooks/useAlertsEditor'; +import { notifyError } from '@/utils/notification'; const ModalTitle = () => { return Alerts; }; -type AlertsModalProps = { - data: any; - handleChange: (value: string | undefined) => void; - handleSubmit: () => void; -}; - -const AlertsModal = (props: AlertsModalProps) => { +const AlertsModal = () => { + const [alertConfig, setAlertConfig] = useState(''); const { - state: { alertsModalOpen }, + state: { alertsModalOpen, currentStream }, methods: { closeAlertsModal }, } = useLogsPageContext(); + const { getLogAlertData } = useGetAlerts(currentStream); + const { updateLogStreamAlerts } = useAlertsEditor(currentStream); + + const onSubmit = useCallback(() => { + if (alertConfig) { + let parsedConfig; + try { + parsedConfig = JSON.parse(alertConfig); + } catch (e) { + return notifyError({ message: 'Unable to parse config' }); + } + updateLogStreamAlerts(parsedConfig); + } else { + return notifyError({ message: 'Unable to parse config' }); + } + }, [alertConfig]); + + useEffect(() => { + if (getLogAlertData?.data) { + setAlertConfig(JSON.stringify(getLogAlertData?.data, null, 2)); + } + }, [getLogAlertData?.data]); + return ( { { /> - diff --git a/src/pages/Logs/LogTable.tsx b/src/pages/Logs/LogTable.tsx index 16c47a2e..db630d92 100644 --- a/src/pages/Logs/LogTable.tsx +++ b/src/pages/Logs/LogTable.tsx @@ -17,6 +17,7 @@ import { Loader, Group, Stack, + Tooltip, } from '@mantine/core'; import { useCallback, useEffect, useMemo, useRef } from 'react'; import type { FC } from 'react'; @@ -70,11 +71,11 @@ const TotalLogsCount = (props: TotalLogsCountProps) => { const { totalCount, loadedCount } = props; if (typeof totalCount !== 'number' || typeof loadedCount !== 'number') return ; + const renderTotalCount = useCallback(() => ({HumanizeNumber(totalCount)}), [totalCount]); return ( - - {`Showing ${loadedCount < LOAD_LIMIT ? loadedCount : LOAD_LIMIT} out of ${HumanizeNumber( - totalCount, - )} records`} + + {`Showing ${loadedCount < LOAD_LIMIT ? loadedCount : LOAD_LIMIT} out of`} + {renderTotalCount()} ); }; @@ -127,6 +128,8 @@ const LogTable: FC = () => { }; const currentStreamName = subLogQuery.get().streamName; + const startTime = subLogQuery.get().startTime; + const endTime = subLogQuery.get().endTime; const { fetchQueryMutation } = useQueryResult(); const fetchCount = useCallback(() => { const queryContext = subLogQuery.get(); @@ -137,8 +140,8 @@ const LogTable: FC = () => { if (queryContext && query?.length > 0) { const logsQuery = { streamName: queryContext.streamName, - startTime: queryContext.startTime, - endTime: queryContext.endTime, + startTime: startTime, + endTime: endTime, access: [], }; fetchQueryMutation.mutate({ @@ -146,7 +149,7 @@ const LogTable: FC = () => { query, }); } - }, [currentStreamName, isQuerySearchActive, custSearchQuery]); + }, [currentStreamName, isQuerySearchActive, custSearchQuery, startTime, endTime]); useEffect(() => { resetQuerySearch(); @@ -257,7 +260,7 @@ const LogTable: FC = () => { if (pageOffset === 0 && subLogQuery.get()) { fetchCount(); } - }, [currentStreamName, isQuerySearchActive, custSearchQuery]); + }, [currentStreamName, isQuerySearchActive, custSearchQuery, startTime, endTime]); useEffect(() => { const streamErrorListener = subLogStreamError.subscribe(setLogStreamError); diff --git a/src/pages/Logs/RetentionModal.tsx b/src/pages/Logs/RetentionModal.tsx index 2576d79c..25b14ea9 100644 --- a/src/pages/Logs/RetentionModal.tsx +++ b/src/pages/Logs/RetentionModal.tsx @@ -3,29 +3,50 @@ import { useLogsPageContext } from './logsContextProvider'; import { Text } from '@mantine/core'; import classes from './styles/Logs.module.css'; import { Editor } from '@monaco-editor/react'; +import { useCallback, useEffect, useState } from 'react'; +import { useCacheToggle } from '@/hooks/useCacheToggle'; +import { useGetRetention, useRetentionEditor } from '@/hooks/useRetentionEditor'; +import { notifyError } from '@/utils/notification'; const ModalTitle = () => { return Settings; }; -type RetentionModalProps = { - data: any; - handleChange: (value: string | undefined) => void; - handleSubmit: () => void; - handleCacheToggle: () => void; - isCacheEnabled: boolean; -}; - -const RententionModal = (props: RetentionModalProps) => { +const RententionModal = () => { + const [retentionConfig, setRetentionConfig] = useState(''); const { - state: { retentionModalOpen }, + state: { retentionModalOpen, currentStream }, methods: { closeRetentionModal }, } = useLogsPageContext(); - const { isCacheEnabled, handleCacheToggle } = props; + const { handleCacheToggle, isCacheEnabled } = useCacheToggle(currentStream); + + const { getLogRetentionData } = useGetRetention(currentStream); + const {updateLogStreamRetention} = useRetentionEditor(currentStream); + const switchStyles = { track: isCacheEnabled ? classes.trackStyle : {}, }; + const onSubmit = useCallback(() => { + if (retentionConfig) { + let parsedConfig; + try { + parsedConfig = JSON.parse(retentionConfig); + } catch (e) { + return notifyError({ message: 'Unable to parse config' }); + } + updateLogStreamRetention(parsedConfig); + } else { + return notifyError({ message: 'Unable to parse config' }); + } + }, []); + + useEffect(() => { + if (getLogRetentionData?.data) { + setRetentionConfig(JSON.stringify(getLogRetentionData?.data, null, 2)); + } + }, [getLogRetentionData?.data]); + return ( { Retention { /> - diff --git a/src/pages/Logs/index.tsx b/src/pages/Logs/index.tsx index 9cef4972..86a3d220 100644 --- a/src/pages/Logs/index.tsx +++ b/src/pages/Logs/index.tsx @@ -11,9 +11,6 @@ import { useLogsPageContext } from './logsContextProvider'; import PrimaryToolbar from './PrimaryToolbar'; import SecondaryToolbar from './SecondaryToolbar'; import { useHeaderContext } from '@/layouts/MainLayout/Context'; -import { useAlertsEditor } from '@/hooks/useAlertsEditor'; -import { useRetentionEditor } from '@/hooks/useRetentionEditor'; -import { useCacheToggle } from '@/hooks/useCacheToggle'; const Logs: FC = () => { useDocumentTitle('Parseable | Logs'); @@ -21,24 +18,14 @@ const Logs: FC = () => { state: { maximized }, } = useHeaderContext(); const { - state: { liveTailToggled, currentStream }, + state: { liveTailToggled }, } = useLogsPageContext(); - const { handleAlertQueryChange, submitAlertQuery, getLogAlertData } = useAlertsEditor(currentStream); - const { handleRetentionQueryChange, submitRetentionQuery, getLogRetentionData } = useRetentionEditor(currentStream); - const { handleCacheToggle, isCacheEnabled } = useCacheToggle(currentStream); - return ( - - + + {!maximized && ( <> diff --git a/src/utils/notification.ts b/src/utils/notification.ts index 661005b6..69e289e5 100644 --- a/src/utils/notification.ts +++ b/src/utils/notification.ts @@ -1,11 +1,11 @@ import type { NotificationData } from '@mantine/notifications'; import { showNotification } from '@mantine/notifications'; -export const notifyError = (payload: NotificationData) => { - const title = ['string', 'undefined'].includes(typeof payload?.title) ? payload?.title : 'Oops!'; +export const notifyError = (payload?: NotificationData) => { + const title = payload?.title || 'Oops!'; const message = payload?.message || 'Something went wrong!.'; const color = payload?.color || 'red'; - const autoClose = payload?.autoClose || 6000; + const autoClose = payload?.autoClose || 3000; showNotification({ ...payload, title, @@ -15,23 +15,26 @@ export const notifyError = (payload: NotificationData) => { }) }; -export const notify = (payload: NotificationData) => { - const color = payload.color || 'green'; - const autoClose = payload.autoClose || 6000; +export const notifySuccess = (payload?: NotificationData) => { + const title = payload?.title || 'Success!'; + const message = payload?.message || 'Done'; + const color = payload?.color || 'green'; + const autoClose = payload?.autoClose || 3000; showNotification({ ...payload, + title, + message, color, autoClose, - }); -}; - -export const notifyApi = (payload: NotificationData, customTitle: boolean = true) => { - const autoClose = payload.autoClose ?? 3000; - const title = customTitle && payload.color === 'green' ? 'Success' : 'Error'; + }) +}; +export const notify = (payload: NotificationData) => { + const color = payload.color || 'green'; + const autoClose = payload.autoClose || 3000; showNotification({ ...payload, + color, autoClose, - title, }); -}; +}; \ No newline at end of file