import { ListResults } from "~/services/common-service/common-service";
import * as parser from './search-query/arv-parser';
import { Keywords } from './search-query/arv-parser';
+import { Vocabulary, getTagKeyLabel, getTagValueLabel } from "~/models/vocabulary";
export const searchBarActions = unionize({
SET_CURRENT_VIEW: ofType<string>(),
dispatch(searchBarActions.SET_SEARCH_VALUE(value));
};
-export const setAdvancedDataFromSearchValue = (search: string) =>
+export const setAdvancedDataFromSearchValue = (search: string, vocabulary: Vocabulary) =>
async (dispatch: Dispatch) => {
- const data = getAdvancedDataFromQuery(search);
+ const data = getAdvancedDataFromQuery(search, vocabulary);
dispatch<any>(initialize(SEARCH_BAR_ADVANCE_FORM_NAME, data));
if (data.projectUuid) {
await dispatch<any>(activateSearchBarProject(data.projectUuid));
return value;
};
-export const getAdvancedDataFromQuery = (query: string): SearchBarAdvanceFormData => {
+export const getAdvancedDataFromQuery = (query: string, vocabulary?: Vocabulary): SearchBarAdvanceFormData => {
const { tokens, searchString } = parser.parseSearchQuery(query);
const getValue = parser.getValue(tokens);
return {
inTrash: parser.isTrashed(tokens),
dateFrom: getValue(Keywords.FROM) || '',
dateTo: getValue(Keywords.TO) || '',
- properties: parser.getProperties(tokens),
+ properties: vocabulary
+ ? parser.getProperties(tokens).map(
+ p => {
+ return {
+ keyID: p.key,
+ key: getTagKeyLabel(p.key, vocabulary),
+ valueID: p.value,
+ value: getTagValueLabel(p.key, p.value, vocabulary),
+ };
+ })
+ : parser.getProperties(tokens),
saveQuery: false,
queryName: ''
};
// SPDX-License-Identifier: AGPL-3.0
import * as React from 'react';
+import { compose } from 'redux';
import {
IconButton,
Paper,
} from '~/views-components/search-bar/search-bar-advanced-view';
import { KEY_CODE_DOWN, KEY_CODE_ESC, KEY_CODE_UP, KEY_ENTER } from "~/common/codes";
import { debounce } from 'debounce';
+import { Vocabulary } from '~/models/vocabulary';
+import { connectVocabulary } from '../resource-properties-form/property-field-common';
type CssRules = 'container' | 'containerSearchViewOpened' | 'input' | 'view';
currentView: string;
isPopoverOpen: boolean;
debounce?: number;
+ vocabulary?: Vocabulary;
}
export type SearchBarActionProps = SearchBarViewActionProps
loadRecentQueries: () => string[];
moveUp: () => void;
moveDown: () => void;
- setAdvancedDataFromSearchValue: (search: string) => void;
+ setAdvancedDataFromSearchValue: (search: string, vocabulary?: Vocabulary) => void;
}
type SearchBarViewProps = SearchBarDataProps & SearchBarActionProps & WithStyles<CssRules>;
if (props.isPopoverOpen && props.currentView === SearchView.ADVANCED) {
props.closeView();
} else {
- props.setAdvancedDataFromSearchValue(props.searchValue);
+ props.setAdvancedDataFromSearchValue(props.searchValue, props.vocabulary);
props.onSetView(SearchView.ADVANCED);
}
};
-export const SearchBarView = withStyles(styles)(
+export const SearchBarView = compose(connectVocabulary, withStyles(styles))(
class extends React.Component<SearchBarViewProps> {
debouncedSearch = debounce(() => {
} from '~/store/search-bar/search-bar-actions';
import { SearchBarView, SearchBarActionProps, SearchBarDataProps } from '~/views-components/search-bar/search-bar-view';
import { SearchBarAdvanceFormData } from '~/models/search-bar';
+import { Vocabulary } from '~/models/vocabulary';
const mapStateToProps = ({ searchBar, form }: RootState): SearchBarDataProps => {
return {
editSavedQuery: (data: SearchBarAdvanceFormData) => dispatch<any>(editSavedQuery(data)),
moveUp: () => dispatch<any>(moveUp()),
moveDown: () => dispatch<any>(moveDown()),
- setAdvancedDataFromSearchValue: (search: string) => dispatch<any>(setAdvancedDataFromSearchValue(search))
+ setAdvancedDataFromSearchValue: (search: string, vocabulary: Vocabulary) => dispatch<any>(setAdvancedDataFromSearchValue(search, vocabulary))
});
export const SearchBar = connect(mapStateToProps, mapDispatchToProps)(SearchBarView);