mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Snapshot & Restore] Fix date parsing in the search bar (#125234)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c52ffd8d17
commit
c14173cd09
3 changed files with 18 additions and 3 deletions
|
@ -155,6 +155,17 @@ describe('<SnapshotList />', () => {
|
|||
});
|
||||
});
|
||||
|
||||
test('term search with a date is parsed', async () => {
|
||||
await setSearchText('2022.02.10');
|
||||
expect(useLoadSnapshots).lastCalledWith({
|
||||
...DEFAULT_SNAPSHOT_LIST_PARAMS,
|
||||
searchField: 'snapshot',
|
||||
searchValue: '2022.02.10',
|
||||
searchMatch: 'must',
|
||||
searchOperator: 'eq',
|
||||
});
|
||||
});
|
||||
|
||||
test('excluding term search is converted to partial excluding snapshot search', async () => {
|
||||
await setSearchText('-test_snapshot');
|
||||
expect(useLoadSnapshots).lastCalledWith({
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
import { Direction, Query } from '@elastic/eui';
|
||||
import { SchemaType } from '@elastic/eui/src/components/search_bar/search_box';
|
||||
|
||||
export type SortField =
|
||||
| 'snapshot'
|
||||
|
@ -49,12 +50,15 @@ const resetSearchOptions = (listParams: SnapshotListParams): SnapshotListParams
|
|||
});
|
||||
|
||||
// to init the query for repository and policyName search passed via url
|
||||
export const getQueryFromListParams = (listParams: SnapshotListParams): Query => {
|
||||
export const getQueryFromListParams = (
|
||||
listParams: SnapshotListParams,
|
||||
schema: SchemaType
|
||||
): Query => {
|
||||
const { searchField, searchValue } = listParams;
|
||||
if (!searchField || !searchValue) {
|
||||
return Query.MATCH_ALL;
|
||||
}
|
||||
return Query.parse(`${searchField}=${searchValue}`);
|
||||
return Query.parse(`${searchField}=${searchValue}`, { schema });
|
||||
};
|
||||
|
||||
export const getListParams = (listParams: SnapshotListParams, query: Query): SnapshotListParams => {
|
||||
|
|
|
@ -126,7 +126,7 @@ export const SnapshotSearchBar: React.FunctionComponent<Props> = ({
|
|||
</EuiButton>
|
||||
);
|
||||
|
||||
const [query, setQuery] = useState<Query>(getQueryFromListParams(listParams));
|
||||
const [query, setQuery] = useState<Query>(getQueryFromListParams(listParams, searchSchema));
|
||||
const [error, setError] = useState<Error | null>(null);
|
||||
|
||||
const onSearchBarChange = (args: EuiSearchBarOnChangeArgs) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue