fbaba210e29b94cec6d32def6256c6eba116d342
[arvados-workbench2.git] / src / views / search-results-panel / search-results-panel-view.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import { SortDirection } from '~/components/data-table/data-column';
7 import { DataColumns } from '~/components/data-table/data-table';
8 import { DataTableFilterItem } from '~/components/data-table-filters/data-table-filters';
9 import { ResourceKind } from '~/models/resource';
10 import { ContainerRequestState } from '~/models/container-request';
11 import { SEARCH_RESULTS_PANEL_ID } from '~/store/search-results-panel/search-results-panel-actions';
12 import { DataExplorer } from '~/views-components/data-explorer/data-explorer';
13 import {
14     ResourceCluster,
15     ResourceFileSize,
16     ResourceLastModifiedDate,
17     ResourceName,
18     ResourceOwner,
19     ResourceStatus,
20     ResourceType
21 } from '~/views-components/data-explorer/renderers';
22 import { createTree } from '~/models/tree';
23 import { getInitialResourceTypeFilters } from '~/store/resource-type-filters/resource-type-filters';
24 import { SearchResultsPanelProps } from "./search-results-panel";
25 import { Routes } from '~/routes/routes';
26 import { Link } from 'react-router-dom';
27 import { StyleRulesCallback, withStyles, WithStyles } from '@material-ui/core';
28 import { ArvadosTheme } from '~/common/custom-theme';
29
30 export enum SearchResultsPanelColumnNames {
31     CLUSTER = "Cluster",
32     NAME = "Name",
33     STATUS = "Status",
34     TYPE = 'Type',
35     OWNER = "Owner",
36     FILE_SIZE = "File size",
37     LAST_MODIFIED = "Last modified"
38 }
39
40 export type CssRules = 'siteManagerLink';
41
42 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
43     siteManagerLink: {
44         marginRight: theme.spacing.unit * 2,
45         float: 'right'
46     }
47 });
48
49 export interface WorkflowPanelFilter extends DataTableFilterItem {
50     type: ResourceKind | ContainerRequestState;
51 }
52
53 export const searchResultsPanelColumns: DataColumns<string> = [
54     {
55         name: SearchResultsPanelColumnNames.CLUSTER,
56         selected: true,
57         configurable: true,
58         filters: createTree(),
59         render: (uuid: string) => <ResourceCluster uuid={uuid} />
60     },
61     {
62         name: SearchResultsPanelColumnNames.NAME,
63         selected: true,
64         configurable: true,
65         sortDirection: SortDirection.NONE,
66         filters: createTree(),
67         render: (uuid: string) => <ResourceName uuid={uuid} />
68     },
69     {
70         name: SearchResultsPanelColumnNames.STATUS,
71         selected: true,
72         configurable: true,
73         filters: createTree(),
74         render: uuid => <ResourceStatus uuid={uuid} />
75     },
76     {
77         name: SearchResultsPanelColumnNames.TYPE,
78         selected: true,
79         configurable: true,
80         filters: getInitialResourceTypeFilters(),
81         render: (uuid: string) => <ResourceType uuid={uuid} />,
82     },
83     {
84         name: SearchResultsPanelColumnNames.OWNER,
85         selected: true,
86         configurable: true,
87         filters: createTree(),
88         render: uuid => <ResourceOwner uuid={uuid} />
89     },
90     {
91         name: SearchResultsPanelColumnNames.FILE_SIZE,
92         selected: true,
93         configurable: true,
94         filters: createTree(),
95         render: uuid => <ResourceFileSize uuid={uuid} />
96     },
97     {
98         name: SearchResultsPanelColumnNames.LAST_MODIFIED,
99         selected: true,
100         configurable: true,
101         sortDirection: SortDirection.DESC,
102         filters: createTree(),
103         render: uuid => <ResourceLastModifiedDate uuid={uuid} />
104     }
105 ];
106
107 export const SearchResultsPanelView = withStyles(styles, { withTheme: true })(
108     (props: SearchResultsPanelProps & WithStyles<CssRules, true>) => {
109         const homeCluster = props.user.uuid.substr(0, 5);
110         const loggedIn = props.sessions.filter((ss) => ss.loggedIn && ss.userIsActive);
111         return <DataExplorer
112             id={SEARCH_RESULTS_PANEL_ID}
113             onRowClick={props.onItemClick}
114             onRowDoubleClick={props.onItemDoubleClick}
115             onContextMenu={props.onContextMenu}
116             contextMenuColumn={false}
117             hideSearchInput
118             title={
119                 <div>
120                     {loggedIn.length === 1 ?
121                         <span>Searching local cluster <ResourceCluster uuid={props.localCluster} /></span>
122                         : <span>Searching clusters: {loggedIn.map((ss) => <span key={ss.clusterId}>
123                             <a href={props.remoteHostsConfig[ss.clusterId] && props.remoteHostsConfig[ss.clusterId].workbench2Url} style={{ textDecoration: 'none' }}> <ResourceCluster uuid={ss.clusterId} /></a>
124                         </span>)}</span>}
125                     {loggedIn.length === 1 && props.localCluster !== homeCluster ?
126                         <span>To search multiple clusters, <a href={props.remoteHostsConfig[homeCluster] && props.remoteHostsConfig[homeCluster].workbench2Url}> start from your home Workbench.</a></span>
127                         : <span style={{ marginLeft: "2em" }}>Use <Link to={Routes.SITE_MANAGER} >Site Manager</Link> to manage which clusters will be searched.</span>}
128                 </div >
129             }
130         />;
131     });