Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.

Commit b773e4b

Browse files
authored
Formatting timestamps in local timezone & auto detect datatype support (#343)
1 parent 51c1fc1 commit b773e4b

File tree

12 files changed

+328
-52
lines changed

12 files changed

+328
-52
lines changed

src/api/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export const LOG_STREAMS_RETRNTION_URL = (streamName: string) => `${LOG_STREAM_L
3535
export const LOG_STREAMS_STATS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/stats`;
3636
export const LOG_STREAMS_INFO_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/info`;
3737
export const DELETE_STREAMS_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`;
38+
export const DETECT_LOG_STREAM_SCHEMA_URL = `${LOG_STREAM_LIST_URL}/schema/detect`;
3839
export const CREATE_STREAM_URL = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}`;
3940
export const LOG_STREAM_HOT_TIER = (streamName: string) => `${LOG_STREAM_LIST_URL}/${streamName}/hottier`;
4041

src/api/logStream.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
DELETE_SAVED_FILTERS_URL,
1515
CREATE_SAVED_FILTERS_URL,
1616
LOG_STREAM_HOT_TIER,
17+
DETECT_LOG_STREAM_SCHEMA_URL,
1718
} from './constants';
1819
import { HotTierConfig, LogStreamData, LogStreamSchemaData } from '@/@types/parseable/api/stream';
1920

@@ -65,6 +66,10 @@ export const deleteLogStream = (streamName: string) => {
6566
return Axios().delete(DELETE_STREAMS_URL(streamName));
6667
};
6768

69+
export const detectLogStreamSchema = (data: any) => {
70+
return Axios().post(DETECT_LOG_STREAM_SCHEMA_URL, data);
71+
};
72+
6873
export const createLogStream = (streamName: string, data: any, headers: any) => {
6974
return Axios().put(CREATE_STREAM_URL(streamName), data, { headers });
7075
};

src/hooks/useLogStream.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { useMutation, useQuery } from 'react-query';
2-
import { deleteLogStream, getLogStreamList, createLogStream, updateLogStream } from '@/api/logStream';
2+
import {
3+
deleteLogStream,
4+
getLogStreamList,
5+
createLogStream,
6+
updateLogStream,
7+
detectLogStreamSchema,
8+
} from '@/api/logStream';
39
import { AxiosError, isAxiosError } from 'axios';
410
import { notifyError, notifySuccess } from '@/utils/notification';
11+
import { LogStreamSchemaData } from '@/@types/parseable/api/stream';
512

613
type CreateStreamOpts = {
714
streamName: string;
@@ -24,6 +31,27 @@ export const useLogStream = () => {
2431
},
2532
});
2633

34+
const {
35+
mutate: detectLogStreamSchemaMutation,
36+
isSuccess: detectLogStreamSchemaIsSuccess,
37+
isError: detectLogStreamSchemaIsError,
38+
isLoading: detectLogStreamSchemaIsLoading,
39+
} = useMutation(
40+
(data: { sampleLogs: any[]; onSuccess: (data: LogStreamSchemaData) => void }) =>
41+
detectLogStreamSchema(data.sampleLogs),
42+
{
43+
onSuccess: (data, variables) => {
44+
variables.onSuccess && variables.onSuccess(data.data);
45+
notifySuccess({ message: `Detected schema successfully` });
46+
},
47+
onError: (data: AxiosError) => {
48+
if (isAxiosError(data) && typeof data.message === 'string') {
49+
notifyError({ message: data.message });
50+
}
51+
},
52+
},
53+
);
54+
2755
const {
2856
mutate: createLogStreamMutation,
2957
isSuccess: createLogStreamIsSuccess,
@@ -109,5 +137,9 @@ export const useLogStream = () => {
109137
updateLogStreamIsSuccess,
110138
updateLogStreamIsError,
111139
updateLogStreamIsLoading,
140+
detectLogStreamSchemaMutation,
141+
detectLogStreamSchemaIsSuccess,
142+
detectLogStreamSchemaIsError,
143+
detectLogStreamSchemaIsLoading,
112144
};
113145
};

0 commit comments

Comments
 (0)