18549: Layout fixed, tests updated
[arvados-workbench2.git] / src / views / search-results-panel / search-results-panel-view.tsx
index 6febabf2eb164013329e4c2dafa24705fb6294fa..60fdd33ef3a49fc44718b61c383f167a22f3c3f6 100644 (file)
@@ -27,6 +27,8 @@ 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';
+import { camelCase } from 'lodash';
 
 export enum SearchResultsPanelColumnNames {
     CLUSTER = "Cluster",
@@ -38,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'
@@ -110,43 +115,57 @@ 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[] = [];
+        const [itemPath, setItemPath] = useState<string[]>([]);
 
         useEffect(() => {
-            if (selectedItem !== '') {
-                itemPath = [];
+            let tmpPath: 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 = 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;
+                        }
                     }
 
-                    const rootFolder = props.user.uuid === searchUuid ? 'Projects' : 'Shared with me';
-                    itemPath.push(rootFolder);
+                    tmpPath.push(props.user.uuid === searchUuid ? 'Projects' : 'Shared with me');
+                    setItemPath(tmpPath);
+                }
+            })();
 
-                    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' className={props.classes.searchResults}>
+            <DataExplorer
             id={SEARCH_RESULTS_PANEL_ID}
             onRowClick={onItemClick}
             onRowDoubleClick={props.onItemDoubleClick}
             onContextMenu={props.onContextMenu}
             contextMenuColumn={false}
+            elementPath={`/ ${itemPath.reverse().join(' / ')}`}
             hideSearchInput
             title={
                 <div>