Skip to content

Commit f9f0337

Browse files
committed
fix: Detect schema JSON type fix
1 parent 16e3a8a commit f9f0337

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

src/hooks/useLogStream.tsx

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';
2+
import { AxiosError, isAxiosError } from 'axios';
3+
import { LogStreamSchemaData } from '@/@types/parseable/api/stream';
4+
import { notifyError, notifySuccess } from '@/utils/notification';
15
import { useMutation, useQuery } from 'react-query';
26
import {
7+
createLogStream,
38
deleteLogStream,
9+
detectLogStreamSchema,
410
getLogStreamList,
5-
createLogStream,
611
updateLogStream,
7-
detectLogStreamSchema,
812
} from '@/api/logStream';
9-
import { AxiosError, isAxiosError } from 'axios';
10-
import { notifyError, notifySuccess } from '@/utils/notification';
11-
import { LogStreamSchemaData } from '@/@types/parseable/api/stream';
12-
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';
13+
1314

1415
type CreateStreamOpts = {
1516
streamName: string;
@@ -40,7 +41,7 @@ export const useLogStream = () => {
4041
isError: detectLogStreamSchemaIsError,
4142
isLoading: detectLogStreamSchemaIsLoading,
4243
} = useMutation(
43-
(data: { sampleLogs: any[]; onSuccess: (data: LogStreamSchemaData) => void }) =>
44+
(data: { sampleLogs: Record<string, any>; onSuccess: (data: LogStreamSchemaData) => void }) =>
4445
detectLogStreamSchema(data.sampleLogs),
4546
{
4647
onSuccess: (data, variables) => {

src/pages/Home/CreateStreamModal.tsx

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
import _ from 'lodash';
2+
import styles from './styles/CreateStreamModal.module.css';
3+
import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/AppProvider';
4+
import { CreatableSelect } from '@/components/Misc/CreatableSelect';
5+
import {
6+
FC,
7+
useCallback,
8+
useEffect,
9+
useState
10+
} from 'react';
11+
import { GetInputPropsReturnType, UseFormReturnType } from 'node_modules/@mantine/form/lib/types';
12+
import { IconInfoCircleFilled, IconPlus } from '@tabler/icons-react';
13+
import { LogStreamSchemaData } from '@/@types/parseable/api/stream';
14+
import { notifyError } from '@/utils/notification';
15+
import { useForm } from '@mantine/form';
16+
import { useLogStream } from '@/hooks/useLogStream';
117
import {
218
ActionIcon,
319
Box,
@@ -18,17 +34,7 @@ import {
1834
ThemeIcon,
1935
Tooltip,
2036
} from '@mantine/core';
21-
import { FC, useCallback, useEffect, useState } from 'react';
22-
import styles from './styles/CreateStreamModal.module.css';
23-
import { useLogStream } from '@/hooks/useLogStream';
24-
import { useForm } from '@mantine/form';
25-
import { IconInfoCircleFilled, IconPlus } from '@tabler/icons-react';
26-
import _ from 'lodash';
27-
import { CreatableSelect } from '@/components/Misc/CreatableSelect';
28-
import { useAppStore, appStoreReducers } from '@/layouts/MainLayout/providers/AppProvider';
29-
import { GetInputPropsReturnType, UseFormReturnType } from 'node_modules/@mantine/form/lib/types';
30-
import { notifyError } from '@/utils/notification';
31-
import { LogStreamSchemaData } from '@/@types/parseable/api/stream';
37+
3238

3339
const { toggleCreateStreamModal } = appStoreReducers;
3440

@@ -461,9 +467,7 @@ const DetectSchemaSection = (props: { form: StreamFormType }) => {
461467
} catch (e) {
462468
console.error('Error parsing json', e);
463469
}
464-
if (!_.isArray(logRecords)) {
465-
return notifyError({ message: 'Invalid JSON' });
466-
} else if (_.isEmpty(logRecords)) {
470+
if (_.isEmpty(logRecords)) {
467471
return notifyError({ message: 'No records found' });
468472
} else if (_.size(logRecords) > 10) {
469473
return notifyError({ message: 'More than 10 records found' });

0 commit comments

Comments
 (0)