18549: New implementation with snackbar
authorDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Wed, 9 Mar 2022 16:36:48 +0000 (17:36 +0100)
committerDaniel Kutyła <daniel.kutyla@contractors.roche.com>
Wed, 9 Mar 2022 16:36:48 +0000 (17:36 +0100)
Arvados-DCO-1.1-Signed-off-by: Daniel Kutyła <daniel.kutyla@contractors.roche.com>

src/services/collection-service/collection-service.ts
src/services/common-service/common-service.ts
src/views/search-results-panel/search-results-panel-view.tsx
src/views/search-results-panel/search-results-panel.tsx

index b6272650debf07034f2c3f336880d94e2814a42a..a3a7cf8f3af89c88ddd7edac938719199df74cbf 100644 (file)
@@ -13,6 +13,7 @@ import { ApiActions } from "services/api/api-actions";
 import { customEncodeURI } from "common/url";
 import { FilterBuilder } from "services/api/filter-builder";
 import { ListArguments } from "services/common-service/common-service";
+import { Session } from "models/session";
 
 export type UploadProgress = (fileId: number, loaded: number, total: number, currentTime: number) => void;
 
@@ -30,7 +31,7 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         ]);
     }
 
-    async get(uuid: string, showErrors?: boolean, select?: string[]) {
+    async get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         super.validateUuid(uuid);
         // We use a filtered list request to avoid getting the manifest text
         const filters = new FilterBuilder().addEqual('uuid', uuid).getFilters();
@@ -38,8 +39,13 @@ export class CollectionService extends TrashableResourceService<CollectionResour
         if (select) {
             listArgs.select = select;
         }
-        const lst = await super.list(listArgs, showErrors);
-        return lst.items[0];
+
+        if (session) {
+            const lst = await super.list(listArgs, showErrors);
+            return lst.items[0];
+        } else {
+            return super.get(uuid, showErrors, session);
+        }
     }
 
     create(data?: Partial<CollectionResource>) {
index f66fad74b701c07d079d56bf087375a049e18a1d..ddaf2ab02fa5ee4e18d544158e42f7606339983c 100644 (file)
@@ -3,10 +3,11 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import { camelCase, isPlainObject, isArray, snakeCase } from "lodash";
-import { AxiosInstance, AxiosPromise } from "axios";
+import { AxiosInstance, AxiosPromise, AxiosRequestConfig } from "axios";
 import uuid from "uuid/v4";
 import { ApiActions } from "services/api/api-actions";
 import QueryString from "query-string";
+import { Session } from "models/session";
 
 interface Errors {
     status: number;
@@ -113,11 +114,18 @@ export class CommonService<T> {
         );
     }
 
-    get(uuid: string, showErrors?: boolean) {
+    get(uuid: string, showErrors?: boolean, select?: string[], session?: Session) {
         this.validateUuid(uuid);
+
+        const cfg: AxiosRequestConfig = {};
+        if (session) {
+            cfg.baseURL = session.baseUrl;
+            cfg.headers = { 'Authorization': 'Bearer ' + session.token };
+        }
+
         return CommonService.defaultResponse(
             this.serverApi
-                .get<T>(`/${this.resourceType}/${uuid}`),
+                .get<T>(`/${this.resourceType}/${uuid}`, session ? cfg : undefined),
             this.actions,
             true, // mapKeys
             showErrors
index 6febabf2eb164013329e4c2dafa24705fb6294fa..fd420b83ffadd624c6ac22b12d9654f5a91d68ff 100644 (file)
@@ -27,6 +27,7 @@ import { Routes } from 'routes/routes';
 import { Link } from 'react-router-dom';
 import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core';
 import { ArvadosTheme } from 'common/custom-theme';
+import { getSearchSessions } from 'store/search-bar/search-bar-actions';
 
 export enum SearchResultsPanelColumnNames {
     CLUSTER = "Cluster",
@@ -110,38 +111,50 @@ export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
         const homeCluster = props.user.uuid.substring(0, 5);
         const loggedIn = props.sessions.filter((ss) => ss.loggedIn && ss.userIsActive);
         const [selectedItem, setSelectedItem] = useState('');
-        let itemPath: string[] = [];
 
         useEffect(() => {
-            if (selectedItem !== '') {
-                itemPath = [];
+            let itemPath: string[] = [];
 
-                (async () => {
+            (async () => {
+                if (selectedItem !== '') {
                     let searchUuid = selectedItem;
                     let itemKind = extractUuidKind(searchUuid);
 
                     while (itemKind !== ResourceKind.USER) {
-                        console.log(itemKind);
-                        const { name, ownerUuid } = await servicesProvider.getServices().groupsService.get(searchUuid);
-                        itemKind = extractUuidKind(ownerUuid);
-                        searchUuid = ownerUuid;
-                        itemPath.push(name);
+                        const clusterId = searchUuid.split('-')[0];
+                        const serviceType = itemKind?.replace('arvados#', '');
+                        const service = Object.values(servicesProvider.getServices())
+                            .filter(({resourceType}) => !!resourceType)
+                            .find(({resourceType}) => resourceType.indexOf(serviceType) > -1);
+                        const sessions = getSearchSessions(clusterId, props.sessions);
+
+                        if (sessions.length > 0) {
+                            const session = sessions[0];
+                            const { name, ownerUuid } = await (service as any).get(searchUuid, false, session);
+                            itemPath.push(name);
+                            searchUuid = ownerUuid;
+                            itemKind = extractUuidKind(searchUuid);
+                        } else {
+                            break;
+                        }
                     }
 
-                    const rootFolder = props.user.uuid === searchUuid ? 'Projects' : 'Shared with me';
-                    itemPath.push(rootFolder);
+                    itemPath.push(props.user.uuid === searchUuid ? 'Projects' : 'Shared with me');
+                    props.onPathDisplay(`/ ${itemPath.reverse().join(' / ')}`);
+                }
+            })();
 
-                    console.log(itemPath.reverse().join('/'));
-                })();
-            }
+        // eslint-disable-next-line react-hooks/exhaustive-deps
         }, [selectedItem]);
 
         const onItemClick = useCallback((uuid) => {
             setSelectedItem(uuid);
             props.onItemClick(uuid);
+        // eslint-disable-next-line react-hooks/exhaustive-deps
         },[props.onItemClick]);
 
-        return <span data-cy='search-results'><DataExplorer
+        return <span data-cy='search-results'>
+            <DataExplorer
             id={SEARCH_RESULTS_PANEL_ID}
             onRowClick={onItemClick}
             onRowDoubleClick={props.onItemDoubleClick}
index d25682f6e1d8b59a07d4c91c4e8a469bd119504b..6d1d2bf569f6d06d287f67fbde1f4e94901a05b3 100644 (file)
@@ -14,6 +14,7 @@ import { SearchBarAdvancedFormData } from 'models/search-bar';
 import { User } from "models/user";
 import { Config } from 'common/config';
 import { Session } from "models/session";
+import { snackbarActions, SnackbarKind } from "store/snackbar/snackbar-actions";
 
 export interface SearchResultsPanelDataProps {
     data: SearchBarAdvancedFormData;
@@ -28,6 +29,7 @@ export interface SearchResultsPanelActionProps {
     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
     onDialogOpen: (ownerUuid: string) => void;
     onItemDoubleClick: (item: string) => void;
+    onPathDisplay: (path: string) => void;
 }
 
 export type SearchResultsPanelProps = SearchResultsPanelDataProps & SearchResultsPanelActionProps;
@@ -49,7 +51,15 @@ const mapDispatchToProps = (dispatch: Dispatch): SearchResultsPanelActionProps =
     },
     onItemDoubleClick: uuid => {
         dispatch<any>(navigateTo(uuid));
-    }
+    },
+    onPathDisplay: (path: string) => {
+        dispatch(snackbarActions.SHIFT_MESSAGES());
+        dispatch(snackbarActions.OPEN_SNACKBAR({
+            message: path,
+            kind: SnackbarKind.INFO,
+            hideDuration: 9999999999,
+        }));
+    },
 });
 
 export const SearchResultsPanel = connect(mapStateToProps, mapDispatchToProps)(SearchResultsPanelView);