@@ -28,8 +28,15 @@ import { useFetchStreamData } from '@/hooks/useFetchStreamData';
2828import useParamsController from './hooks/useParamsController' ;
2929
3030const { 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
3441const 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 }
0 commit comments