Merge branch '21846-rightclick-context-menu'
[arvados.git] / services / workbench2 / src / views / project-panel / project-panel-run.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { ProjectIcon } from "components/icon/icon";
7 import { PROJECT_PANEL_RUN_ID } from "store/project-panel/project-panel-action-bind";
8 import { DataColumns } from 'components/data-table/data-table';
9 import { DataExplorer } from "views-components/data-explorer/data-explorer";
10 import { ProjectResource } from 'models/project';
11 import { SortDirection } from "components/data-table/data-column";
12 import { createTree } from "models/tree";
13 import {
14     ContainerRunTime,
15     ResourceContainerUuid,
16     ResourceCreatedAtDate,
17     ResourceDeleteDate,
18     ResourceLastModifiedDate,
19     ResourceLogUuid,
20     ResourceModifiedByUserUuid,
21     ResourceName,
22     ResourceOutputUuid,
23     ResourceOwnerWithName,
24     ResourceParentProcess,
25     ResourceStatus,
26     ResourceTrashDate,
27     ResourceType,
28     ResourceUUID,
29 } from "views-components/data-explorer/renderers";
30 import { getInitialProcessStatusFilters, getInitialProcessTypeFilters } from "store/resource-type-filters/resource-type-filters";
31 import { SubprocessProgressBar } from "components/subprocess-progress-bar/subprocess-progress-bar";
32 import { connect } from "react-redux";
33 import { RootState } from "store/store";
34 import { getProjectPanelCurrentUuid } from "store/project-panel/project-panel-action";
35 import { getResource } from "store/resources/resources";
36
37 export enum ProjectPanelRunColumnNames {
38     NAME = 'Name',
39     STATUS = 'Status',
40     TYPE = 'Type',
41     OWNER = 'Owner',
42     PORTABLE_DATA_HASH = 'Portable Data Hash',
43     FILE_SIZE = 'File Size',
44     FILE_COUNT = 'File Count',
45     UUID = 'UUID',
46     CONTAINER_UUID = 'Container UUID',
47     RUNTIME = 'Runtime',
48     OUTPUT_UUID = 'Output UUID',
49     LOG_UUID = 'Log UUID',
50     PARENT_PROCESS = 'Parent Process UUID',
51     MODIFIED_BY_USER_UUID = 'Modified by User UUID',
52     VERSION = 'Version',
53     CREATED_AT = 'Date Created',
54     LAST_MODIFIED = 'Last Modified',
55     TRASH_AT = 'Trash at',
56     DELETE_AT = 'Delete at',
57 }
58
59 export const projectPanelRunColumns: DataColumns<string, ProjectResource> = [
60     {
61         name: ProjectPanelRunColumnNames.NAME,
62         selected: true,
63         configurable: true,
64         sort: { direction: SortDirection.NONE, field: 'name' },
65         filters: createTree(),
66         render: (uuid) => <ResourceName uuid={uuid} />,
67     },
68     {
69         name: ProjectPanelRunColumnNames.STATUS,
70         selected: true,
71         configurable: true,
72         mutuallyExclusiveFilters: true,
73         filters: getInitialProcessStatusFilters(),
74         render: (uuid) => <ResourceStatus uuid={uuid} />,
75     },
76     {
77         name: ProjectPanelRunColumnNames.TYPE,
78         selected: true,
79         configurable: true,
80         filters: getInitialProcessTypeFilters(),
81         render: (uuid) => <ResourceType uuid={uuid} />,
82     },
83     {
84         name: ProjectPanelRunColumnNames.OWNER,
85         selected: false,
86         configurable: true,
87         filters: createTree(),
88         render: (uuid) => <ResourceOwnerWithName uuid={uuid} />,
89     },
90     {
91         name: ProjectPanelRunColumnNames.UUID,
92         selected: false,
93         configurable: true,
94         filters: createTree(),
95         render: (uuid) => <ResourceUUID uuid={uuid} />,
96     },
97     {
98         name: ProjectPanelRunColumnNames.CONTAINER_UUID,
99         selected: false,
100         configurable: true,
101         filters: createTree(),
102         render: (uuid) => <ResourceContainerUuid uuid={uuid} />,
103     },
104     {
105         name: ProjectPanelRunColumnNames.RUNTIME,
106         selected: true,
107         configurable: true,
108         filters: createTree(),
109         render: (uuid) => <ContainerRunTime uuid={uuid} />,
110     },
111     {
112         name: ProjectPanelRunColumnNames.OUTPUT_UUID,
113         selected: false,
114         configurable: true,
115         filters: createTree(),
116         render: (uuid) => <ResourceOutputUuid uuid={uuid} />,
117     },
118     {
119         name: ProjectPanelRunColumnNames.LOG_UUID,
120         selected: false,
121         configurable: true,
122         filters: createTree(),
123         render: (uuid) => <ResourceLogUuid uuid={uuid} />,
124     },
125     {
126         name: ProjectPanelRunColumnNames.PARENT_PROCESS,
127         selected: false,
128         configurable: true,
129         filters: createTree(),
130         render: (uuid) => <ResourceParentProcess uuid={uuid} />,
131     },
132     {
133         name: ProjectPanelRunColumnNames.MODIFIED_BY_USER_UUID,
134         selected: false,
135         configurable: true,
136         filters: createTree(),
137         render: (uuid) => <ResourceModifiedByUserUuid uuid={uuid} />,
138     },
139     {
140         name: ProjectPanelRunColumnNames.CREATED_AT,
141         selected: false,
142         configurable: true,
143         sort: { direction: SortDirection.NONE, field: 'createdAt' },
144         filters: createTree(),
145         render: (uuid) => <ResourceCreatedAtDate uuid={uuid} />,
146     },
147     {
148         name: ProjectPanelRunColumnNames.LAST_MODIFIED,
149         selected: true,
150         configurable: true,
151         sort: { direction: SortDirection.DESC, field: 'modifiedAt' },
152         filters: createTree(),
153         render: (uuid) => <ResourceLastModifiedDate uuid={uuid} />,
154     },
155     {
156         name: ProjectPanelRunColumnNames.TRASH_AT,
157         selected: false,
158         configurable: true,
159         sort: { direction: SortDirection.NONE, field: 'trashAt' },
160         filters: createTree(),
161         render: (uuid) => <ResourceTrashDate uuid={uuid} />,
162     },
163     {
164         name: ProjectPanelRunColumnNames.DELETE_AT,
165         selected: false,
166         configurable: true,
167         sort: { direction: SortDirection.NONE, field: 'deleteAt' },
168         filters: createTree(),
169         render: (uuid) => <ResourceDeleteDate uuid={uuid} />,
170     },
171 ];
172
173 const DEFAULT_VIEW_MESSAGES = ['No workflow runs found'];
174
175 interface ProjectPanelRunProps {
176     project?: ProjectResource;
177     paperClassName?: string;
178     onRowClick: (uuid: string) => void;
179     onRowDoubleClick: (uuid: string) => void;
180     onContextMenu: (event: React.MouseEvent<HTMLElement>, resourceUuid: string) => void;
181 }
182
183 const mapStateToProps = (state: RootState): Pick<ProjectPanelRunProps, 'project'> => {
184     const projectUuid = getProjectPanelCurrentUuid(state) || "";
185     const project = getResource<ProjectResource>(projectUuid)(state.resources);
186     return {
187         project,
188     };
189 };
190
191 export const ProjectPanelRun = connect(mapStateToProps)((props: ProjectPanelRunProps) => {
192     return <DataExplorer
193         id={PROJECT_PANEL_RUN_ID}
194         onRowClick={props.onRowClick}
195         onRowDoubleClick={props.onRowDoubleClick}
196         onContextMenu={props.onContextMenu}
197         contextMenuColumn={true}
198         defaultViewIcon={ProjectIcon}
199         defaultViewMessages={DEFAULT_VIEW_MESSAGES}
200         progressBar={<SubprocessProgressBar parentResource={props.project} dataExplorerId={PROJECT_PANEL_RUN_ID} />}
201         paperClassName={props.paperClassName}
202     />;
203 });