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