66 ComponentStatus ,
77 IconFont ,
88 Input ,
9- List ,
9+ Dropdown ,
1010 TechnoSpinner ,
1111 Overlay ,
1212 EmptyState ,
@@ -19,6 +19,7 @@ import {useSelector} from 'react-redux'
1919import { getOrg } from 'src/organizations/selectors'
2020import { ResultsContext } from 'src/dataExplorer/components/ResultsContext'
2121import { QueryContext } from 'src/shared/contexts/query'
22+ import { debouncer } from 'src/dataExplorer/shared/utils'
2223
2324let getScripts
2425
@@ -41,11 +42,11 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
4142 const history = useHistory ( )
4243 const org = useSelector ( getOrg )
4344
44- const handleGetScripts = useCallback ( async ( ) => {
45+ const handleGetScripts = useCallback ( async ( name : string = '' ) => {
4546 try {
4647 if ( getScripts ) {
4748 setLoading ( RemoteDataState . Loading )
48- const resp = await getScripts ( { } )
49+ const resp = await getScripts ( { query : { limit : 250 , name } } )
4950
5051 if ( resp . status !== 200 ) {
5152 throw new Error ( resp . data . message )
@@ -60,7 +61,17 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
6061 setLoading ( RemoteDataState . Error )
6162 console . error ( { error} )
6263 }
63- } , [ getScripts ] )
64+ } , [ ] )
65+
66+ const handleSearchTerm = useCallback (
67+ ( name : string ) => {
68+ setSearchTerm ( name )
69+ debouncer ( ( ) => {
70+ handleGetScripts ( name )
71+ } )
72+ } ,
73+ [ handleGetScripts ]
74+ )
6475
6576 const handleOpenScript = ( ) => {
6677 setStatus ( RemoteDataState . NotStarted )
@@ -96,33 +107,27 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
96107 }
97108
98109 if ( loading === RemoteDataState . Done ) {
99- const filteredScripts = scripts . filter ( script =>
100- script . name . includes ( searchTerm )
101- )
102-
103110 let list = (
104- < List >
105- { filteredScripts . map ( script => (
106- < List . Item
111+ < >
112+ { scripts . map ( script => (
113+ < Dropdown . Item
107114 key = { script . id }
108115 value = { script . name }
109116 onClick = { ( ) => setSelectedScript ( script ) }
110117 selected = { script . name === selectedScript ?. name }
111- title = { script }
112- wrapText = { true }
113118 >
114119 { script . name }
115- </ List . Item >
120+ </ Dropdown . Item >
116121 ) ) }
117- </ List >
122+ </ >
118123 )
119- if ( filteredScripts . length === 0 && searchTerm ) {
124+ if ( scripts . length === 0 && searchTerm ) {
120125 list = (
121126 < EmptyState className = "data-source--list__no-results" >
122127 < p > { `No Scripts match "${ searchTerm } "` } </ p >
123128 </ EmptyState >
124129 )
125- } else if ( filteredScripts . length === 0 && ! searchTerm ) {
130+ } else if ( scripts . length === 0 && ! searchTerm ) {
126131 list = (
127132 < EmptyState className = "data-source--list__no-results" >
128133 < p > No Scripts found</ p >
@@ -139,9 +144,11 @@ const OpenScript: FC<Props> = ({onCancel, onClose}) => {
139144 size = { ComponentSize . Medium }
140145 value = { searchTerm }
141146 placeholder = "Search Scripts"
142- onChange = { evt => setSearchTerm ( evt . target . value ) }
147+ onChange = { evt => handleSearchTerm ( evt . target . value ) }
143148 />
144- < List > { list } </ List >
149+ < Dropdown . Menu className = "open-script__menu-items" maxHeight = { 300 } >
150+ { list }
151+ </ Dropdown . Menu >
145152 </ Overlay . Body >
146153 < Overlay . Footer >
147154 < Button
0 commit comments