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

Commit 9fafe70

Browse files
committed
schema fetch logic
1 parent 2ef9c0d commit 9fafe70

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

src/pages/Correlation/index.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ import { useFetchStreamData } from '@/hooks/useFetchStreamData';
2828
import useParamsController from './hooks/useParamsController';
2929

3030
const { setStreamForCorrelation, setTimeRange } = appStoreReducers;
31-
const { setSelectedFields, setCorrelationCondition, setActiveCorrelation, setPageAndPageData, setTargetPage } =
32-
correlationStoreReducers;
31+
import { getLogStreamSchema } from '@/api/logStream';
32+
const {
33+
setSelectedFields,
34+
setCorrelationCondition,
35+
setActiveCorrelation,
36+
setPageAndPageData,
37+
setTargetPage,
38+
setStreamSchema,
39+
} = correlationStoreReducers;
3340

3441
const Correlation = () => {
3542
useDocumentTitle('Parseable | Correlation');
@@ -62,6 +69,7 @@ const Correlation = () => {
6269
(isSavedCorrelation && activeCorrelation?.tableConfigs.map((config: { tableName: string }) => config.tableName)) ||
6370
[];
6471
const { isLoading: multipleSchemasLoading } = useGetMultipleStreamSchemas(streamsToFetch);
72+
const [schemaLoad, setSchemaLoad] = useState<boolean>(false);
6573

6674
const { getCorrelationData, loadingState, error: errorMessage } = useCorrelationQueryLogs();
6775
const { getFetchStreamData, loading: streamsLoading } = useFetchStreamData();
@@ -140,6 +148,22 @@ const Correlation = () => {
140148
type: 'custom',
141149
}),
142150
);
151+
if (!activeCorrelation) return;
152+
153+
const fetchSchema = async (streamName: string) => {
154+
setSchemaLoad(true);
155+
try {
156+
const schema = await getLogStreamSchema(streamName);
157+
setCorrelationData((store) => setStreamSchema(store, schema.data, streamName));
158+
} catch (error) {
159+
console.log(error);
160+
} finally {
161+
setSchemaLoad(false);
162+
}
163+
};
164+
const streamNames = activeCorrelation.tableConfigs.map((config: { tableName: string }) => config.tableName);
165+
streamNames.forEach(async (el) => await fetchSchema(el));
166+
143167
setSelect1Value({ value: null, dataType: '' });
144168
setSelect2Value({ value: null, dataType: '' });
145169
setCorrelationData((store) => setCorrelationCondition(store, ''));
@@ -154,21 +178,22 @@ const Correlation = () => {
154178
}, [streamForCorrelation, fields]);
155179

156180
useEffect(() => {
157-
if (isCorrelatedData) {
181+
if (isCorrelatedData && !schemaLoad) {
158182
getCorrelationData();
159183
} else {
160184
getFetchStreamData();
161185
}
162-
}, [currentOffset, timeRange]);
186+
}, [currentOffset, timeRange, schemaLoad]);
163187

164188
useEffect(() => {
189+
if (schemaLoad) return;
165190
updateCorrelationCondition();
166191
if (activeCorrelation && correlationCondition && isSavedCorrelation) {
167192
refetchCount();
168193
getCorrelationData();
169194
}
170195
correlationCondition && setIsCorrelationEnabled(true);
171-
}, [select1Value, select2Value, activeCorrelation, correlationCondition]);
196+
}, [select1Value, select2Value, activeCorrelation, correlationCondition, schemaLoad]);
172197

173198
const updateCorrelationCondition = () => {
174199
if (select1Value.value && select2Value.value) {
@@ -196,14 +221,14 @@ const Correlation = () => {
196221
}
197222
}, [loadingState, currentPage]);
198223

199-
if (isLoading || !Object.keys(fields) || !Object.keys(selectedFields)) return;
224+
if (isLoading || schemaLoad || !Object.keys(fields) || !Object.keys(selectedFields)) return;
200225

201226
return (
202227
<Box className={classes.correlationWrapper}>
203228
<SavedCorrelationsModal />
204229
<SaveCorrelationModal />
205230
<CorrelationSidebar
206-
isLoading={isStreamsLoading}
231+
isLoading={isStreamsLoading || multipleSchemasLoading}
207232
loadingState={loadingState}
208233
setSelect1Value={setSelect1Value}
209234
setSelect2Value={setSelect2Value}

src/pages/Stream/components/PrimaryToolbar.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ import { appStoreReducers, useAppStore } from '@/layouts/MainLayout/providers/Ap
55
import { filterStoreReducers, useFilterStore } from '../providers/FilterProvider';
66
import { logsStoreReducers, useLogsStore } from '../providers/LogsProvider';
77
import { useCallback, useEffect } from 'react';
8-
import { useNavigate, useParams } from 'react-router-dom';
8+
import { useParams } from 'react-router-dom';
99

10-
import { CorrelationIcon } from '@/components/Navbar/components/CorrelationIcon';
1110
import IconButton from '@/components/Button/IconButton';
1211
import Querier from './Querier';
1312
import RefreshInterval from '@/components/Header/RefreshInterval';
@@ -22,7 +21,6 @@ import { notifications } from '@mantine/notifications';
2221

2322
const { toggleDeleteModal, onToggleView } = logsStoreReducers;
2423
const { toggleSavedFiltersModal } = filterStoreReducers;
25-
const { setStreamForCorrelation } = appStoreReducers;
2624
const renderMaximizeIcon = () => <IconMaximize size={px('1rem')} stroke={1.5} />;
2725
const renderDeleteIcon = () => <IconTrash data-id="delete-stream-btn" size={px('1rem')} stroke={1.5} />;
2826

@@ -46,24 +44,6 @@ const SavedFiltersButton = () => {
4644
);
4745
};
4846

49-
const AddCorrelationButton = () => {
50-
const navigate = useNavigate();
51-
const [, setAppStore] = useAppStore(() => null);
52-
53-
return (
54-
<Button
55-
className={classes.savedFiltersBtn}
56-
h="100%"
57-
onClick={() => {
58-
setAppStore((store) => setStreamForCorrelation(store, store.currentStream || ''));
59-
navigate('/correlation');
60-
}}
61-
leftSection={<CorrelationIcon stroke={'#000000'} strokeWidth={1} />}>
62-
Correlate
63-
</Button>
64-
);
65-
};
66-
6747
const DeleteStreamButton = () => {
6848
const [, setLogsStore] = useLogsStore(() => null);
6949
const onClick = useCallback(() => setLogsStore(toggleDeleteModal), []);
@@ -122,7 +102,6 @@ const PrimaryToolbar = () => {
122102
{view === 'explore' ? (
123103
<Stack style={{ flexDirection: 'row', height: STREAM_PRIMARY_TOOLBAR_HEIGHT }} w="100%">
124104
<StreamDropdown />
125-
<AddCorrelationButton />
126105
<Querier />
127106
<SavedFiltersButton />
128107
<TimeRange />

0 commit comments

Comments
 (0)