Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down