-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] De-angularize side bar search field (#46679)
* Add DiscoverFieldSearch react component * Adapt field_chooser.js * Add jest test * Adapt scss
- Loading branch information
Showing
12 changed files
with
328 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...re_plugins/kibana/public/discover/components/field_chooser/discover_field_search.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 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. | ||
*/ | ||
import React from 'react'; | ||
import { mountWithIntl } from 'test_utils/enzyme_helpers'; | ||
// @ts-ignore | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
import { DiscoverFieldSearch } from './discover_field_search'; | ||
|
||
describe('DiscoverFieldSearch', () => { | ||
function mountComponent() { | ||
const props = { | ||
onChange: jest.fn(), | ||
onShowFilter: jest.fn(), | ||
showFilter: false, | ||
value: 'test', | ||
}; | ||
const comp = mountWithIntl(<DiscoverFieldSearch {...props} />); | ||
const input = findTestSubject(comp, 'fieldFilterSearchInput'); | ||
const btn = findTestSubject(comp, 'toggleFieldFilterButton'); | ||
return { comp, input, btn, props }; | ||
} | ||
|
||
test('enter value', () => { | ||
const { input, props } = mountComponent(); | ||
input.simulate('change', { target: { value: 'new filter' } }); | ||
expect(props.onChange).toBeCalledTimes(1); | ||
}); | ||
|
||
// this should work, but doesn't, have to do some research | ||
test('click toggle filter button', () => { | ||
const { btn, props } = mountComponent(); | ||
btn.simulate('click'); | ||
expect(props.onShowFilter).toBeCalledTimes(1); | ||
}); | ||
|
||
test('change showFilter value should change button label', () => { | ||
const { btn, comp } = mountComponent(); | ||
const prevFilterBtnHTML = btn.html(); | ||
comp.setProps({ showFilter: true }); | ||
expect(btn.html()).not.toBe(prevFilterBtnHTML); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
...cy/core_plugins/kibana/public/discover/components/field_chooser/discover_field_search.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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. | ||
*/ | ||
import React from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { EuiButtonIcon, EuiFieldSearch, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; | ||
|
||
export interface Props { | ||
/** | ||
* triggered on input of user into search field | ||
*/ | ||
onChange: (field: string, value: string) => void; | ||
/** | ||
* triggered when the "additional filter btn" is clicked | ||
*/ | ||
onShowFilter: () => void; | ||
/** | ||
* determines whether additional filter fields are displayed | ||
*/ | ||
showFilter: boolean; | ||
/** | ||
* the input value of the user | ||
*/ | ||
value?: string; | ||
} | ||
|
||
/** | ||
* Component is Discover'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 DiscoverFieldSearch({ showFilter, onChange, onShowFilter, value }: Props) { | ||
if (typeof value !== 'string') { | ||
// at initial rendering value is undefined (angular related), this catches the warning | ||
// should be removed once all is react | ||
return null; | ||
} | ||
const filterBtnAriaLabel = showFilter | ||
? i18n.translate('kbn.discover.fieldChooser.toggleFieldFilterButtonHideAriaLabel', { | ||
defaultMessage: 'Hide field filter settings', | ||
}) | ||
: i18n.translate('kbn.discover.fieldChooser.toggleFieldFilterButtonShowAriaLabel', { | ||
defaultMessage: 'Show field filter settings', | ||
}); | ||
const searchPlaceholder = i18n.translate('kbn.discover.fieldChooser.searchPlaceHolder', { | ||
defaultMessage: 'Search fields', | ||
}); | ||
|
||
return ( | ||
<EuiFlexGroup responsive={false} gutterSize={'s'}> | ||
<EuiFlexItem> | ||
<EuiFieldSearch | ||
aria-label={searchPlaceholder} | ||
data-test-subj="fieldFilterSearchInput" | ||
compressed | ||
fullWidth | ||
onChange={event => onChange('name', event.currentTarget.value)} | ||
placeholder={searchPlaceholder} | ||
value={value} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiToolTip content={filterBtnAriaLabel} position="right"> | ||
<EuiButtonIcon | ||
aria-expanded={showFilter} | ||
aria-label={filterBtnAriaLabel} | ||
className="dscToggleFieldFilterButton" | ||
data-test-subj="toggleFieldFilterButton" | ||
iconType="filter" | ||
onClick={() => onShowFilter()} | ||
size="m" | ||
/> | ||
</EuiToolTip> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
} |
33 changes: 33 additions & 0 deletions
33
...lugins/kibana/public/discover/components/field_chooser/discover_field_search_directive.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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. | ||
*/ | ||
// @ts-ignore | ||
import { uiModules } from 'ui/modules'; | ||
import { wrapInI18nContext } from 'ui/i18n'; | ||
import { DiscoverFieldSearch } from './discover_field_search'; | ||
|
||
const app = uiModules.get('apps/discover'); | ||
|
||
app.directive('discoverFieldSearch', function(reactDirective: any) { | ||
return reactDirective(wrapInI18nContext(DiscoverFieldSearch), [ | ||
['onChange', { watchDepth: 'reference' }], | ||
['onShowFilter', { watchDepth: 'reference' }], | ||
['showFilter', { watchDepth: 'value' }], | ||
['value', { watchDepth: 'value' }], | ||
]); | ||
}); |
Oops, something went wrong.