Skip to content

Commit 13859be

Browse files
authored
fix: make the list of scripts 250 (#6174)
* fix: make the list of scripts 250 * feat: integrate API searches
1 parent 9e12b53 commit 13859be

File tree

4 files changed

+53
-31
lines changed

4 files changed

+53
-31
lines changed

src/dataExplorer/components/OpenScript.tsx

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
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'
1919
import {getOrg} from 'src/organizations/selectors'
2020
import {ResultsContext} from 'src/dataExplorer/components/ResultsContext'
2121
import {QueryContext} from 'src/shared/contexts/query'
22+
import {debouncer} from 'src/dataExplorer/shared/utils'
2223

2324
let 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

src/dataExplorer/components/SaveAsScript.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
@import '@influxdata/clockface/dist/variables.scss';
2+
3+
.data-source--list__empty {
4+
display: flex;
5+
align-items: center;
6+
justify-content: center;
7+
user-select: none;
8+
color: $cf-grey-45;
9+
height: 300px;
10+
}
11+
12+
.open-script__menu-items {
13+
background-color: #000;
14+
}
15+
116
.save-script-overlay__warning-text {
217
margin-bottom: 25px;
318
}

src/dataExplorer/context/fluxQueryBuilder.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,10 @@ import {MeasurementsContext} from 'src/dataExplorer/context/measurements'
1313
import {FieldsContext} from 'src/dataExplorer/context/fields'
1414
import {PersistanceContext} from 'src/dataExplorer/context/persistance'
1515
import {TagsContext} from 'src/dataExplorer/context/tags'
16-
16+
import {debouncer} from 'src/dataExplorer/shared/utils'
1717
// Types
1818
import {Bucket, TagKeyValuePair} from 'src/types'
1919

20-
const DEBOUNCE_TIMEOUT = 500
21-
let timer: ReturnType<typeof setTimeout>
22-
type NOOP = () => void
23-
const debouncer = (action: NOOP): void => {
24-
clearTimeout(timer)
25-
timer = setTimeout(() => {
26-
action()
27-
timer = null
28-
}, DEBOUNCE_TIMEOUT)
29-
}
30-
3120
const DEFAULT_SELECTED_TAG_VALUES: SelectedTagValues = {}
3221
interface SelectedTagValues {
3322
[key: string]: string[]

src/dataExplorer/shared/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,14 @@ export const useSessionStorage = (keyName: string, defaultValue: any) => {
7676

7777
return [storedValue, setValue]
7878
}
79+
80+
const DEBOUNCE_TIMEOUT = 500
81+
let timer: ReturnType<typeof setTimeout>
82+
type NOOP = () => void
83+
export const debouncer = (action: NOOP): void => {
84+
clearTimeout(timer)
85+
timer = setTimeout(() => {
86+
action()
87+
timer = null
88+
}, DEBOUNCE_TIMEOUT)
89+
}

0 commit comments

Comments
 (0)