X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/2b3f667039ba2e7efe0852d58ae2c62899b773f0..41f6f1e495c82fcfa79b87cf718fa2e9cd91c726:/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 ea658ee7..e281035c 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,37 @@
 //
 // 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 { resourceLabel } from '~/common/labels';
-import { SearchBarAdvanceFormData } from '~/models/search-bar';
-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 {
-    ProcessStatus,
+    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';
-// TODO: code clean up
+} 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 { 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",
     NAME = "Name",
-    PROJECT = "Project",
     STATUS = "Status",
     TYPE = 'Type',
     OWNER = "Owner",
@@ -33,18 +40,17 @@ export enum SearchResultsPanelColumnNames {
     LAST_MODIFIED = "Last modified"
 }
 
-export interface SearchResultsPanelDataProps {
-    data: SearchBarAdvanceFormData;
-}
-
-export interface SearchResultsPanelActionProps {
-    onItemClick: (item: string) => void;
-    onContextMenu: (event: React.MouseEvent<HTMLElement>, item: string) => void;
-    onDialogOpen: (ownerUuid: string) => void;
-    onItemDoubleClick: (item: string) => void;
-}
+export type CssRules = 'siteManagerLink' | 'searchResults';
 
-export type SearchResultsPanelProps = SearchResultsPanelDataProps & SearchResultsPanelActionProps;
+const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
+    searchResults: {
+        width: '100%'
+    },
+    siteManagerLink: {
+        marginRight: theme.spacing.unit * 2,
+        float: 'right'
+    }
+});
 
 export interface WorkflowPanelFilter extends DataTableFilterItem {
     type: ResourceKind | ContainerRequestState;
@@ -52,26 +58,26 @@ export interface WorkflowPanelFilter extends DataTableFilterItem {
 
 export const searchResultsPanelColumns: DataColumns<string> = [
     {
-        name: SearchResultsPanelColumnNames.NAME,
+        name: SearchResultsPanelColumnNames.CLUSTER,
         selected: true,
         configurable: true,
-        sortDirection: SortDirection.ASC,
         filters: createTree(),
-        render: (uuid: string) => <ResourceName uuid={uuid} />
+        render: (uuid: string) => <ResourceCluster uuid={uuid} />
     },
     {
-        name: SearchResultsPanelColumnNames.PROJECT,
+        name: SearchResultsPanelColumnNames.NAME,
         selected: true,
         configurable: true,
+        sortDirection: SortDirection.NONE,
         filters: createTree(),
-        render: uuid => <ResourceFileSize uuid={uuid} />
+        render: (uuid: string) => <ResourceName uuid={uuid} />
     },
     {
         name: SearchResultsPanelColumnNames.STATUS,
         selected: true,
         configurable: true,
         filters: createTree(),
-        render: uuid => <ProcessStatus uuid={uuid} />
+        render: uuid => <ResourceStatus uuid={uuid} />
     },
     {
         name: SearchResultsPanelColumnNames.TYPE,
@@ -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,
@@ -98,17 +104,80 @@ export const searchResultsPanelColumns: DataColumns<string> = [
         name: SearchResultsPanelColumnNames.LAST_MODIFIED,
         selected: true,
         configurable: true,
-        sortDirection: SortDirection.NONE,
+        sortDirection: SortDirection.DESC,
         filters: createTree(),
         render: uuid => <ResourceLastModifiedDate uuid={uuid} />
     }
 ];
 
-export const SearchResultsPanelView = (props: SearchResultsPanelProps) => {
-    return <DataExplorer
-        id={SEARCH_RESULTS_PANEL_ID}
-        onRowClick={props.onItemClick}
-        onRowDoubleClick={props.onItemDoubleClick}
-        onContextMenu={props.onContextMenu}
-        contextMenuColumn={true} />;
-};
\ No newline at end of file
+export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
+    (props: SearchResultsPanelProps & WithStyles<CssRules, true>) => {
+        const homeCluster = props.user.uuid.substring(0, 5);
+        const loggedIn = props.sessions.filter((ss) => ss.loggedIn && ss.userIsActive);
+        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, undefined, 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={onItemClick}
+            onRowDoubleClick={props.onItemDoubleClick}
+            onContextMenu={props.onContextMenu}
+            contextMenuColumn={false}
+            elementPath={`/ ${itemPath.reverse().join(' / ')}`}
+            hideSearchInput
+            title={
+                <div>
+                    {loggedIn.length === 1 ?
+                        <span>Searching local cluster <ResourceCluster uuid={props.localCluster} /></span>
+                        : <span>Searching clusters: {loggedIn.map((ss) => <span key={ss.clusterId}>
+                            <a href={props.remoteHostsConfig[ss.clusterId] && props.remoteHostsConfig[ss.clusterId].workbench2Url} style={{ textDecoration: 'none' }}> <ResourceCluster uuid={ss.clusterId} /></a>
+                        </span>)}</span>}
+                    {loggedIn.length === 1 && props.localCluster !== homeCluster ?
+                        <span>To search multiple clusters, <a href={props.remoteHostsConfig[homeCluster] && props.remoteHostsConfig[homeCluster].workbench2Url}> start from your home Workbench.</a></span>
+                        : <span style={{ marginLeft: "2em" }}>Use <Link to={Routes.SITE_MANAGER} >Site Manager</Link> to manage which clusters will be searched.</span>}
+                </div >
+            }
+        /></span>;
+    });
