|
61 | 61 | /** @type {import('$commonTypes').LabelValuePair[]} */ |
62 | 62 | let agentLabelOptions = []; |
63 | 63 |
|
64 | | - /** @type {string[]} */ |
65 | | - let selectedAgentTypes = []; |
66 | | - /** @type {string[]} */ |
67 | | - let selectedAgentLabels = []; |
| 64 | + /** @type {{ name: string, types: string[], labels: string[] }} */ |
| 65 | + let searchItem = { |
| 66 | + name: '', |
| 67 | + types: [], |
| 68 | + labels: [] |
| 69 | + }; |
68 | 70 |
|
69 | 71 | onMount(async () => { |
70 | 72 | isPageMounted = true; |
|
98 | 100 | page: firstPage, |
99 | 101 | count: 0 |
100 | 102 | }, |
101 | | - types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null, |
102 | | - labels: selectedAgentLabels?.length > 0 ? selectedAgentLabels : null, |
| 103 | + types: searchItem.types?.length > 0 ? searchItem.types : null, |
| 104 | + labels: searchItem.labels?.length > 0 ? searchItem.labels : null, |
103 | 105 | similarName: event.payload?.trim() || null |
104 | 106 | }; |
105 | 107 |
|
|
221 | 223 |
|
222 | 224 | getPagedAgents(); |
223 | 225 | } |
| 226 | +
|
| 227 | + /** @param {any} e */ |
| 228 | + function changeSearchName(e) { |
| 229 | + searchItem.name = e.target.value || ''; |
| 230 | + filter = { |
| 231 | + ...filter, |
| 232 | + similarName: searchItem.name?.trim() |
| 233 | + }; |
| 234 | + } |
| 235 | +
|
| 236 | + /** @param {any} e */ |
| 237 | + function searchKeyDown(e) { |
| 238 | + if (e.key === 'Enter' && filter?.similarName) { |
| 239 | + e.preventDefault(); |
| 240 | + search(); |
| 241 | + } |
| 242 | + } |
224 | 243 | |
225 | 244 | /** @param {any} e */ |
226 | 245 | function selectAgentTypeOption(e) { |
227 | 246 | // @ts-ignore |
228 | | - selectedAgentTypes = e.detail.selecteds?.map(x => x.label) || []; |
| 247 | + searchItem.types = e.detail.selecteds?.map(x => x.label) || []; |
229 | 248 | } |
230 | 249 |
|
231 | 250 | /** @param {any} e */ |
232 | 251 | function selectAgentLabelOption(e) { |
233 | 252 | // @ts-ignore |
234 | | - selectedAgentLabels = e.detail.selecteds?.map(x => x.label) || []; |
| 253 | + searchItem.labels = e.detail.selecteds?.map(x => x.label) || []; |
235 | 254 | } |
236 | 255 |
|
237 | 256 | function search() { |
|
241 | 260 | } |
242 | 261 |
|
243 | 262 | function reset() { |
244 | | - selectedAgentTypes = []; |
245 | | - selectedAgentLabels = []; |
| 263 | + searchItem = { |
| 264 | + name: '', |
| 265 | + types: [], |
| 266 | + labels: [] |
| 267 | + }; |
246 | 268 |
|
247 | 269 | filter = { ...initFilter }; |
248 | 270 | getPagedAgents(); |
|
251 | 273 | function refreshFilter() { |
252 | 274 | filter = { |
253 | 275 | ...filter, |
254 | | - types: selectedAgentTypes?.length > 0 ? selectedAgentTypes : null, |
255 | | - labels: selectedAgentLabels?.length > 0 ? selectedAgentLabels : null, |
| 276 | + types: searchItem.types?.length > 0 ? searchItem.types : null, |
| 277 | + labels: searchItem.labels?.length > 0 ? searchItem.labels : null, |
256 | 278 | pager: initFilter.pager |
257 | 279 | }; |
258 | 280 | } |
|
285 | 307 | type="text" |
286 | 308 | placeholder="Search by name" |
287 | 309 | style="width: fit-content;" |
288 | | - value={filter.similarName} |
289 | | - on:input={e => filter.similarName = e.target.value?.trim()} |
| 310 | + value={searchItem.name} |
| 311 | + on:input={e => changeSearchName(e)} |
| 312 | + on:keydown={e => searchKeyDown(e)} |
290 | 313 | /> |
291 | 314 | <Select |
292 | 315 | tag={'agent-label-select'} |
293 | 316 | placeholder={'Select labels'} |
294 | 317 | selectedText={'labels'} |
295 | 318 | multiSelect |
296 | 319 | searchMode |
297 | | - selectedValues={selectedAgentLabels} |
| 320 | + selectedValues={searchItem.labels} |
298 | 321 | options={agentLabelOptions} |
299 | 322 | on:select={e => selectAgentLabelOption(e)} |
300 | 323 | /> |
|
304 | 327 | selectedText={'types'} |
305 | 328 | multiSelect |
306 | 329 | searchMode |
307 | | - selectedValues={selectedAgentTypes} |
| 330 | + selectedValues={searchItem.types} |
308 | 331 | options={agentTypeOptions} |
309 | 332 | on:select={e => selectAgentTypeOption(e)} |
310 | 333 | /> |
|
0 commit comments