From 0e6dd0c58e947881d19195ee6b1ee232aa08ac5a Mon Sep 17 00:00:00 2001 From: Kartik Gupta Date: Wed, 26 Jul 2023 17:09:59 +0530 Subject: [PATCH] final update and config page --- src/api/constants.ts | 8 +- src/api/logStream.ts | 25 +++- src/components/Navbar/index.tsx | 97 ++++++++++++- src/hooks/useDeleteLogStream.ts | 39 +++++ src/hooks/useGetLogStreamList.ts | 5 +- src/hooks/usePutLogStreamAlerts.ts | 39 +++++ src/hooks/usePutLogStreamRetention.ts | 39 +++++ src/hooks/useQueryLogs.ts | 2 +- src/hooks/useQueryResult.ts | 2 +- src/pages/Config/index.tsx | 197 +++++++++++++++++++++++++- src/pages/Config/styles.tsx | 33 +++++ src/pages/Logs/ViewLog.tsx | 10 +- src/pages/Logs/styles.tsx | 4 + src/pages/Query/QueryCodeEditor.tsx | 15 +- src/pages/Stats/Status.tsx | 10 +- 15 files changed, 489 insertions(+), 36 deletions(-) create mode 100644 src/hooks/useDeleteLogStream.ts create mode 100644 src/hooks/usePutLogStreamAlerts.ts create mode 100644 src/hooks/usePutLogStreamRetention.ts create mode 100644 src/pages/Config/styles.tsx diff --git a/src/api/constants.ts b/src/api/constants.ts index 64920165..3e244fae 100644 --- a/src/api/constants.ts +++ b/src/api/constants.ts @@ -4,6 +4,8 @@ export const HEALTH_LIVENESS_URL = `${API_V1}/liveness`; export const LOG_STREAM_LIST_URL = `${API_V1}/logstream`; export const LOG_STREAMS_SCHEMA_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/schema`; export const LOG_QUERY_URL = `${API_V1}/query`; -export const STATS_STREAMS_ALERTS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/alert`; -export const STATS_STREAMS_RETRNTION_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/retention`; -export const STATS_STREAMS_STATS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/stats`; +export const LOG_STREAMS_ALERTS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/alert`; +export const LOG_STREAMS_RETRNTION_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/retention`; +export const LOG_STREAMS_STATS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/stats`; +export const DELETE_STREAMS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`; + diff --git a/src/api/logStream.ts b/src/api/logStream.ts index adf8a8e7..12ad545e 100644 --- a/src/api/logStream.ts +++ b/src/api/logStream.ts @@ -1,10 +1,11 @@ import { Axios } from './axios'; import { + DELETE_STREAMS_URL, LOG_STREAMS_SCHEMA_URL, LOG_STREAM_LIST_URL, - STATS_STREAMS_ALERTS_URL, - STATS_STREAMS_RETRNTION_URL, - STATS_STREAMS_STATS_URL, + LOG_STREAMS_ALERTS_URL, + LOG_STREAMS_RETRNTION_URL, + LOG_STREAMS_STATS_URL, } from './constants'; import { LogStreamData, LogStreamSchemaData } from '@/@types/parseable/api/stream'; @@ -17,13 +18,25 @@ export const getLogStreamSchema = (streamName: string) => { }; export const getLogStreamAlerts = (streamName: string) => { - return Axios().get(STATS_STREAMS_ALERTS_URL(streamName)); + return Axios().get(LOG_STREAMS_ALERTS_URL(streamName)); +}; + +export const putLogStreamAlerts = (streamName: string, data: any) => { + return Axios().put(LOG_STREAMS_ALERTS_URL(streamName), data); }; export const getLogStreamRetention = (streamName: string) => { - return Axios().get(STATS_STREAMS_RETRNTION_URL(streamName)); + return Axios().get(LOG_STREAMS_RETRNTION_URL(streamName)); +}; + +export const putLogStreamRetention = (streamName: string, data: any) => { + return Axios().put(LOG_STREAMS_RETRNTION_URL(streamName), data); }; export const getLogStreamStats = (streamName: string) => { - return Axios().get(STATS_STREAMS_STATS_URL(streamName)); + return Axios().get(LOG_STREAMS_STATS_URL(streamName)); }; + +export const deleteLogStream = (streamName: string) => { + return Axios().delete(DELETE_STREAMS_URL(streamName)); +} diff --git a/src/components/Navbar/index.tsx b/src/components/Navbar/index.tsx index 57cfc033..e36be286 100644 --- a/src/components/Navbar/index.tsx +++ b/src/components/Navbar/index.tsx @@ -1,5 +1,5 @@ import type { NavbarProps as MantineNavbarProps } from '@mantine/core'; -import { Navbar as MantineNavbar, NavLink, Select, Anchor, Card, Box, Modal, Text, Image } from '@mantine/core'; +import { Navbar as MantineNavbar, NavLink, Select, Anchor, Card, Box, Modal, Text, Image, Button, TextInput } from '@mantine/core'; import { IconZoomCode, IconReportAnalytics, @@ -12,6 +12,7 @@ import { IconBinaryTree2, IconTableShortcut, IconSettings, + IconTrash, } from '@tabler/icons-react'; import { FC, useEffect, useState } from 'react'; import docImage from '@/assets/images/doc.webp'; @@ -27,6 +28,7 @@ import useMountedState from '@/hooks/useMountedState'; import dayjs from 'dayjs'; import { useDisclosure, useLocalStorage } from '@mantine/hooks'; import { LOGIN_ROUTE } from '@/constants/routes'; +import { useDeleteLogStream } from '@/hooks/useDeleteLogStream'; const links = [ { icon: IconZoomCode, label: 'Query', pathname: '/query' }, @@ -40,11 +42,13 @@ type NavbarProps = Omit; const Navbar: FC = (props) => { const [username] = useLocalStorage({ key: 'username', getInitialValueInEffect: false }); const navigate = useNavigate(); - const { data: streams, loading, error, getData } = useGetLogStreamList(); + const { data: streams, loading, error, getData, resetData:resetStreamArray} = useGetLogStreamList(); const [activeStream, setActiveStream] = useState(''); const [searchValue, setSearchValue] = useState(''); const { classes } = useNavbarStyles(); const [currentPage, setCurrentPage] = useState('/logs'); + const [opened, { open, close }] = useDisclosure(false); + const [ deleteStream, setDeleteStream] = useState(''); const { container, linkBtnActive, @@ -65,8 +69,9 @@ const Navbar: FC = (props) => { state: { subNavbarTogle }, } = useHeaderContext(); const [isSubNavbarOpen, setIsSubNavbarOpen] = useMountedState(false); - const [opened, { close, open }] = useDisclosure(); + const [openedDelete, { close:closeDelete, open:openDelete}] = useDisclosure(); let location = useLocation(); + const {data:deleteData, loading:deleteLoading, error:deleteError, deleteLogStreamFun , resetData: resetDatalogStraeam} = useDeleteLogStream(); useEffect(() => { const listener = subNavbarTogle.subscribe(setIsSubNavbarOpen); @@ -151,6 +156,59 @@ const Navbar: FC = (props) => { }); } }, [streams, error, loading]); + const handleCloseDelete = () => { + closeDelete(); + setDeleteStream(''); + }; + const handleDelete = () => { + deleteLogStreamFun(deleteStream||""); + closeDelete(); + }; + + useEffect(() => { + if (deleteLoading) { + notifications.show({ + id: 'delete-data', + loading: true, + color: '#545BEB', + title: 'Deleting Stream', + message: 'Stream will be deleted.', + autoClose: false, + withCloseButton: false, + + }); + return; + } + if (deleteData && !deleteLoading) { + notifications.update({ + id: 'delete-data', + color: 'green', + title: 'Stream was deleted', + message: 'Successfully Deleted!!', + icon: , + autoClose: 1000, + }); + resetDatalogStraeam(); + resetStreamArray(); + getData(); + return; + } + if (deleteError) { + notifications.update({ + id: 'delete-data', + color: 'red', + title: 'Error Occured', + message: 'Error Occured while deleting stream', + icon: , + autoClose: 2000, + }); + return; + } + if(streams && streams.length!==0 && deleteStream===streamName){ + navigate(`/${streams[0].name}/query`); + } + + }, [deleteData, deleteError, deleteLoading,streams]); return (