@@ -13,7 +13,15 @@ import {
1313 InputAdornment ,
1414 Pagination ,
1515 Stack ,
16- Link
16+ Link ,
17+ List ,
18+ ListItem ,
19+ ListItemButton ,
20+ Dialog ,
21+ DialogTitle ,
22+ DialogContent ,
23+ ListItemText ,
24+ DialogActions
1725} from '@mui/material' ;
1826import SearchIcon from '@mui/icons-material/Search' ;
1927import { CodeSnippet , SearchQueryRequest , SearchQueryResponse , TextualSearch } from '@site/src/services/models' ;
@@ -23,9 +31,17 @@ import Head from '@docusaurus/Head';
2331import Layout from '@theme/Layout' ;
2432import { TDSExamples } from '@site/src/components/HubFeatures/HubFeatures' ;
2533import AuthService from '@site/src/services/AuthService' ;
34+ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown' ;
2635
2736const RESULTS_PER_PAGE = 10 ;
2837
38+ interface DataSource {
39+ id : string ;
40+ name : string ;
41+ description ?: string ;
42+ url ?: string ;
43+ }
44+
2945const CodeSearchPage : React . FC = ( ) => {
3046 // Only run in browser context
3147 let filterString = ""
@@ -69,6 +85,13 @@ const CodeSearchPage: React.FC = () => {
6985 const [ page , setPage ] = useState ( 1 ) ;
7086 const [ total , setTotal ] = useState ( 0 ) ;
7187
88+ // New state for dialog and datasources:
89+ const [ dsDialogOpen , setDsDialogOpen ] = useState ( false ) ;
90+ const [ availableDataSources , setAvailableDataSources ] = useState < DataSource [ ] > ( [ ] ) ;
91+ const [ dataSourcesLoading , setDataSourcesLoading ] = useState ( false ) ;
92+
93+
94+
7295 const sortImplementationsToArray = ( implementations : any ) : any [ ] => {
7396 const jsonArray = Array . from ( Object . values ( implementations ) ) ;
7497
@@ -82,6 +105,31 @@ const CodeSearchPage: React.FC = () => {
82105 return jsonArray ;
83106 } ;
84107
108+ // Helper to open dialog and fetch datasources on-open:
109+ const handleOpenDatasourceDialog = async ( ) => {
110+ setDsDialogOpen ( true ) ;
111+ setDataSourcesLoading ( true ) ;
112+ try {
113+ const response = await LassoService . getDataSources ( ) ;
114+
115+ // Now extract: response.data.dataSources, convert to array:
116+ const dsMap = response . data . dataSources ;
117+ const dsArray = Object . values ( dsMap ) as DataSource [ ] ;
118+ setAvailableDataSources ( dsArray ) ;
119+ } catch ( error ) {
120+ // Handle error as you wish (alert, etc)
121+ setAvailableDataSources ( [ ] ) ;
122+ }
123+ setDataSourcesLoading ( false ) ;
124+ } ;
125+ const handleCloseDatasourceDialog = ( ) => setDsDialogOpen ( false ) ;
126+
127+ // When a datasource is selected:
128+ const handleSelectDatasource = ( selectedId : string ) => {
129+ setUrlDataSource ( selectedId ) ; // This changes which is used for searching
130+ setDsDialogOpen ( false ) ;
131+ } ;
132+
85133 const handleSearch = async ( ) => {
86134 // do a textual search
87135 let textualSearch = new TextualSearch ( )
@@ -109,24 +157,24 @@ const CodeSearchPage: React.FC = () => {
109157 console . log ( JSON . stringify ( request ) )
110158
111159 await AuthService . loginDefault ( ) . then (
112- ( response ) => {
160+ ( response ) => {
113161 // login successful
114162 console . log ( "Successfully logged in" )
115163
116-
117- } ,
118- ( error ) => {
164+
165+ } ,
166+ ( error ) => {
119167 const resMessage =
120- ( error . response &&
121- error . response . data &&
122- error . response . data . message ) ||
123- error . message ||
124- error . toString ( ) ;
125-
168+ ( error . response &&
169+ error . response . data &&
170+ error . response . data . message ) ||
171+ error . message ||
172+ error . toString ( ) ;
173+
126174 // FIXME
127175 console . log ( "Login attempt failed " + error )
128- }
129- )
176+ }
177+ )
130178
131179 await LassoService . queryImplementationsForDataSource ( lassoDataSource , request ) . then (
132180 ( response ) => {
@@ -226,6 +274,20 @@ const CodeSearchPage: React.FC = () => {
226274 Search
227275 </ Button >
228276 </ Grid >
277+
278+ { /* NEW: Datasource selector button */ }
279+ < Grid item >
280+ < Button
281+ variant = "outlined"
282+ color = "secondary"
283+ onClick = { handleOpenDatasourceDialog }
284+ endIcon = { < ArrowDropDownIcon /> }
285+ >
286+ Datasource: { urlDataSource }
287+ </ Button >
288+ </ Grid >
289+
290+ < Grid item >
229291 < Stack direction = "row" spacing = { 1 } alignItems = "center" sx = { { mt : 1 , mb : 3 } } >
230292 < Typography variant = "body2" color = "text.secondary" >
231293 Learn more about the < b > LQL Query Language</ b > :
@@ -239,9 +301,44 @@ const CodeSearchPage: React.FC = () => {
239301 Documentation
240302 </ Link >
241303 </ Stack >
242- </ Grid >
304+ </ Grid >
305+
243306
307+ </ Grid >
244308
309+ { /* Datasource selection dialog */ }
310+ < Dialog open = { dsDialogOpen } onClose = { handleCloseDatasourceDialog } fullWidth >
311+ < DialogTitle > Select a Datasource</ DialogTitle >
312+ < DialogContent dividers >
313+ { dataSourcesLoading ? (
314+ < CircularProgress />
315+ ) : (
316+ < List >
317+ { availableDataSources . map ( ds => (
318+ < ListItem key = { ds . id } disablePadding >
319+ < ListItemButton onClick = { ( ) => handleSelectDatasource ( ds . id ) } >
320+ < ListItemText
321+ primary = { ds . name }
322+ secondary = { ds . description }
323+ style = { ds . id === urlDataSource ? { fontWeight : 'bold' } : { } }
324+ />
325+ </ ListItemButton >
326+ </ ListItem >
327+ ) ) }
328+ { availableDataSources . length === 0 && (
329+ < Typography color = "text.secondary" >
330+ No datasources found.
331+ </ Typography >
332+ ) }
333+ </ List >
334+ ) }
335+ </ DialogContent >
336+ < DialogActions >
337+ < Button onClick = { handleCloseDatasourceDialog } color = "primary" >
338+ Close
339+ </ Button >
340+ </ DialogActions >
341+ </ Dialog >
245342
246343 < div style = { { minHeight : 320 , marginTop : 40 } } >
247344 { ! loading && searched && total > 0 && (
0 commit comments