[ARVADOS-WORKBENCH2] updated: 1.2.0-566-g47440ea

Git user git at public.curoverse.com
Mon Oct 8 07:55:48 EDT 2018


Summary of changes:
 src/services/groups-service/groups-service.ts      | 16 +++++----
 src/store/search-bar/search-bar-actions.ts         | 38 ++++++++++++++++++++--
 src/store/search-bar/search-bar-reducer.ts         |  6 +++-
 .../search-bar/search-bar-autocomplete-view.tsx    | 16 ++++++---
 .../search-bar/search-bar-view.tsx                 |  9 ++---
 src/views-components/search-bar/search-bar.tsx     |  9 +++--
 6 files changed, 70 insertions(+), 24 deletions(-)

       via  47440ead99a61a13bc635630e0f4b07d9322edbf (commit)
      from  ea17d70fbcc3401f4ffd01ec02f3206616261dcf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 47440ead99a61a13bc635630e0f4b07d9322edbf
Author: Janicki Artur <artur.janicki at contractors.roche.com>
Date:   Mon Oct 8 13:55:38 2018 +0200

    init search and display results
    
    Feature #14307
    
    Arvados-DCO-1.1-Signed-off-by: Janicki Artur <artur.janicki at contractors.roche.com>

diff --git a/src/services/groups-service/groups-service.ts b/src/services/groups-service/groups-service.ts
index c4c56f3..b0c1b56 100644
--- a/src/services/groups-service/groups-service.ts
+++ b/src/services/groups-service/groups-service.ts
@@ -45,14 +45,16 @@ export class GroupsService<T extends GroupResource = GroupResource> extends Tras
             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);
diff --git a/src/store/search-bar/search-bar-actions.ts b/src/store/search-bar/search-bar-actions.ts
index 1e1810e..b4835ed 100644
--- a/src/store/search-bar/search-bar-actions.ts
+++ b/src/store/search-bar/search-bar-actions.ts
@@ -3,13 +3,47 @@
 // 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
diff --git a/src/store/search-bar/search-bar-reducer.ts b/src/store/search-bar/search-bar-reducer.ts
index 97e22d7..5c3fb47 100644
--- a/src/store/search-bar/search-bar-reducer.ts
+++ b/src/store/search-bar/search-bar-reducer.ts
@@ -3,10 +3,12 @@
 // 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 {
@@ -17,7 +19,8 @@ export enum SearchView {
 
 const initialState: SearchBar = {
     currentView: SearchView.BASIC,
-    open: false
+    open: false,
+    searchResults: []
 };
 
 export const searchBarReducer = (state = initialState, action: SearchBarActions): SearchBar =>
@@ -25,5 +28,6 @@ export const searchBarReducer = (state = initialState, action: SearchBarActions)
         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
diff --git a/src/views-components/search-bar/search-bar-autocomplete-view.tsx b/src/views-components/search-bar/search-bar-autocomplete-view.tsx
index 64b8361..73872f2 100644
--- a/src/views-components/search-bar/search-bar-autocomplete-view.tsx
+++ b/src/views-components/search-bar/search-bar-autocomplete-view.tsx
@@ -5,6 +5,7 @@
 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';
 
@@ -16,14 +17,19 @@ const styles: StyleRulesCallback<CssRules> = theme => {
     };
 };
 
-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
diff --git a/src/views-components/search-bar/search-bar-view.tsx b/src/views-components/search-bar/search-bar-view.tsx
index acd7ca2..69e3717 100644
--- a/src/views-components/search-bar/search-bar-view.tsx
+++ b/src/views-components/search-bar/search-bar-view.tsx
@@ -19,7 +19,8 @@ import { RemoveIcon } from '~/components/icon/icon';
 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';
 
@@ -40,11 +41,11 @@ const styles: StyleRulesCallback<CssRules> = theme => {
     };
 };
 
-interface SearchBarDataProps {
+type SearchBarDataProps = {
     value: string;
     currentView: string;
     open: boolean;
-}
+} & SearchBarAutocompleteViewDataProps;
 
 interface SearchBarActionProps {
     onSearch: (value: string) => any;
@@ -143,7 +144,7 @@ export const SearchBarView = withStyles(styles)(
                 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} />;
             }
diff --git a/src/views-components/search-bar/search-bar.tsx b/src/views-components/search-bar/search-bar.tsx
index 5f51654..3315c14 100644
--- a/src/views-components/search-bar/search-bar.tsx
+++ b/src/views-components/search-bar/search-bar.tsx
@@ -5,7 +5,7 @@
 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) => {
@@ -13,14 +13,13 @@ 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())

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list