import { initUserProject, treePickerActions } from '~/store/tree-picker/tree-picker-actions';
import { ServiceRepository } from '~/services/services';
import { FilterBuilder } from "~/services/api/filter-builder";
-import { getResourceKind, ResourceKind } from '~/models/resource';
+import { ResourceKind } from '~/models/resource';
import { GroupClass } from '~/models/group';
import { SearchView } from '~/store/search-bar/search-bar-reducer';
import { navigateTo, navigateToSearchResults } from '~/store/navigation/navigation-action';
import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions';
-import { getClusterObjectType, PropertyValues, SearchBarAdvanceFormData } from '~/models/search-bar';
+import { ClusterObjectType, PropertyValue, SearchBarAdvanceFormData } from '~/models/search-bar';
import { debounce } from 'debounce';
import * as _ from "lodash";
import { getModifiedKeysValues } from "~/common/objects";
'has:'
];
- const hasKeywords = (search: string) => keywords.reduce((acc, keyword) => acc + search.indexOf(keyword) >= 0 ? 1 : 0, 0);
+ const hasKeywords = (search: string) => keywords.reduce((acc, keyword) => acc + (search.includes(keyword) ? 1 : 0), 0);
let keywordsCnt = 0;
const properties = {};
const getFirstProp = (sq: ParseSearchQuery, name: string) => sq.properties[name] && sq.properties[name][0];
const getPropValue = (sq: ParseSearchQuery, name: string, value: string) => sq.properties[name] && sq.properties[name].find((v: string) => v === value);
-const getProperties = (sq: ParseSearchQuery) => {
+const getProperties = (sq: ParseSearchQuery): PropertyValue[] => {
if (sq.properties.has) {
return sq.properties.has.map((value: string) => {
const v = value.split(':');
return {
searchValue: sq.values.join(' '),
- type: getResourceKind(getFirstProp(sq, 'type')),
- cluster: getClusterObjectType(getFirstProp(sq, 'cluster')),
+ type: getFirstProp(sq, 'type') as ResourceKind,
+ cluster: getFirstProp(sq, 'cluster') as ClusterObjectType,
projectUuid: getFirstProp(sq, 'project'),
inTrash: getPropValue(sq, 'is', 'trashed') !== undefined,
dateFrom: getFirstProp(sq, 'from'),
const filter = new FilterBuilder();
const sq = parseSearchQuery(searchValue);
- const resourceKind = getResourceKind(getFirstProp(sq, 'type'));
+ const resourceKind = getFirstProp(sq, 'type') as ResourceKind;
let prefix = '';
switch (resourceKind) {
if (dateTo) {
filter.addLte('modified_at', buildDateFilter(dateTo));
}
- }
- // TODO: has props
+ const props = getProperties(sq);
+ props.forEach(p => {
+ // filter.addILike(`properties.${p.key}`, p.value);
+ filter.addExists(p.key);
+ });
+ }
return filter
.addEqual('groupClass', GroupClass.PROJECT, GroupContentsResourcePrefix.PROJECT)
dispatch<any>(initUserProject(SEARCH_BAR_ADVANCE_FORM_PICKER_ID));
};
-export const changeAdvanceFormProperty = (property: string, value: PropertyValues[] | string = '') =>
+export const changeAdvanceFormProperty = (property: string, value: PropertyValue[] | string = '') =>
(dispatch: Dispatch) => {
dispatch(change(SEARCH_BAR_ADVANCE_FORM_NAME, property, value));
};
-export const updateAdvanceFormProperties = (propertyValues: PropertyValues) =>
+export const updateAdvanceFormProperties = (propertyValues: PropertyValue) =>
(dispatch: Dispatch) => {
dispatch(arrayPush(SEARCH_BAR_ADVANCE_FORM_NAME, 'properties', propertyValues));
};