//
// SPDX-License-Identifier: AGPL-3.0
-import { getAdvancedDataFromQuery, getQueryFromAdvancedData, parseQuery } from "~/store/search-bar/search-bar-actions";
+import { getAdvancedDataFromQuery, getQueryFromAdvancedData, parseSearchQuery } from "~/store/search-bar/search-bar-actions";
import { ResourceKind } from "~/models/resource";
import { ClusterObjectType } from "~/models/search-bar";
describe('search-bar-actions', () => {
- describe('parseQuery', () => {
+ describe('parseSearchQuery', () => {
it('should correctly parse query #1', () => {
const q = 'val0 is:trashed val1';
- const r = parseQuery(q);
+ const r = parseSearchQuery(q);
expect(r.hasKeywords).toBeTruthy();
expect(r.values).toEqual(['val0', 'val1']);
expect(r.properties).toEqual({
it('should correctly parse query #2 (value with keyword should be ignored)', () => {
const q = 'val0 is:from:trashed val1';
- const r = parseQuery(q);
+ const r = parseSearchQuery(q);
expect(r.hasKeywords).toBeTruthy();
expect(r.values).toEqual(['val0', 'val1']);
expect(r.properties).toEqual({
it('should correctly parse query #3 (many keywords)', () => {
const q = 'val0 is:trashed val2 from:2017-04-01 val1';
- const r = parseQuery(q);
+ const r = parseSearchQuery(q);
expect(r.hasKeywords).toBeTruthy();
expect(r.values).toEqual(['val0', 'val2', 'val1']);
expect(r.properties).toEqual({
it('should correctly parse query #4 (no duplicated values)', () => {
const q = 'val0 is:trashed val2 val2 val0';
- const r = parseQuery(q);
+ const r = parseSearchQuery(q);
expect(r.hasKeywords).toBeTruthy();
expect(r.values).toEqual(['val0', 'val2']);
expect(r.properties).toEqual({
it('should correctly parse query #5 (properties)', () => {
const q = 'val0 has:filesize:100mb val2 val2 val0';
- const r = parseQuery(q);
+ const r = parseSearchQuery(q);
expect(r.hasKeywords).toBeTruthy();
expect(r.values).toEqual(['val0', 'val2']);
expect(r.properties).toEqual({
it('should correctly parse query #6 (multiple properties, multiple is)', () => {
const q = 'val0 has:filesize:100mb val2 has:user:daniel is:starred val2 val0 is:trashed';
- const r = parseQuery(q);
+ const r = parseSearchQuery(q);
expect(r.hasKeywords).toBeTruthy();
expect(r.values).toEqual(['val0', 'val2']);
expect(r.properties).toEqual({
return value;
};
-export const parseQuery: (query: string) => { hasKeywords: boolean; values: string[]; properties: any } = (searchValue: string) => {
+export interface ParsedSearchQuery {
+ hasKeywords: boolean;
+ values: string[];
+ properties: {
+ [key: string]: string
+ };
+}
+
+export const parseSearchQuery: (query: string) => { hasKeywords: boolean; values: string[]; properties: any } = (searchValue: string): ParsedSearchQuery => {
const keywords = [
'type:',
'cluster:',
};
export const getAdvancedDataFromQuery = (query: string): SearchBarAdvanceFormData => {
- const r = parseQuery(query);
+ const r = parseSearchQuery(query);
const getFirstProp = (name: string) => r.properties[name] && r.properties[name][0];
const getPropValue = (name: string, value: string) => r.properties[name] && r.properties[name].find((v: string) => v === value);
export const getFilters = (filterName: string, searchValue: string): string => {
const filter = new FilterBuilder();
- const pq = parseQuery(searchValue);
+ const pq = parseSearchQuery(searchValue);
if (!pq.hasKeywords) {
filter
import { compose, Dispatch } from 'redux';
import { Paper, StyleRulesCallback, withStyles, WithStyles, Button, Grid, IconButton, CircularProgress } from '@material-ui/core';
import {
- SEARCH_BAR_ADVANCE_FORM_NAME,
+ SEARCH_BAR_ADVANCE_FORM_NAME, SEARCH_BAR_ADVANCE_FORM_PICKER_ID,
searchAdvanceData,
setSearchValueFromAdvancedData
} from '~/store/search-bar/search-bar-actions';
SearchBarDateFromField, SearchBarDateToField, SearchBarPropertiesField,
SearchBarSaveSearchField, SearchBarQuerySearchField
} from '~/views-components/form-fields/search-bar-form-fields';
+import { treePickerActions } from "~/store/tree-picker/tree-picker-actions";
type CssRules = 'container' | 'closeIcon' | 'label' | 'buttonWrapper'
| 'button' | 'circularProgress' | 'searchView' | 'selectGrid';
// ToDo: maybe we should remove tags
export interface SearchBarAdvancedViewDataProps {
tags: any;
+ saveQuery: boolean;
}
export interface SearchBarAdvancedViewActionProps {
onSubmit: (data: SearchBarAdvanceFormData, dispatch: Dispatch) => {
dispatch<any>(searchAdvanceData(data));
dispatch(reset(SEARCH_BAR_ADVANCE_FORM_NAME));
+ dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ pickerId: SEARCH_BAR_ADVANCE_FORM_PICKER_ID, id: "" }));
},
onChange: (data: SearchBarAdvanceFormData, dispatch: Dispatch, props: any, prevData: SearchBarAdvanceFormData) => {
dispatch<any>(setSearchValueFromAdvancedData(data, prevData));
}
}),
withStyles(styles))(
- ({ classes, closeAdvanceView, handleSubmit, submitting, invalid, pristine, tags }: SearchBarAdvancedViewFormProps) =>
+ ({ classes, closeAdvanceView, handleSubmit, submitting, invalid, pristine, tags, saveQuery }: SearchBarAdvancedViewFormProps) =>
<Paper className={classes.searchView}>
<form onSubmit={handleSubmit}>
<Grid container direction="column" justify="flex-start" alignItems="flex-start">
<SearchBarSaveSearchField />
</Grid>
<Grid item xs={4}>
- <SearchBarQuerySearchField />
+ {saveQuery && <SearchBarQuerySearchField />}
</Grid>
</Grid>
<Grid container item xs={12} justify='flex-end'>
case SearchView.ADVANCED:
return <SearchBarAdvancedView
closeAdvanceView={props.closeAdvanceView}
- tags={props.tags} />;
+ tags={props.tags}
+ saveQuery={props.saveQuery} />;
default:
return <SearchBarBasicView
onSetView={props.onSetView}
searchResults: searchBar.searchResults,
selectedItem: searchBar.selectedItem,
savedQueries: searchBar.savedQueries,
- tags: form.searchBarAdvanceFormName
+ tags: form.searchBarAdvanceFormName,
+ saveQuery: form.searchBarAdvanceFormName &&
+ form.searchBarAdvanceFormName.values &&
+ form.searchBarAdvanceFormName.values.saveQuery
};
};