@@ -6,11 +6,7 @@ import { log } from "./Utils";
66import { toast , ToastContainer } from "react-toastify" ;
77import "react-toastify/dist/ReactToastify.css" ;
88import { isTokenValid , fetchLogsWithToken , useCloudLoggingLogin , buildQueryFilter } from "./CloudLogging" ;
9-
10- const DATA_SOURCES = {
11- CLOUD_LOGGING : "cloudLogging" ,
12- EXTRA : "extra" ,
13- } ;
9+ import { HAS_EXTRA_DATA_SOURCE } from "./constants" ;
1410
1511const CloudLoggingFormComponent = ( { onLogsReceived, onFileUpload } ) => {
1612 const getStoredValue = ( key , defaultValue = "" ) => localStorage . getItem ( `datasetLoading_${ key } ` ) || defaultValue ;
@@ -181,38 +177,37 @@ const CloudLoggingFormComponent = ({ onLogsReceived, onFileUpload }) => {
181177
182178export default function DatasetLoading ( props ) {
183179 const [ activeDataSource , setActiveDataSource ] = useState (
184- localStorage . getItem ( "datasetLoading_dataSource" ) ||
185- ( ExtraDataSource . isAvailable ( ) ? DATA_SOURCES . EXTRA : DATA_SOURCES . CLOUD_LOGGING )
180+ localStorage . getItem ( "lastUsedDataSource" ) || ( HAS_EXTRA_DATA_SOURCE ? "extra" : "cloudLogging" )
186181 ) ;
187182
188183 useEffect ( ( ) => {
189- localStorage . setItem ( "datasetLoading_dataSource " , activeDataSource ) ;
184+ localStorage . setItem ( "lastUsedDataSource " , activeDataSource ) ;
190185 } , [ activeDataSource ] ) ;
191186
192- const isExtra = activeDataSource === DATA_SOURCES . EXTRA ;
187+ const isExtra = activeDataSource === "extra" ;
193188 const ExtraFormComponent = isExtra ? ExtraDataSource . getFormComponent ( props ) : null ;
194- const isExtraAvailable = ExtraDataSource . isAvailable ( ) ;
189+
190+ const renderSourceSelection = ( ) => {
191+ if ( ! HAS_EXTRA_DATA_SOURCE ) {
192+ return < button className = "active static" > Cloud Logging</ button > ;
193+ }
194+
195+ return (
196+ < >
197+ < button onClick = { ( ) => setActiveDataSource ( "cloudLogging" ) } className = { ! isExtra ? "active" : "" } >
198+ Cloud Logging
199+ </ button >
200+ < button onClick = { ( ) => setActiveDataSource ( "extra" ) } className = { isExtra ? "active" : "" } >
201+ { ExtraDataSource . getDisplayName ( ) }
202+ </ button >
203+ </ >
204+ ) ;
205+ } ;
195206
196207 return (
197208 < >
198209 < ToastContainer position = "top-right" autoClose = { 5000 } />
199- < div className = "data-source-toggle" >
200- { isExtraAvailable ? (
201- < >
202- < button
203- onClick = { ( ) => setActiveDataSource ( DATA_SOURCES . CLOUD_LOGGING ) }
204- className = { ! isExtra ? "active" : "" }
205- >
206- Cloud Logging
207- </ button >
208- < button onClick = { ( ) => setActiveDataSource ( DATA_SOURCES . EXTRA ) } className = { isExtra ? "active" : "" } >
209- { ExtraDataSource . getDisplayName ( ) }
210- </ button >
211- </ >
212- ) : (
213- < button className = "active static" > Cloud Logging</ button >
214- ) }
215- </ div >
210+ < div className = "data-source-toggle" > { renderSourceSelection ( ) } </ div >
216211
217212 { isExtra ? (
218213 ExtraFormComponent
0 commit comments