16811: Fix public favorites.
[arvados-workbench2.git] / src / store / workflow-panel / workflow-panel-actions.ts
index 3d51cbb8dbff61db38620569ff19d6087b78287a..bfd899fd38d973b62b627242bd657f11ecbcab69 100644 (file)
@@ -7,11 +7,12 @@ import { RootState } from '~/store/store';
 import { ServiceRepository } from '~/services/services';
 import { bindDataExplorerActions } from '~/store/data-explorer/data-explorer-action';
 import { propertiesActions } from '~/store/properties/properties-actions';
-import { getResource } from '../resources/resources';
 import { getProperty } from '~/store/properties/properties';
-import { WorkflowResource } from '~/models/workflow';
 import { navigateToRunProcess } from '~/store/navigation/navigation-action';
-import { goToStep, runProcessPanelActions } from '~/store/run-process-panel/run-process-panel-actions';
+import { goToStep, runProcessPanelActions, loadPresets, DEFAULT_ADVANCED_FORM_VALUES } from '~/store/run-process-panel/run-process-panel-actions';
+import { snackbarActions } from '~/store/snackbar/snackbar-actions';
+import { initialize } from 'redux-form';
+import { RUN_PROCESS_ADVANCED_FORM } from '~/views/run-process-panel/run-process-advanced-form';
 
 export const WORKFLOW_PANEL_ID = "workflowPanel";
 const UUID_PREFIX_PROPERTY_NAME = 'uuidPrefix';
@@ -33,22 +34,27 @@ export const getUuidPrefix = (state: RootState) => {
 };
 
 export const openRunProcess = (uuid: string) =>
-    async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {  
+    (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const workflows = getState().runProcessPanel.searchWorkflows;
         const workflow = workflows.find(workflow => workflow.uuid === uuid);
-        dispatch<any>(navigateToRunProcess);
-        dispatch(runProcessPanelActions.RESET_RUN_PROCESS_PANEL()); 
-        dispatch<any>(goToStep(1));
-        dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
-        dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow!));       
+        if (workflow) {
+            dispatch<any>(navigateToRunProcess);
+            dispatch<any>(goToStep(1));
+            dispatch(runProcessPanelActions.SET_STEP_CHANGED(true));
+            dispatch(runProcessPanelActions.SET_SELECTED_WORKFLOW(workflow));
+            dispatch<any>(loadPresets(workflow.uuid));
+            dispatch(initialize(RUN_PROCESS_ADVANCED_FORM, DEFAULT_ADVANCED_FORM_VALUES));
+        } else {
+            dispatch<any>(snackbarActions.OPEN_SNACKBAR({ message: `You can't run this process` }));
+        }
     };
 
 export const getPublicUserUuid = (state: RootState) => {
-    const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
+    const prefix = state.auth.localCluster;
     return `${prefix}-tpzed-anonymouspublic`;
 };
 export const getPublicGroupUuid = (state: RootState) => {
-    const prefix = getProperty<string>(UUID_PREFIX_PROPERTY_NAME)(state.properties);
+    const prefix = state.auth.localCluster;
     return `${prefix}-j7d0g-anonymouspublic`;
 };
 
@@ -57,5 +63,7 @@ export const showWorkflowDetails = (uuid: string) =>
 
 export const getWorkflowDetails = (state: RootState) => {
     const uuid = getProperty<string>(WORKFLOW_PANEL_DETAILS_UUID)(state.properties);
-    return uuid ? getResource<WorkflowResource>(uuid)(state.resources) : undefined;
+    const workflows = state.runProcessPanel.workflows;
+    const workflow = workflows.find(workflow => workflow.uuid === uuid);
+    return workflow || undefined;
 };