33 * or more contributor license agreements. Licensed under the Elastic License;
44 * you may not use this file except in compliance with the Elastic License.
55 */
6- import React , { useState , useMemo } from 'react' ;
6+ import React , { useState , useMemo , useCallback } from 'react' ;
77import {
88 EuiBasicTable ,
99 EuiButton ,
@@ -144,13 +144,20 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
144144 const [ search , setSearch ] = useState ( defaultKuery ) ;
145145 const { pagination, pageSizeOptions, setPagination } = usePagination ( ) ;
146146
147- // Configs state ( for filtering)
147+ // Configs state for filtering
148148 const [ isConfigsFilterOpen , setIsConfigsFilterOpen ] = useState < boolean > ( false ) ;
149149 const [ selectedConfigs , setSelectedConfigs ] = useState < string [ ] > ( [ ] ) ;
150+
150151 // Status for filtering
151152 const [ isStatusFilterOpen , setIsStatutsFilterOpen ] = useState < boolean > ( false ) ;
152153 const [ selectedStatus , setSelectedStatus ] = useState < string [ ] > ( [ ] ) ;
153154
155+ const clearFilters = useCallback ( ( ) => {
156+ setSearch ( '' ) ;
157+ setSelectedConfigs ( [ ] ) ;
158+ setSelectedStatus ( [ ] ) ;
159+ } , [ setSearch , setSelectedConfigs , setSelectedStatus ] ) ;
160+
154161 // Add a config id to current search
155162 const addConfigFilter = ( configId : string ) => {
156163 setSelectedConfigs ( [ ...selectedConfigs , configId ] ) ;
@@ -500,23 +507,21 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
500507 < EuiBasicTable < Agent >
501508 className = "fleet__agentList__table"
502509 data-test-subj = "fleetAgentListTable"
503- loading = { isLoading && agentsRequest . isInitialRequest }
510+ loading = { isLoading }
504511 hasActions = { true }
505512 noItemsMessage = {
506513 isLoading && agentsRequest . isInitialRequest ? (
507514 < FormattedMessage
508515 id = "xpack.ingestManager.agentList.loadingAgentsMessage"
509516 defaultMessage = "Loading agents…"
510517 />
511- ) : ! search . trim ( ) && selectedConfigs . length === 0 && totalAgents === 0 ? (
512- emptyPrompt
513- ) : (
518+ ) : search . trim ( ) || selectedConfigs . length || selectedStatus . length ? (
514519 < FormattedMessage
515520 id = "xpack.ingestManager.agentList.noFilteredAgentsPrompt"
516521 defaultMessage = "No agents found. {clearFiltersLink}"
517522 values = { {
518523 clearFiltersLink : (
519- < EuiLink onClick = { ( ) => setSearch ( '' ) } >
524+ < EuiLink onClick = { ( ) => clearFilters ( ) } >
520525 < FormattedMessage
521526 id = "xpack.ingestManager.agentList.clearFiltersLinkText"
522527 defaultMessage = "Clear filters"
@@ -525,7 +530,9 @@ export const AgentListPage: React.FunctionComponent<{}> = () => {
525530 ) ,
526531 } }
527532 />
528- )
533+ ) : ! isLoading && totalAgents === 0 ? (
534+ emptyPrompt
535+ ) : undefined
529536 }
530537 items = { totalAgents ? agents : [ ] }
531538 itemId = "id"
0 commit comments