1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { StyleRulesCallback, WithStyles, withStyles } from "@material-ui/core";
7 import { DataExplorer } from "views-components/data-explorer/data-explorer";
8 import { connect, DispatchProp } from "react-redux";
9 import { DataColumns } from "components/data-table/data-table";
10 import { RouteComponentProps } from "react-router";
11 import { DataTableFilterItem } from "components/data-table-filters/data-table-filters";
12 import { SortDirection } from "components/data-table/data-column";
13 import { ResourceKind } from "models/resource";
14 import { ArvadosTheme } from "common/custom-theme";
15 import { ALL_PROCESSES_PANEL_ID } from "store/all-processes-panel/all-processes-panel-action";
19 ResourceOwnerWithName,
22 ResourceCreatedAtDate,
23 } from "views-components/data-explorer/renderers";
24 import { ProcessIcon } from "components/icon/icon";
25 import { openProcessContextMenu } from "store/context-menu/context-menu-actions";
26 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
27 import { navigateTo } from "store/navigation/navigation-action";
28 import { ContainerRequestResource, ContainerRequestState } from "models/container-request";
29 import { RootState } from "store/store";
30 import { createTree } from "models/tree";
31 import { getInitialProcessStatusFilters, getInitialProcessTypeFilters } from "store/resource-type-filters/resource-type-filters";
32 import { getProcess } from "store/processes/process";
33 import { ResourcesState } from "store/resources/resources";
34 import { toggleOne } from "store/multiselect/multiselect-actions";
36 type CssRules = "toolbar" | "button" | "root";
38 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
40 paddingBottom: theme.spacing.unit * 3,
44 marginLeft: theme.spacing.unit,
51 export enum AllProcessesPanelColumnNames {
56 CREATED_AT = "Created at",
60 export interface AllProcessesPanelFilter extends DataTableFilterItem {
61 type: ResourceKind | ContainerRequestState;
64 export const allProcessesPanelColumns: DataColumns<string, ContainerRequestResource> = [
66 name: AllProcessesPanelColumnNames.NAME,
69 sort: { direction: SortDirection.NONE, field: "name" },
70 filters: createTree(),
71 render: uuid => <ResourceName uuid={uuid} />,
74 name: AllProcessesPanelColumnNames.STATUS,
77 mutuallyExclusiveFilters: true,
78 filters: getInitialProcessStatusFilters(),
79 render: uuid => <ProcessStatus uuid={uuid} />,
82 name: AllProcessesPanelColumnNames.TYPE,
85 filters: getInitialProcessTypeFilters(),
86 render: uuid => <ResourceType uuid={uuid} />,
89 name: AllProcessesPanelColumnNames.OWNER,
92 filters: createTree(),
93 render: uuid => <ResourceOwnerWithName uuid={uuid} />,
96 name: AllProcessesPanelColumnNames.CREATED_AT,
99 sort: { direction: SortDirection.DESC, field: "createdAt" },
100 filters: createTree(),
101 render: uuid => <ResourceCreatedAtDate uuid={uuid} />,
104 name: AllProcessesPanelColumnNames.RUNTIME,
107 filters: createTree(),
108 render: uuid => <ContainerRunTime uuid={uuid} />,
112 interface AllProcessesPanelDataProps {
113 resources: ResourcesState;
116 interface AllProcessesPanelActionProps {
117 onItemClick: (item: string) => void;
118 onDialogOpen: (ownerUuid: string) => void;
119 onItemDoubleClick: (item: string) => void;
121 const mapStateToProps = (state: RootState): AllProcessesPanelDataProps => ({
122 resources: state.resources,
125 type AllProcessesPanelProps = AllProcessesPanelDataProps &
126 AllProcessesPanelActionProps &
128 WithStyles<CssRules> &
129 RouteComponentProps<{ id: string }>;
131 export const AllProcessesPanel = withStyles(styles)(
132 connect(mapStateToProps)(
133 class extends React.Component<AllProcessesPanelProps> {
134 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
135 const process = getProcess(resourceUuid)(this.props.resources);
137 this.props.dispatch<any>(openProcessContextMenu(event, process));
139 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
142 handleRowDoubleClick = (uuid: string) => {
143 this.props.dispatch<any>(navigateTo(uuid));
146 handleRowClick = (uuid: string) => {
147 this.props.dispatch<any>(toggleOne(uuid))
148 this.props.dispatch<any>(loadDetailsPanel(uuid));
153 <div className={this.props.classes.root}>
155 id={ALL_PROCESSES_PANEL_ID}
156 onRowClick={this.handleRowClick}
157 onRowDoubleClick={this.handleRowDoubleClick}
158 onContextMenu={this.handleContextMenu}
159 contextMenuColumn={true}
160 defaultViewIcon={ProcessIcon}
161 defaultViewMessages={["Processes list empty."]}