Skip to content

Commit f0e8fc0

Browse files
committed
[Fleet] Use Fleet Server indices in the search bar
1 parent e221992 commit f0e8fc0

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

x-pack/plugins/fleet/public/applications/fleet/components/search_bar.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,22 @@ import {
1414
import { useStartServices } from '../hooks';
1515
import { INDEX_NAME, AGENT_SAVED_OBJECT_TYPE } from '../constants';
1616

17-
const HIDDEN_FIELDS = [`${AGENT_SAVED_OBJECT_TYPE}.actions`];
17+
const HIDDEN_FIELDS = [`${AGENT_SAVED_OBJECT_TYPE}.actions`, '_id', '_index'];
1818

1919
interface Props {
2020
value: string;
21-
fieldPrefix: string;
21+
fieldPrefix?: string;
2222
onChange: (newValue: string, submit?: boolean) => void;
2323
placeholder?: string;
24+
indexPattern?: string;
2425
}
2526

2627
export const SearchBar: React.FunctionComponent<Props> = ({
2728
value,
2829
fieldPrefix,
2930
onChange,
3031
placeholder,
32+
indexPattern = INDEX_NAME,
3133
}) => {
3234
const { data } = useStartServices();
3335
const [indexPatternFields, setIndexPatternFields] = useState<IFieldType[]>();
@@ -49,10 +51,10 @@ export const SearchBar: React.FunctionComponent<Props> = ({
4951
const fetchFields = async () => {
5052
try {
5153
const _fields: IFieldType[] = await data.indexPatterns.getFieldsForWildcard({
52-
pattern: INDEX_NAME,
54+
pattern: indexPattern,
5355
});
5456
const fields = (_fields || []).filter((field) => {
55-
if (fieldPrefix && field.name.startsWith(fieldPrefix)) {
57+
if (!fieldPrefix || field.name.startsWith(fieldPrefix)) {
5658
for (const hiddenField of HIDDEN_FIELDS) {
5759
if (field.name.startsWith(hiddenField)) {
5860
return false;
@@ -67,7 +69,7 @@ export const SearchBar: React.FunctionComponent<Props> = ({
6769
}
6870
};
6971
fetchFields();
70-
}, [data.indexPatterns, fieldPrefix]);
72+
}, [data.indexPatterns, fieldPrefix, indexPattern]);
7173

7274
return (
7375
<QueryStringInput
@@ -77,7 +79,7 @@ export const SearchBar: React.FunctionComponent<Props> = ({
7779
indexPatternFields
7880
? [
7981
{
80-
title: INDEX_NAME,
82+
title: indexPattern,
8183
fields: indexPatternFields,
8284
},
8385
]

x-pack/plugins/fleet/public/applications/fleet/constants/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export {
1515
AGENT_SAVED_OBJECT_TYPE,
1616
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
1717
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
18+
// Fleet Server index
19+
AGENTS_INDEX,
20+
ENROLLMENT_API_KEYS_INDEX,
1821
} from '../../../../common';
1922

2023
export * from './page_paths';

x-pack/plugins/fleet/public/applications/fleet/sections/agents/agent_list_page/components/search_and_filter_bar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import { i18n } from '@kbn/i18n';
1818
import { FormattedMessage } from '@kbn/i18n/react';
1919
import { AgentPolicy } from '../../../../types';
2020
import { SearchBar } from '../../../../components';
21-
import { AGENT_SAVED_OBJECT_TYPE } from '../../../../constants';
21+
import { AGENTS_INDEX, AGENT_SAVED_OBJECT_TYPE } from '../../../../constants';
22+
import { useConfig } from '../../../../hooks';
2223

2324
const statusFilters = [
2425
{
@@ -76,6 +77,7 @@ export const SearchAndFilterBar: React.FunctionComponent<{
7677
showUpgradeable,
7778
onShowUpgradeableChange,
7879
}) => {
80+
const config = useConfig();
7981
// Policies state for filtering
8082
const [isAgentPoliciesFilterOpen, setIsAgentPoliciesFilterOpen] = useState<boolean>(false);
8183

@@ -109,7 +111,13 @@ export const SearchAndFilterBar: React.FunctionComponent<{
109111
onSubmitSearch(newSearch);
110112
}
111113
}}
112-
fieldPrefix={AGENT_SAVED_OBJECT_TYPE}
114+
{...(config.agents.fleetServerEnabled
115+
? {
116+
indexPattern: AGENTS_INDEX,
117+
}
118+
: {
119+
fieldPrefix: AGENT_SAVED_OBJECT_TYPE,
120+
})}
113121
/>
114122
</EuiFlexItem>
115123
<EuiFlexItem grow={2}>

x-pack/plugins/fleet/public/applications/fleet/sections/agents/enrollment_token_list_page/index.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import {
2020
HorizontalAlignment,
2121
} from '@elastic/eui';
2222
import { FormattedMessage, FormattedDate } from '@kbn/i18n/react';
23-
import { ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE } from '../../../constants';
23+
import {
24+
ENROLLMENT_API_KEYS_INDEX,
25+
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
26+
} from '../../../constants';
2427
import {
2528
useBreadcrumbs,
2629
usePagination,
@@ -29,6 +32,7 @@ import {
2932
sendGetOneEnrollmentAPIKey,
3033
useStartServices,
3134
sendDeleteOneEnrollmentAPIKey,
35+
useConfig,
3236
} from '../../../hooks';
3337
import { EnrollmentAPIKey } from '../../../types';
3438
import { SearchBar } from '../../../components/search_bar';
@@ -154,6 +158,7 @@ const DeleteButton: React.FunctionComponent<{ apiKey: EnrollmentAPIKey; refresh:
154158

155159
export const EnrollmentTokenListPage: React.FunctionComponent<{}> = () => {
156160
useBreadcrumbs('fleet_enrollment_tokens');
161+
const config = useConfig();
157162
const [flyoutOpen, setFlyoutOpen] = useState(false);
158163
const [search, setSearch] = useState('');
159164
const { pagination, setPagination, pageSizeOptions } = usePagination();
@@ -281,7 +286,13 @@ export const EnrollmentTokenListPage: React.FunctionComponent<{}> = () => {
281286
});
282287
setSearch(newSearch);
283288
}}
284-
fieldPrefix={ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE}
289+
{...(config.agents.fleetServerEnabled
290+
? {
291+
indexPattern: ENROLLMENT_API_KEYS_INDEX,
292+
}
293+
: {
294+
fieldPrefix: ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
295+
})}
285296
/>
286297
</EuiFlexItem>
287298
<EuiFlexItem grow={false}>

0 commit comments

Comments
 (0)