Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field Search in Data panel #995

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
abbashus marked this conversation as resolved.
Show resolved Hide resolved
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/
import React from 'react';
import { i18n } from '@osd/i18n';
import { EuiFieldSearch, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

export interface Props {
/**
* triggered on input of user into search field
*/
onChange: (field: string) => void;

/**
* the input value of the user
*/
value?: string;
}

/**
* Component is Wizard's side bar to search of available fields
* Additionally there's a button displayed that allows the user to show/hide more filter fields
*/
export function FieldSearch({ onChange, value }: Props) {
const searchPlaceholder = i18n.translate('wizard.fieldChooser.searchPlaceHolder', {
defaultMessage: 'Search field names',
});

return (
<React.Fragment>
<EuiFlexGroup responsive={false} gutterSize={'s'}>
<EuiFlexItem>
<EuiFieldSearch
aria-label={searchPlaceholder}
data-test-subj="fieldFilterSearchInput"
compressed
fullWidth
onChange={(event) => onChange(event.currentTarget.value)}
placeholder={searchPlaceholder}
value={value}
/>
</EuiFlexItem>
</EuiFlexGroup>
</React.Fragment>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';

import {
EuiFormLabel,
EuiFlexItem,
EuiAccordion,
EuiSpacer,
EuiNotificationBadge,
EuiTitle,
} from '@elastic/eui';
import React, { useCallback, useState, useEffect } from 'react';
import { EuiFlexItem, EuiAccordion, EuiSpacer, EuiNotificationBadge, EuiTitle } from '@elastic/eui';
import { FieldSearch } from './field_search';

import {
IndexPatternField,
Expand All @@ -39,7 +32,19 @@ const META_FIELDS: string[] = [

export const FieldSelector = () => {
const indexFields = useTypedSelector((state) => state.dataSource.visualizableFields);
const fields = indexFields?.reduce<IFieldCategories>(
const [filteredFields, setFilteredFields] = useState(indexFields);
abbashus marked this conversation as resolved.
Show resolved Hide resolved
const [fieldSearchValue, setFieldSearchValue] = useState('');

useEffect(() => {
const filteredSubset = indexFields.filter((field) =>
field.displayName.includes(fieldSearchValue)
);

setFilteredFields(filteredSubset);
return;
}, [indexFields, fieldSearchValue]);

const fields = filteredFields?.reduce<IFieldCategories>(
(fieldGroups, currentField) => {
const category = getFieldCategory(currentField);
fieldGroups[category].push(currentField);
Expand All @@ -53,10 +58,16 @@ export const FieldSelector = () => {
}
);

const onChangeFieldSearch = useCallback((field: string) => {
setFieldSearchValue(field);
}, []);

return (
<div className="wizFieldSelector">
<div>
<EuiFormLabel>TODO: Search goes here</EuiFormLabel>
<form>
<FieldSearch onChange={onChangeFieldSearch} value={fieldSearchValue} />
</form>
</div>
<div className="wizFieldSelector__fieldGroups">
<FieldGroup
Expand Down