15230: Link to other workbenches when double-clicking search results.
[arvados-workbench2.git] / src / store / run-process-panel / run-process-panel-actions.ts
index 0cbd9cd6823abd18e284e95c9ecc1177b2febb69..7203d375eb3ec1604d9954b4c2d4ed9de672bc09 100644 (file)
@@ -13,13 +13,14 @@ import { RUN_PROCESS_INPUTS_FORM } from '~/views/run-process-panel/run-process-i
 import { WorkflowInputsData } from '~/models/workflow';
 import { createWorkflowMounts } from '~/models/process';
 import { ContainerRequestState } from '~/models/container-request';
-import { navigateToProcess } from '../navigation/navigation-action';
-import { RunProcessAdvancedFormData, RUN_PROCESS_ADVANCED_FORM } from '~/views/run-process-panel/run-process-advanced-form';
-import { isItemNotInProject, isProjectOrRunProcessRoute } from '~/store/projects/project-create-actions';
+import { navigateTo } from '../navigation/navigation-action';
+import { RunProcessAdvancedFormData, RUN_PROCESS_ADVANCED_FORM, VCPUS_FIELD, RAM_FIELD, RUNTIME_FIELD, OUTPUT_FIELD, API_FIELD } from '~/views/run-process-panel/run-process-advanced-form';
 import { dialogActions } from '~/store/dialog/dialog-actions';
 import { setBreadcrumbs } from '~/store/breadcrumbs/breadcrumbs-actions';
+import { matchProjectRoute } from '~/routes/routes';
 
 export const runProcessPanelActions = unionize({
+    SET_PROCESS_PATHNAME: ofType<string>(),
     SET_PROCESS_OWNER_UUID: ofType<string>(),
     SET_CURRENT_STEP: ofType<number>(),
     SET_STEP_CHANGED: ofType<boolean>(),
@@ -45,7 +46,6 @@ export const loadRunProcessPanel = () =>
     async (dispatch: Dispatch<any>, getState: () => RootState, services: ServiceRepository) => {
         try {
             dispatch(setBreadcrumbs([{ label: 'Run Process' }]));
-            dispatch(runProcessPanelActions.RESET_RUN_PROCESS_PANEL());
             const response = await services.workflowService.list();
             dispatch(runProcessPanelActions.SET_WORKFLOWS(response.items));
         } catch (e) {
@@ -79,10 +79,12 @@ export const setWorkflow = (workflow: WorkflowResource, isWorkflowChanged = true
             dispatch(runProcessPanelActions.SET_STEP_CHANGED(false));
             dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
             dispatch<any>(loadPresets(workflow.uuid));
+            dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, DEFAULT_ADVANCED_FORM_VALUES));
         }
         if (!isWorkflowChanged) {
             dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
             dispatch<any>(loadPresets(workflow.uuid));
+            dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, DEFAULT_ADVANCED_FORM_VALUES));
         }
     };
 
@@ -115,42 +117,54 @@ export const runProcess = async (dispatch: Dispatch<any>, getState: () => RootSt
     const state = getState();
     const basicForm = getFormValues(RUN_PROCESS_BASIC_FORM)(state) as RunProcessBasicFormData;
     const inputsForm = getFormValues(RUN_PROCESS_INPUTS_FORM)(state) as WorkflowInputsData;
-    const advancedForm = getFormValues(RUN_PROCESS_ADVANCED_FORM)(state) as RunProcessAdvancedFormData;
+    const advancedForm = getFormValues(RUN_PROCESS_ADVANCED_FORM)(state) as RunProcessAdvancedFormData || DEFAULT_ADVANCED_FORM_VALUES;
     const userUuid = getState().auth.user!.uuid;
-    const router = getState();
-    const properties = getState().properties;
+    const pathname = getState().runProcessPanel.processPathname;
     const { processOwnerUuid, selectedWorkflow } = state.runProcessPanel;
     if (selectedWorkflow) {
         const newProcessData = {
-            ownerUuid: isItemNotInProject(properties) || !isProjectOrRunProcessRoute(router) ? userUuid : processOwnerUuid,
+            ownerUuid: !matchProjectRoute(pathname) ? userUuid : processOwnerUuid,
             name: basicForm.name,
             description: basicForm.description,
             state: ContainerRequestState.COMMITTED,
             mounts: createWorkflowMounts(selectedWorkflow, normalizeInputKeys(inputsForm)),
             runtimeConstraints: {
                 API: true,
-                vcpus: 1,
-                ram: 1073741824,
+                vcpus: advancedForm[VCPUS_FIELD],
+                ram: advancedForm[RAM_FIELD],
+                api: advancedForm[API_FIELD],
+            },
+            schedulingParameters: {
+                maxRunTime: advancedForm[RUNTIME_FIELD]
             },
             containerImage: 'arvados/jobs',
             cwd: '/var/spool/cwl',
             command: [
                 'arvados-cwl-runner',
-                '--local',
                 '--api=containers',
-                `--project-uuid=${processOwnerUuid}`,
+                '--local',
                 '/var/lib/cwl/workflow.json#main',
                 '/var/lib/cwl/cwl.input.json'
             ],
             outputPath: '/var/spool/cwl',
             priority: 1,
-            outputName: advancedForm && advancedForm.output ? advancedForm.output : undefined,
+            outputName: advancedForm[OUTPUT_FIELD] ? advancedForm[OUTPUT_FIELD] : undefined,
+            properties: {
+                workflowUuid: selectedWorkflow.uuid,
+                workflowName: selectedWorkflow.name
+            }
         };
         const newProcess = await services.containerRequestService.create(newProcessData);
-        dispatch(navigateToProcess(newProcess.uuid));
+        dispatch(navigateTo(newProcess.uuid));
     }
 };
 
+export const DEFAULT_ADVANCED_FORM_VALUES: Partial<RunProcessAdvancedFormData> = {
+    [VCPUS_FIELD]: 1,
+    [RAM_FIELD]: 1073741824,
+    [API_FIELD]: true,
+};
+
 const normalizeInputKeys = (inputs: WorkflowInputsData): WorkflowInputsData =>
     Object.keys(inputs).reduce((normalizedInputs, key) => ({
         ...normalizedInputs,