add disabled props to checkbox component
[arvados.git] / src / index.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 * as ReactDOM from 'react-dom';
7 import { Provider } from "react-redux";
8 import { MainPanel } from './views/main-panel/main-panel';
9 import './index.css';
10 import { Route } from 'react-router';
11 import createBrowserHistory from "history/createBrowserHistory";
12 import { History } from "history";
13 import { configureStore, RootStore } from './store/store';
14 import { ConnectedRouter } from "react-router-redux";
15 import { ApiToken } from "./views-components/api-token/api-token";
16 import { initAuth } from "./store/auth/auth-action";
17 import { createServices } from "./services/services";
18 import { MuiThemeProvider } from '@material-ui/core/styles';
19 import { CustomTheme } from './common/custom-theme';
20 import { fetchConfig } from './common/config';
21 import { addMenuActionSet, ContextMenuKind } from './views-components/context-menu/context-menu';
22 import { rootProjectActionSet } from "./views-components/context-menu/action-sets/root-project-action-set";
23 import { projectActionSet } from "./views-components/context-menu/action-sets/project-action-set";
24 import { resourceActionSet } from './views-components/context-menu/action-sets/resource-action-set';
25 import { favoriteActionSet } from "./views-components/context-menu/action-sets/favorite-action-set";
26 import { collectionFilesActionSet } from './views-components/context-menu/action-sets/collection-files-action-set';
27 import { collectionFilesItemActionSet } from './views-components/context-menu/action-sets/collection-files-item-action-set';
28 import { collectionActionSet } from './views-components/context-menu/action-sets/collection-action-set';
29 import { collectionResourceActionSet } from './views-components/context-menu/action-sets/collection-resource-action-set';
30 import { processActionSet } from './views-components/context-menu/action-sets/process-action-set';
31 import { loadWorkbench } from './store/workbench/workbench-actions';
32 import { Routes } from '~/routes/routes';
33 import { trashActionSet } from "~/views-components/context-menu/action-sets/trash-action-set";
34 import { ServiceRepository } from '~/services/services';
35 import { initWebSocket } from '~/websocket/websocket';
36 import { Config } from '~/common/config';
37 import { addRouteChangeHandlers } from './routes/route-change-handlers';
38 import { setCurrentTokenDialogApiHost } from '~/store/current-token-dialog/current-token-dialog-actions';
39 import { processResourceActionSet } from '~/views-components/context-menu/action-sets/process-resource-action-set';
40 import { progressIndicatorActions } from '~/store/progress-indicator/progress-indicator-actions';
41 import { setUuidPrefix } from '~/store/workflow-panel/workflow-panel-actions';
42 import { trashedCollectionActionSet } from '~/views-components/context-menu/action-sets/trashed-collection-action-set';
43 import { ContainerRequestState } from '~/models/container-request';
44 import { MountKind } from './models/mount-types';
45 import { setBuildInfo } from '~/store/app-info/app-info-actions';
46 import { getBuildInfo } from '~/common/app-info';
47
48 console.log(`Starting arvados [${getBuildInfo()}]`);
49
50 addMenuActionSet(ContextMenuKind.ROOT_PROJECT, rootProjectActionSet);
51 addMenuActionSet(ContextMenuKind.PROJECT, projectActionSet);
52 addMenuActionSet(ContextMenuKind.RESOURCE, resourceActionSet);
53 addMenuActionSet(ContextMenuKind.FAVORITE, favoriteActionSet);
54 addMenuActionSet(ContextMenuKind.COLLECTION_FILES, collectionFilesActionSet);
55 addMenuActionSet(ContextMenuKind.COLLECTION_FILES_ITEM, collectionFilesItemActionSet);
56 addMenuActionSet(ContextMenuKind.COLLECTION, collectionActionSet);
57 addMenuActionSet(ContextMenuKind.COLLECTION_RESOURCE, collectionResourceActionSet);
58 addMenuActionSet(ContextMenuKind.TRASHED_COLLECTION, trashedCollectionActionSet);
59 addMenuActionSet(ContextMenuKind.PROCESS, processActionSet);
60 addMenuActionSet(ContextMenuKind.PROCESS_RESOURCE, processResourceActionSet);
61 addMenuActionSet(ContextMenuKind.TRASH, trashActionSet);
62
63 fetchConfig()
64     .then(({ config, apiHost }) => {
65         const history = createBrowserHistory();
66         const services = createServices(config, {
67             progressFn: (id, working) => {
68                 store.dispatch(progressIndicatorActions.TOGGLE_WORKING({ id, working }));
69             },
70             errorFn: (id, error) => {
71                 // console.error("Backend error:", error);
72                 // store.dispatch(snackbarActions.OPEN_SNACKBAR({ message: "Backend error", kind: SnackbarKind.ERROR }));
73             }
74         });
75         const store = configureStore(history, services);
76
77         store.subscribe(initListener(history, store, services, config));
78         store.dispatch(initAuth());
79         store.dispatch(setBuildInfo());
80         store.dispatch(setCurrentTokenDialogApiHost(apiHost));
81         store.dispatch(setUuidPrefix(config.uuidPrefix));
82
83         const TokenComponent = (props: any) => <ApiToken authService={services.authService} {...props} />;
84         const MainPanelComponent = (props: any) => <MainPanel {...props} />;
85
86         const App = () =>
87             <MuiThemeProvider theme={CustomTheme}>
88                 <Provider store={store}>
89                     <ConnectedRouter history={history}>
90                         <div>
91                             <Route path={Routes.TOKEN} component={TokenComponent} />
92                             <Route path={Routes.ROOT} component={MainPanelComponent} />
93                         </div>
94                     </ConnectedRouter>
95                 </Provider>
96             </MuiThemeProvider>;
97
98         ReactDOM.render(
99             <App />,
100             document.getElementById('root') as HTMLElement
101         );
102     });
103
104 const initListener = (history: History, store: RootStore, services: ServiceRepository, config: Config) => {
105     let initialized = false;
106     return async () => {
107         const { router, auth } = store.getState();
108         if (router.location && auth.user && !initialized) {
109             initialized = true;
110             initWebSocket(config, services.authService, store);
111             await store.dispatch(loadWorkbench());
112             addRouteChangeHandlers(history, store);
113             // createEnumCollectorWorkflow(services);
114         }
115     };
116 };
117
118 const createPrimitivesCollectorWorkflow = ({workflowService}:ServiceRepository) => {
119     workflowService.create({
120             name: 'Primitive values collector',
121             description: 'Workflow for collecting primitive values',
122             definition: "cwlVersion: v1.0\n$graph:\n- class: CommandLineTool\n  requirements:\n  - listing:\n    - entryname: input_collector.log\n      entry: |\n        \"flag\":\n          $(inputs.example_flag)\n        \"string\":\n          $(inputs.example_string)\n        \"int\":\n          $(inputs.example_int)\n        \"long\":\n          $(inputs.example_long)\n        \"float\":\n          $(inputs.example_float)\n        \"double\":\n          $(inputs.example_double)\n    class: InitialWorkDirRequirement\n  inputs:\n  - type: double\n    id: '#input_collector.cwl/example_double'\n  - type: boolean\n    id: '#input_collector.cwl/example_flag'\n  - type: float\n    id: '#input_collector.cwl/example_float'\n  - type: int\n    id: '#input_collector.cwl/example_int'\n  - type: long\n    id: '#input_collector.cwl/example_long'\n  - type: string\n    id: '#input_collector.cwl/example_string'\n  outputs:\n  - type: File\n    outputBinding:\n      glob: '*'\n    id: '#input_collector.cwl/output'\n  baseCommand: [echo]\n  id: '#input_collector.cwl'\n- class: Workflow\n  doc: Workflw for collecting primitive values\n  inputs:\n  - type: double\n    label: Double value\n    doc: This should allow for entering a decimal number (64-bit).\n    id: '#main/example_double'\n    default: 0.3333333333333333\n  - type: boolean\n    label: Boolean Flag\n    doc: This should render as in checkbox.\n    id: '#main/example_flag'\n    default: true\n  - type: float\n    label: Float value\n    doc: This should allow for entering a decimal number (32-bit).\n    id: '#main/example_float'\n    default: 0.15625\n  - type: int\n    label: Integer Number\n    doc: This should allow for entering a number (32-bit signed).\n    id: '#main/example_int'\n    default: 2147483647\n  - type: long\n    label: Long Number\n    doc: This should allow for entering a number (64-bit signed).\n    id: '#main/example_long'\n    default: 9223372036854775807\n  - type: string\n    label: Freetext\n    doc: This should allow for entering an arbitrary char sequence.\n    id: '#main/example_string'\n    default: This is a string\n  outputs:\n  - type: File\n    outputSource: '#main/input_collector/output'\n    id: '#main/log_file'\n  steps:\n  - run: '#input_collector.cwl'\n    in:\n    - source: '#main/example_double'\n      id: '#main/input_collector/example_double'\n    - source: '#main/example_flag'\n      id: '#main/input_collector/example_flag'\n    - source: '#main/example_float'\n      id: '#main/input_collector/example_float'\n    - source: '#main/example_int'\n      id: '#main/input_collector/example_int'\n    - source: '#main/example_long'\n      id: '#main/input_collector/example_long'\n    - source: '#main/example_string'\n      id: '#main/input_collector/example_string'\n    out: ['#main/input_collector/output']\n    id: '#main/input_collector'\n  id: '#main'\n",
123         });
124 };
125
126 const createEnumCollectorWorkflow = ({workflowService}:ServiceRepository) => {
127     workflowService.create({
128             name: 'Enum values collector',
129             description: 'Workflow for collecting enum values',
130             definition: "cwlVersion: v1.0\n$graph:\n- class: CommandLineTool\n  requirements:\n  - listing:\n    - entryname: input_collector.log\n      entry: |\n        \"enum_type\":\n          $(inputs.enum_type)\n\n    class: InitialWorkDirRequirement\n  inputs:\n  - type:\n      type: enum\n      symbols: ['#input_collector.cwl/enum_type/OTU table', '#input_collector.cwl/enum_type/Pathway\n          table', '#input_collector.cwl/enum_type/Function table', '#input_collector.cwl/enum_type/Ortholog\n          table']\n    id: '#input_collector.cwl/enum_type'\n  outputs:\n  - type: File\n    outputBinding:\n      glob: '*'\n    id: '#input_collector.cwl/output'\n  baseCommand: [echo]\n  id: '#input_collector.cwl'\n- class: Workflow\n  doc: This is the description of the workflow\n  inputs:\n  - type:\n      type: enum\n      symbols: ['#main/enum_type/OTU table', '#main/enum_type/Pathway table', '#main/enum_type/Function\n          table', '#main/enum_type/Ortholog table']\n      name: '#enum_typef4179c7f-45f9-482d-a5db-1abb86698384'\n    label: Enumeration Type\n    doc: This should render as a drop-down menu.\n    id: '#main/enum_type'\n    default: OTU table\n  outputs:\n  - type: File\n    outputSource: '#main/input_collector/output'\n    id: '#main/log_file'\n  steps:\n  - run: '#input_collector.cwl'\n    in:\n    - source: '#main/enum_type'\n      id: '#main/input_collector/enum_type'\n    out: ['#main/input_collector/output']\n    id: '#main/input_collector'\n  id: '#main'\n",
131         });
132 };
133
134 const createSampleProcess = ({ containerRequestService }: ServiceRepository) => {
135     containerRequestService.create({
136         ownerUuid: 'c97qk-j7d0g-s3ngc1z0748hsmf',
137         name: 'Simple process 7',
138         state: ContainerRequestState.COMMITTED,
139         mounts: {
140             '/var/spool/cwl': {
141                 kind: MountKind.COLLECTION,
142                 writable: true,
143             },
144             'stdout': {
145                 kind: MountKind.MOUNTED_FILE,
146                 path: '/var/spool/cwl/cwl.output.json'
147             },
148             '/var/lib/cwl/workflow.json': {
149                 kind: MountKind.JSON,
150                 content: {
151                     "cwlVersion": "v1.0",
152                     "$graph": [
153                         {
154                             "class": "CommandLineTool",
155                             "requirements": [
156                                 {
157                                   "listing": [
158                                     {
159                                       "entryname": "input_collector.log",
160                                       "entry": "$(inputs.single_file.basename)\n"
161                                     }
162                                   ],
163                                   "class": "InitialWorkDirRequirement"
164                                 }
165                               ],
166                             "inputs": [
167                                 {
168                                     "type": "File",
169                                     "id": "#input_collector.cwl/single_file"
170                                 }
171                             ],
172                             "outputs": [
173                                 {
174                                     "type": "File",
175                                     "outputBinding": {
176                                         "glob": "*"
177                                     },
178                                     "id": "#input_collector.cwl/output"
179                                 }
180                             ],
181                             "baseCommand": [
182                                 "echo"
183                             ],
184                             "id": "#input_collector.cwl"
185                         },
186                         {
187                             "class": "Workflow",
188                             "doc": "This is the description of the workflow",
189                             "inputs": [
190                                 {
191                                     "type": "File",
192                                     "label": "Single File",
193                                     "doc": "This should allow for single File selection only.",
194                                     "id": "#main/single_file"
195                                 }
196                             ],
197                             "outputs": [
198                                 {
199                                     "type": "File",
200                                     "outputSource": "#main/input_collector/output",
201                                     "id": "#main/log_file"
202                                 }
203                             ],
204                             "steps": [
205                                 {
206                                     "run": "#input_collector.cwl",
207                                     "in": [
208                                         {
209                                             "source": "#main/single_file",
210                                             "id": "#main/input_collector/single_file"
211                                         }
212                                     ],
213                                     "out": [
214                                         "#main/input_collector/output"
215                                     ],
216                                     "id": "#main/input_collector"
217                                 }
218                             ],
219                             "id": "#main"
220                         }
221                     ]
222                 },
223             },
224             '/var/lib/cwl/cwl.input.json': {
225                 kind: MountKind.JSON,
226                 content: {
227                     "single_file": {
228                         "class": "File",
229                         "location": "keep:233454526794c0a2d56a305baeff3d30+145/1.txt",
230                         "basename": "fileA"
231                       }
232                 },
233             }
234         },
235         runtimeConstraints: {
236             API: true,
237             vcpus: 1,
238             ram: 1073741824,
239         },
240         containerImage: 'arvados/jobs:1.1.4.20180618144723',
241         cwd: '/var/spool/cwl',
242         command: [
243             'arvados-cwl-runner',
244             '--local',
245             '--api=containers',
246             "--project-uuid=c97qk-j7d0g-s3ngc1z0748hsmf",
247             '/var/lib/cwl/workflow.json#main',
248             '/var/lib/cwl/cwl.input.json'
249         ],
250         outputPath: '/var/spool/cwl',
251         priority: 1,
252     });
253 };
254