@@ -11,7 +11,8 @@ import { auth0State, errorsState } from '../state/atoms';
11
11
import { protocolsQuery , runsQuery } from '../state/selectors' ;
12
12
import moment from 'moment' ;
13
13
import { LoadingPage } from '../components/LoadingPage' ;
14
- import { FetchError , upsertProtocol , upsertRun } from '../state/api' ;
14
+ import { apiGetOne , FetchError , upsertProtocol , upsertRun } from '../state/api' ;
15
+ import { labflowOptions } from '../config' ;
15
16
16
17
export function HomePage ( ) {
17
18
const [ runsTimestamp , setRunsTimestamp ] = React . useState ( "" ) ;
@@ -49,7 +50,13 @@ export function HomePage() {
49
50
history . push ( `/protocol/${ created . id } ` ) ;
50
51
}
51
52
} ;
52
- const createRun = ( protocol : Protocol ) => async ( ) => {
53
+ const createRun = useRecoilCallback ( ( { snapshot } ) => async ( protocol : Protocol ) => {
54
+ const { auth0Client } = await snapshot . getPromise ( auth0State ) ;
55
+ const fullProtocol : Protocol = await apiGetOne ( labflowOptions , ( ) => auth0Client , `protocol/${ protocol . id } ` ) ;
56
+ if ( fullProtocol ) {
57
+ protocol = fullProtocol ;
58
+ }
59
+
53
60
// Create new run
54
61
const created = await runUpsert ( {
55
62
status : 'todo' ,
@@ -64,7 +71,7 @@ export function HomePage() {
64
71
} ) ;
65
72
// Redirect to the new run page editor
66
73
history . push ( `/run/${ created . id } ` ) ;
67
- } ;
74
+ } ) ;
68
75
const refresh = ( ) => {
69
76
setRunsTimestamp ( moment ( ) . format ( ) ) ;
70
77
setProtocolsTimestamp ( moment ( ) . format ( ) ) ;
@@ -95,7 +102,7 @@ export function HomePage() {
95
102
< Dropdown . Menu >
96
103
{
97
104
protocols && protocols . map ( protocol =>
98
- < Dropdown . Item key = { protocol . id } onClick = { createRun ( protocol ) } >
105
+ < Dropdown . Item key = { protocol . id } onClick = { ( ) => createRun ( protocol ) } >
99
106
{ protocol . name || < i > Untitled Protocol</ i > }
100
107
</ Dropdown . Item >
101
108
)
0 commit comments