X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/970a9e9dcd2a444d02181c4df3f205f7e0a8ebeb..4b75b09d1c75d6796e75efc55e7b06917834b63e:/src/views/search-results-panel/search-results-panel-view.tsx

diff --git a/src/views/search-results-panel/search-results-panel-view.tsx b/src/views/search-results-panel/search-results-panel-view.tsx
index fbaba210..60fdd33e 100644
--- a/src/views/search-results-panel/search-results-panel-view.tsx
+++ b/src/views/search-results-panel/search-results-panel-view.tsx
@@ -2,30 +2,33 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-import * as React from 'react';
-import { SortDirection } from '~/components/data-table/data-column';
-import { DataColumns } from '~/components/data-table/data-table';
-import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
-import { ResourceKind } from '~/models/resource';
-import { ContainerRequestState } from '~/models/container-request';
-import { SEARCH_RESULTS_PANEL_ID } from '~/store/search-results-panel/search-results-panel-actions';
-import { DataExplorer } from '~/views-components/data-explorer/data-explorer';
+import React, { useEffect, useCallback, useState } from 'react';
+import { SortDirection } from 'components/data-table/data-column';
+import { DataColumns } from 'components/data-table/data-table';
+import { DataTableFilterItem } from 'components/data-table-filters/data-table-filters';
+import { extractUuidKind, ResourceKind } from 'models/resource';
+import { ContainerRequestState } from 'models/container-request';
+import { SEARCH_RESULTS_PANEL_ID } from 'store/search-results-panel/search-results-panel-actions';
+import { DataExplorer } from 'views-components/data-explorer/data-explorer';
 import {
     ResourceCluster,
     ResourceFileSize,
     ResourceLastModifiedDate,
     ResourceName,
-    ResourceOwner,
+    ResourceOwnerWithName,
     ResourceStatus,
     ResourceType
-} from '~/views-components/data-explorer/renderers';
-import { createTree } from '~/models/tree';
-import { getInitialResourceTypeFilters } from '~/store/resource-type-filters/resource-type-filters';
+} from 'views-components/data-explorer/renderers';
+import servicesProvider from 'common/service-provider';
+import { createTree } from 'models/tree';
+import { getInitialResourceTypeFilters } from 'store/resource-type-filters/resource-type-filters';
 import { SearchResultsPanelProps } from "./search-results-panel";
-import { Routes } from '~/routes/routes';
+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 { ArvadosTheme } from 'common/custom-theme';
+import { getSearchSessions } from 'store/search-bar/search-bar-actions';
+import { camelCase } from 'lodash';
 
 export enum SearchResultsPanelColumnNames {
     CLUSTER = "Cluster",
@@ -37,9 +40,12 @@ export enum SearchResultsPanelColumnNames {
     LAST_MODIFIED = "Last modified"
 }
 
-export type CssRules = 'siteManagerLink';
+export type CssRules = 'siteManagerLink' | 'searchResults';
 
 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    searchResults: {
+        width: '100%'
+    },
     siteManagerLink: {
         marginRight: theme.spacing.unit * 2,
         float: 'right'
@@ -85,7 +91,7 @@ export const searchResultsPanelColumns: DataColumns<string> = [
         selected: true,
         configurable: true,
         filters: createTree(),
-        render: uuid => <ResourceOwner uuid={uuid} />
+        render: uuid => <ResourceOwnerWithName uuid={uuid} />
     },
     {
         name: SearchResultsPanelColumnNames.FILE_SIZE,
@@ -106,14 +112,60 @@ export const searchResultsPanelColumns: DataColumns<string> = [
 
 export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
     (props: SearchResultsPanelProps & WithStyles<CssRules, true>) => {
-        const homeCluster = props.user.uuid.substr(0, 5);
+        const homeCluster = props.user.uuid.substring(0, 5);
         const loggedIn = props.sessions.filter((ss) => ss.loggedIn && ss.userIsActive);
-        return <DataExplorer
+        const [selectedItem, setSelectedItem] = useState('');
+        const [itemPath, setItemPath] = useState<string[]>([]);
+
+        useEffect(() => {
+            let tmpPath: string[] = [];
+
+            (async () => {
+                if (selectedItem !== '') {
+                    let searchUuid = selectedItem;
+                    let itemKind = extractUuidKind(searchUuid);
+
+                    while (itemKind !== ResourceKind.USER) {
+                        const clusterId = searchUuid.split('-')[0];
+                        const serviceType = camelCase(itemKind?.replace('arvados#', ''));
+                        const service = Object.values(servicesProvider.getServices())
+                            .filter(({resourceType}) => !!resourceType)
+                            .find(({resourceType}) => camelCase(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);
+                            tmpPath.push(name);
+                            searchUuid = ownerUuid;
+                            itemKind = extractUuidKind(searchUuid);
+                        } else {
+                            break;
+                        }
+                    }
+
+                    tmpPath.push(props.user.uuid === searchUuid ? 'Projects' : 'Shared with me');
+                    setItemPath(tmpPath);
+                }
+            })();
+
+        // 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' className={props.classes.searchResults}>
+            <DataExplorer
             id={SEARCH_RESULTS_PANEL_ID}
-            onRowClick={props.onItemClick}
+            onRowClick={onItemClick}
             onRowDoubleClick={props.onItemDoubleClick}
             onContextMenu={props.onContextMenu}
             contextMenuColumn={false}
+            elementPath={`/ ${itemPath.reverse().join(' / ')}`}
             hideSearchInput
             title={
                 <div>
@@ -127,5 +179,5 @@ export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
                         : <span style={{ marginLeft: "2em" }}>Use <Link to={Routes.SITE_MANAGER} >Site Manager</Link> to manage which clusters will be searched.</span>}
                 </div >
             }
-        />;
+        /></span>;
     });
