1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { CustomStyleRulesCallback } from 'common/custom-theme';
7 import { WithStyles } from '@mui/styles';
8 import withStyles from '@mui/styles/withStyles';
9 import { DataExplorer } from "views-components/data-explorer/data-explorer";
10 import { connect, DispatchProp } from "react-redux";
11 import { DataColumns } from "components/data-table/data-table";
12 import { RouteComponentProps } from "react-router";
13 import { DataTableFilterItem } from "components/data-table-filters/data-table-filters";
14 import { SortDirection } from "components/data-table/data-column";
15 import { ResourceKind } from "models/resource";
16 import { ArvadosTheme } from "common/custom-theme";
17 import { ALL_PROCESSES_PANEL_ID } from "store/all-processes-panel/all-processes-panel-action";
21 ResourceOwnerWithName,
24 ResourceCreatedAtDate,
25 } from "views-components/data-explorer/renderers";
26 import { ProcessIcon } from "components/icon/icon";
27 import { openProcessContextMenu } from "store/context-menu/context-menu-actions";
28 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
29 import { navigateTo } from "store/navigation/navigation-action";
30 import { ContainerRequestResource, ContainerRequestState } from "models/container-request";
31 import { RootState } from "store/store";
32 import { createTree } from "models/tree";
33 import { getInitialProcessStatusFilters, getInitialProcessTypeFilters } from "store/resource-type-filters/resource-type-filters";
34 import { getProcess } from "store/processes/process";
35 import { ResourcesState } from "store/resources/resources";
36 import { toggleOne, deselectAllOthers } from "store/multiselect/multiselect-actions";
38 type CssRules = "toolbar" | "button" | "root";
40 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
42 paddingBottom: theme.spacing(3),
46 marginLeft: theme.spacing(1),
53 export enum AllProcessesPanelColumnNames {
58 CREATED_AT = "Created at",
62 export interface AllProcessesPanelFilter extends DataTableFilterItem {
63 type: ResourceKind | ContainerRequestState;
66 export const allProcessesPanelColumns: DataColumns<string, ContainerRequestResource> = [
68 name: AllProcessesPanelColumnNames.NAME,
71 sort: { direction: SortDirection.NONE, field: "name" },
72 filters: createTree(),
73 render: uuid => <ResourceName uuid={uuid} />,
76 name: AllProcessesPanelColumnNames.STATUS,
79 mutuallyExclusiveFilters: true,
80 filters: getInitialProcessStatusFilters(),
81 render: uuid => <ProcessStatus uuid={uuid} />,
84 name: AllProcessesPanelColumnNames.TYPE,
87 filters: getInitialProcessTypeFilters(),
88 render: uuid => <ResourceType uuid={uuid} />,
91 name: AllProcessesPanelColumnNames.OWNER,
94 filters: createTree(),
95 render: uuid => <ResourceOwnerWithName uuid={uuid} />,
98 name: AllProcessesPanelColumnNames.CREATED_AT,
101 sort: { direction: SortDirection.DESC, field: "createdAt" },
102 filters: createTree(),
103 render: uuid => <ResourceCreatedAtDate uuid={uuid} />,
106 name: AllProcessesPanelColumnNames.RUNTIME,
109 filters: createTree(),
110 render: uuid => <ContainerRunTime uuid={uuid} />,
114 interface AllProcessesPanelDataProps {
115 resources: ResourcesState;
118 interface AllProcessesPanelActionProps {
119 onItemClick: (item: string) => void;
120 onDialogOpen: (ownerUuid: string) => void;
121 onItemDoubleClick: (item: string) => void;
123 const mapStateToProps = (state: RootState): AllProcessesPanelDataProps => ({
124 resources: state.resources,
127 type AllProcessesPanelProps = AllProcessesPanelDataProps &
128 AllProcessesPanelActionProps &
130 WithStyles<CssRules> &
131 RouteComponentProps<{ id: string }>;
133 export const AllProcessesPanel = withStyles(styles)(
134 connect(mapStateToProps)(
135 class extends React.Component<AllProcessesPanelProps> {
136 handleContextMenu = (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => {
137 const process = getProcess(resourceUuid)(this.props.resources);
139 this.props.dispatch<any>(openProcessContextMenu(event, process));
141 this.props.dispatch<any>(loadDetailsPanel(resourceUuid));
144 handleRowDoubleClick = (uuid: string) => {
145 this.props.dispatch<any>(navigateTo(uuid));
148 handleRowClick = (uuid: string) => {
149 this.props.dispatch<any>(toggleOne(uuid))
150 this.props.dispatch<any>(deselectAllOthers(uuid))
151 this.props.dispatch<any>(loadDetailsPanel(uuid));
156 <div className={this.props.classes.root}>
158 id={ALL_PROCESSES_PANEL_ID}
159 onRowClick={this.handleRowClick}
160 onRowDoubleClick={this.handleRowDoubleClick}
161 onContextMenu={this.handleContextMenu}
162 contextMenuColumn={true}
163 defaultViewIcon={ProcessIcon}
164 defaultViewMessages={["Processes list empty."]}