[d6876d]: / src / hooks / usePipeline.ts

Download this file

72 lines (62 with data), 2.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { AppDispatch, RootState } from '../store/store';
import {
runExperiment,
monitorExperiment,
stopExperiment,
clearError
} from '../store/slices/pipelineSlice';
import { ExperimentConfig, GeneAssembly, UsePipelineResult } from '../types';
export const usePipeline = (): UsePipelineResult => {
const dispatch = useDispatch<AppDispatch>();
const { isProcessing, error } = useSelector((state: RootState) => state.pipeline);
const startPipeline = useCallback(
async (config: { experimentConfig: ExperimentConfig; assembly: GeneAssembly }) => {
try {
await dispatch(runExperiment({
config: config.experimentConfig,
assembly: config.assembly
})).unwrap();
// Start monitoring the experiment
const experimentId = config.experimentConfig.id;
await dispatch(monitorExperiment(experimentId)).unwrap();
} catch (error) {
console.error('Pipeline execution failed:', error);
}
},
[dispatch]
);
const stopPipelineExecution = useCallback(
async (id: string) => {
try {
await dispatch(stopExperiment(id)).unwrap();
} catch (error) {
console.error('Failed to stop pipeline:', error);
}
},
[dispatch]
);
const clearPipelineError = useCallback(() => {
dispatch(clearError());
}, [dispatch]);
return {
isProcessing,
error,
startPipeline,
stopPipeline: stopPipelineExecution,
clearError: clearPipelineError,
};
};
// Selector hooks for different pipeline results
export const useExperimentResults = () => {
return useSelector((state: RootState) => state.pipeline.activeExperiments);
};
export const useGenomicAnalyses = () => {
return useSelector((state: RootState) => state.pipeline.genomicAnalyses);
};
export const useSimulationResults = () => {
return useSelector((state: RootState) => state.pipeline.simulations);
};
// Export for module resolution
export default usePipeline;