order: order ? order : undefined
};
+ const pathUrl = uuid ? `${uuid}/contents` : 'contents';
const response = await CommonResourceService.defaultResponse(
- this.serverApi
- .get(this.resourceType + `${uuid}/contents`, {
- params: CommonResourceService.mapKeys(_.snakeCase)(params)
- }),
- this.actions,
- false
- );
+ this.serverApi
+ .get(this.resourceType + pathUrl, {
+ params: CommonResourceService.mapKeys(_.snakeCase)(params)
+ }),
+ this.actions,
+ false
+ );
+
const { items, ...res } = response;
const mappedItems = items.map((item: GroupContentsResource) => {
const mappedItem = TrashableResourceService.mapKeys(_.camelCase)(item);
// SPDX-License-Identifier: AGPL-3.0
import { unionize, ofType, UnionOf } from "~/common/unionize";
+import { GroupContentsResource, GroupContentsResourcePrefix } from '~/services/groups-service/groups-service';
+import { Dispatch } from 'redux';
+import { RootState } from '~/store/store';
+import { ServiceRepository } from '~/services/services';
+import { FilterBuilder } from "~/services/api/filter-builder";
+import { ResourceKind } from '~/models/resource';
+import { GroupClass } from '~/models/group';
export const searchBarActions = unionize({
SET_CURRENT_VIEW: ofType<string>(),
OPEN_SEARCH_VIEW: ofType<{}>(),
- CLOSE_SEARCH_VIEW: ofType<{}>()
+ CLOSE_SEARCH_VIEW: ofType<{}>(),
+ SET_SEARCH_RESULTS: ofType<GroupContentsResource[]>()
});
export type SearchBarActions = UnionOf<typeof searchBarActions>;
-export const goToView = (currentView: string) => searchBarActions.SET_CURRENT_VIEW(currentView);
\ No newline at end of file
+export const goToView = (currentView: string) => searchBarActions.SET_CURRENT_VIEW(currentView);
+
+export const searchData = (searchValue: string) =>
+ async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
+ dispatch(searchBarActions.SET_SEARCH_RESULTS([]));
+ const user = getState().auth.user;
+ if (user && searchValue) {
+ const filters = getFilters('name', searchValue);
+ const { items } = await services.groupsService.contents(user.uuid, {
+ filters,
+ limit: 5,
+ recursive: true
+ });
+ dispatch(searchBarActions.SET_SEARCH_RESULTS(items));
+ }
+ };
+
+
+const getFilters = (filterName: string, searchValue: string): string => {
+ return new FilterBuilder()
+ .addIsA("uuid", [ResourceKind.PROJECT, ResourceKind.COLLECTION, ResourceKind.PROCESS])
+ .addILike(filterName, searchValue, GroupContentsResourcePrefix.COLLECTION)
+ .addILike(filterName, searchValue, GroupContentsResourcePrefix.PROCESS)
+ .addILike(filterName, searchValue, GroupContentsResourcePrefix.PROJECT)
+ .addEqual('groupClass', GroupClass.PROJECT, GroupContentsResourcePrefix.PROJECT)
+ .getFilters();
+};
\ No newline at end of file
// SPDX-License-Identifier: AGPL-3.0
import { searchBarActions, SearchBarActions } from '~/store/search-bar/search-bar-actions';
+import { GroupContentsResource } from '~/services/groups-service/groups-service';
interface SearchBar {
currentView: string;
open: boolean;
+ searchResults: GroupContentsResource[];
}
export enum SearchView {
const initialState: SearchBar = {
currentView: SearchView.BASIC,
- open: false
+ open: false,
+ searchResults: []
};
export const searchBarReducer = (state = initialState, action: SearchBarActions): SearchBar =>
SET_CURRENT_VIEW: currentView => ({ ...state, currentView }),
OPEN_SEARCH_VIEW: () => ({ ...state, open: true }),
CLOSE_SEARCH_VIEW: () => ({ ...state, open: false }),
+ SET_SEARCH_RESULTS: (searchResults) => ({ ...state, searchResults }),
default: () => state
});
\ No newline at end of file
import * as React from 'react';
import { Paper, StyleRulesCallback, withStyles, WithStyles, List } from '@material-ui/core';
import { RenderRecentQueries } from '~/views-components/search-bar/search-bar-view';
+import { GroupContentsResource } from '~/services/groups-service/groups-service';
type CssRules = 'list';
};
};
-interface SearchBarAutocompleteViewProps {
+export interface SearchBarAutocompleteViewDataProps {
+ searchResults?: GroupContentsResource[];
}
+type SearchBarAutocompleteViewProps = SearchBarAutocompleteViewDataProps & WithStyles<CssRules>;
+
export const SearchBarAutocompleteView = withStyles(styles)(
- ({ classes }: SearchBarAutocompleteViewProps & WithStyles<CssRules>) =>
+ ({ classes, searchResults }: SearchBarAutocompleteViewProps ) =>
<Paper>
- <List component="nav" className={classes.list}>
- <RenderRecentQueries text='AUTOCOMPLETE VIEW' />
- </List>
+ {searchResults && <List component="nav" className={classes.list}>
+ {searchResults.map((item) => {
+ return <RenderRecentQueries key={item.uuid} text={item.name} />;
+ })}
+ </List>}
</Paper>
);
\ No newline at end of file
import { SearchView } from '~/store/search-bar/search-bar-reducer';
import { SearchBarBasicView } from '~/views-components/search-bar/search-bar-basic-view';
import { SearchBarAdvancedView } from '~/views-components/search-bar/search-bar-advanced-view';
-import { SearchBarAutocompleteView } from '~/views-components/search-bar/search-bar-autocomplete-view';
+import { SearchBarAutocompleteView, SearchBarAutocompleteViewDataProps } from '~/views-components/search-bar/search-bar-autocomplete-view';
+import { GroupContentsResource } from '~/services/groups-service/groups-service';
type CssRules = 'container' | 'input' | 'searchBar';
};
};
-interface SearchBarDataProps {
+type SearchBarDataProps = {
value: string;
currentView: string;
open: boolean;
-}
+} & SearchBarAutocompleteViewDataProps;
interface SearchBarActionProps {
onSearch: (value: string) => any;
case SearchView.ADVANCED:
return <SearchBarAdvancedView setView={this.props.onSetView} />;
case SearchView.AUTOCOMPLETE:
- return <SearchBarAutocompleteView />;
+ return <SearchBarAutocompleteView searchResults={this.props.searchResults} />;
default:
return <SearchBarBasicView setView={this.props.onSetView} />;
}
import { connect } from 'react-redux';
import { RootState } from '~/store/store';
import { Dispatch } from 'redux';
-import { goToView, searchBarActions } from '~/store/search-bar/search-bar-actions';
+import { goToView, searchData, searchBarActions } from '~/store/search-bar/search-bar-actions';
import { SearchBarView } from '~/views-components/search-bar/search-bar-view';
const mapStateToProps = ({ searchBar }: RootState) => {
// ToDo: add value to store
value: '',
currentView: searchBar.currentView,
- open: searchBar.open
+ open: searchBar.open,
+ searchResults: searchBar.searchResults
};
};
const mapDispatchToProps = (dispatch: Dispatch) => ({
- onSearch: (terms: string) => {
- console.log('search: ', terms);
- },
+ onSearch: (valueSearch: string) => dispatch<any>(searchData(valueSearch)),
onSetView: (currentView: string) => dispatch(goToView(currentView)),
openView: () => dispatch<any>(searchBarActions.OPEN_SEARCH_VIEW()),
closeView: () => dispatch<any>(searchBarActions.CLOSE_SEARCH_VIEW())