From f9f0337c73af90fa7b62af61f1e9c4a7357c9cad Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Fri, 24 Jan 2025 15:41:07 +0530 Subject: [PATCH 1/2] fix: Detect schema JSON type fix --- src/hooks/useLogStream.tsx | 15 +++++++------ src/pages/Home/CreateStreamModal.tsx | 32 ++++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/hooks/useLogStream.tsx b/src/hooks/useLogStream.tsx index acdc9db3..b627e9db 100644 --- a/src/hooks/useLogStream.tsx +++ b/src/hooks/useLogStream.tsx @@ -1,15 +1,16 @@ +import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; +import { AxiosError, isAxiosError } from 'axios'; +import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; +import { notifyError, notifySuccess } from '@/utils/notification'; import { useMutation, useQuery } from 'react-query'; import { + createLogStream, deleteLogStream, + detectLogStreamSchema, getLogStreamList, - createLogStream, updateLogStream, - detectLogStreamSchema, } from '@/api/logStream'; -import { AxiosError, isAxiosError } from 'axios'; -import { notifyError, notifySuccess } from '@/utils/notification'; -import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; -import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; + type CreateStreamOpts = { streamName: string; @@ -40,7 +41,7 @@ export const useLogStream = () => { isError: detectLogStreamSchemaIsError, isLoading: detectLogStreamSchemaIsLoading, } = useMutation( - (data: { sampleLogs: any[]; onSuccess: (data: LogStreamSchemaData) => void }) => + (data: { sampleLogs: Record; onSuccess: (data: LogStreamSchemaData) => void }) => detectLogStreamSchema(data.sampleLogs), { onSuccess: (data, variables) => { diff --git a/src/pages/Home/CreateStreamModal.tsx b/src/pages/Home/CreateStreamModal.tsx index 3da7f7cb..c289d055 100644 --- a/src/pages/Home/CreateStreamModal.tsx +++ b/src/pages/Home/CreateStreamModal.tsx @@ -1,3 +1,19 @@ +import _ from 'lodash'; +import styles from './styles/CreateStreamModal.module.css'; +import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; +import { CreatableSelect } from '@/components/Misc/CreatableSelect'; +import { + FC, + useCallback, + useEffect, + useState + } from 'react'; +import { GetInputPropsReturnType, UseFormReturnType } from 'node_modules/@mantine/form/lib/types'; +import { IconInfoCircleFilled, IconPlus } from '@tabler/icons-react'; +import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; +import { notifyError } from '@/utils/notification'; +import { useForm } from '@mantine/form'; +import { useLogStream } from '@/hooks/useLogStream'; import { ActionIcon, Box, @@ -18,17 +34,7 @@ import { ThemeIcon, Tooltip, } from '@mantine/core'; -import { FC, useCallback, useEffect, useState } from 'react'; -import styles from './styles/CreateStreamModal.module.css'; -import { useLogStream } from '@/hooks/useLogStream'; -import { useForm } from '@mantine/form'; -import { IconInfoCircleFilled, IconPlus } from '@tabler/icons-react'; -import _ from 'lodash'; -import { CreatableSelect } from '@/components/Misc/CreatableSelect'; -import { useAppStore, appStoreReducers } from '@/layouts/MainLayout/providers/AppProvider'; -import { GetInputPropsReturnType, UseFormReturnType } from 'node_modules/@mantine/form/lib/types'; -import { notifyError } from '@/utils/notification'; -import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; + const { toggleCreateStreamModal } = appStoreReducers; @@ -461,9 +467,7 @@ const DetectSchemaSection = (props: { form: StreamFormType }) => { } catch (e) { console.error('Error parsing json', e); } - if (!_.isArray(logRecords)) { - return notifyError({ message: 'Invalid JSON' }); - } else if (_.isEmpty(logRecords)) { + if (_.isEmpty(logRecords)) { return notifyError({ message: 'No records found' }); } else if (_.size(logRecords) > 10) { return notifyError({ message: 'More than 10 records found' }); From b8d5479d4d37b045603c6007c7e6880b27be1788 Mon Sep 17 00:00:00 2001 From: Praveen K B Date: Fri, 24 Jan 2025 15:46:32 +0530 Subject: [PATCH 2/2] Lint fixes --- src/hooks/useLogStream.tsx | 8 ++++---- src/pages/Home/CreateStreamModal.tsx | 27 +++++++++++---------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/hooks/useLogStream.tsx b/src/hooks/useLogStream.tsx index b627e9db..c311918c 100644 --- a/src/hooks/useLogStream.tsx +++ b/src/hooks/useLogStream.tsx @@ -1,8 +1,5 @@ -import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; import { AxiosError, isAxiosError } from 'axios'; -import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; -import { notifyError, notifySuccess } from '@/utils/notification'; -import { useMutation, useQuery } from 'react-query'; +import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; import { createLogStream, deleteLogStream, @@ -10,7 +7,10 @@ import { getLogStreamList, updateLogStream, } from '@/api/logStream'; +import { notifyError, notifySuccess } from '@/utils/notification'; +import { useMutation, useQuery } from 'react-query'; +import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; type CreateStreamOpts = { streamName: string; diff --git a/src/pages/Home/CreateStreamModal.tsx b/src/pages/Home/CreateStreamModal.tsx index c289d055..1520eddd 100644 --- a/src/pages/Home/CreateStreamModal.tsx +++ b/src/pages/Home/CreateStreamModal.tsx @@ -1,19 +1,3 @@ -import _ from 'lodash'; -import styles from './styles/CreateStreamModal.module.css'; -import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; -import { CreatableSelect } from '@/components/Misc/CreatableSelect'; -import { - FC, - useCallback, - useEffect, - useState - } from 'react'; -import { GetInputPropsReturnType, UseFormReturnType } from 'node_modules/@mantine/form/lib/types'; -import { IconInfoCircleFilled, IconPlus } from '@tabler/icons-react'; -import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; -import { notifyError } from '@/utils/notification'; -import { useForm } from '@mantine/form'; -import { useLogStream } from '@/hooks/useLogStream'; import { ActionIcon, Box, @@ -34,7 +18,18 @@ import { ThemeIcon, Tooltip, } from '@mantine/core'; +import { FC, useCallback, useEffect, useState } from 'react'; +import { GetInputPropsReturnType, UseFormReturnType } from 'node_modules/@mantine/form/lib/types'; +import { IconInfoCircleFilled, IconPlus } from '@tabler/icons-react'; +import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider'; +import { CreatableSelect } from '@/components/Misc/CreatableSelect'; +import { LogStreamSchemaData } from '@/@types/parseable/api/stream'; +import _ from 'lodash'; +import { notifyError } from '@/utils/notification'; +import styles from './styles/CreateStreamModal.module.css'; +import { useForm } from '@mantine/form'; +import { useLogStream } from '@/hooks/useLogStream'; const { toggleCreateStreamModal } = appStoreReducers;