Skip to content

Commit

Permalink
[Fleet] Use Fleet Server indices in the search bar (elastic#90835)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored Feb 10, 2021
1 parent 7e80bb3 commit f95bfe8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ import {
import { useStartServices } from '../hooks';
import { INDEX_NAME, AGENT_SAVED_OBJECT_TYPE } from '../constants';

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

interface Props {
value: string;
fieldPrefix: string;
fieldPrefix?: string;
onChange: (newValue: string, submit?: boolean) => void;
placeholder?: string;
indexPattern?: string;
}

export const SearchBar: React.FunctionComponent<Props> = ({
value,
fieldPrefix,
onChange,
placeholder,
indexPattern = INDEX_NAME,
}) => {
const { data } = useStartServices();
const [indexPatternFields, setIndexPatternFields] = useState<IFieldType[]>();
Expand All @@ -49,10 +51,10 @@ export const SearchBar: React.FunctionComponent<Props> = ({
const fetchFields = async () => {
try {
const _fields: IFieldType[] = await data.indexPatterns.getFieldsForWildcard({
pattern: INDEX_NAME,
pattern: indexPattern,
});
const fields = (_fields || []).filter((field) => {
if (fieldPrefix && field.name.startsWith(fieldPrefix)) {
if (!fieldPrefix || field.name.startsWith(fieldPrefix)) {
for (const hiddenField of HIDDEN_FIELDS) {
if (field.name.startsWith(hiddenField)) {
return false;
Expand All @@ -67,7 +69,7 @@ export const SearchBar: React.FunctionComponent<Props> = ({
}
};
fetchFields();
}, [data.indexPatterns, fieldPrefix]);
}, [data.indexPatterns, fieldPrefix, indexPattern]);

return (
<QueryStringInput
Expand All @@ -77,7 +79,7 @@ export const SearchBar: React.FunctionComponent<Props> = ({
indexPatternFields
? [
{
title: INDEX_NAME,
title: indexPattern,
fields: indexPatternFields,
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export {
AGENT_SAVED_OBJECT_TYPE,
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
PACKAGE_POLICY_SAVED_OBJECT_TYPE,
// Fleet Server index
AGENTS_INDEX,
ENROLLMENT_API_KEYS_INDEX,
} from '../../../../common';

export * from './page_paths';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { AgentPolicy } from '../../../../types';
import { SearchBar } from '../../../../components';
import { AGENT_SAVED_OBJECT_TYPE } from '../../../../constants';
import { AGENTS_INDEX, AGENT_SAVED_OBJECT_TYPE } from '../../../../constants';
import { useConfig } from '../../../../hooks';

const statusFilters = [
{
Expand Down Expand Up @@ -76,6 +77,7 @@ export const SearchAndFilterBar: React.FunctionComponent<{
showUpgradeable,
onShowUpgradeableChange,
}) => {
const config = useConfig();
// Policies state for filtering
const [isAgentPoliciesFilterOpen, setIsAgentPoliciesFilterOpen] = useState<boolean>(false);

Expand Down Expand Up @@ -109,7 +111,13 @@ export const SearchAndFilterBar: React.FunctionComponent<{
onSubmitSearch(newSearch);
}
}}
fieldPrefix={AGENT_SAVED_OBJECT_TYPE}
{...(config.agents.fleetServerEnabled
? {
indexPattern: AGENTS_INDEX,
}
: {
fieldPrefix: AGENT_SAVED_OBJECT_TYPE,
})}
/>
</EuiFlexItem>
<EuiFlexItem grow={2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {
HorizontalAlignment,
} from '@elastic/eui';
import { FormattedMessage, FormattedDate } from '@kbn/i18n/react';
import { ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE } from '../../../constants';
import {
ENROLLMENT_API_KEYS_INDEX,
ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
} from '../../../constants';
import {
useBreadcrumbs,
usePagination,
Expand All @@ -29,6 +32,7 @@ import {
sendGetOneEnrollmentAPIKey,
useStartServices,
sendDeleteOneEnrollmentAPIKey,
useConfig,
} from '../../../hooks';
import { EnrollmentAPIKey } from '../../../types';
import { SearchBar } from '../../../components/search_bar';
Expand Down Expand Up @@ -154,6 +158,7 @@ const DeleteButton: React.FunctionComponent<{ apiKey: EnrollmentAPIKey; refresh:

export const EnrollmentTokenListPage: React.FunctionComponent<{}> = () => {
useBreadcrumbs('fleet_enrollment_tokens');
const config = useConfig();
const [flyoutOpen, setFlyoutOpen] = useState(false);
const [search, setSearch] = useState('');
const { pagination, setPagination, pageSizeOptions } = usePagination();
Expand Down Expand Up @@ -281,7 +286,13 @@ export const EnrollmentTokenListPage: React.FunctionComponent<{}> = () => {
});
setSearch(newSearch);
}}
fieldPrefix={ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE}
{...(config.agents.fleetServerEnabled
? {
indexPattern: ENROLLMENT_API_KEYS_INDEX,
}
: {
fieldPrefix: ENROLLMENT_API_KEYS_SAVED_OBJECT_TYPE,
})}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down

0 comments on commit f95bfe8

Please sign in to comment.