Skip to content

Commit 7875d83

Browse files
committed
Fix create run from home-page.
1 parent fafa3a8 commit 7875d83

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

web/src/pages/HomePage.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import { auth0State, errorsState } from '../state/atoms';
1111
import { protocolsQuery, runsQuery } from '../state/selectors';
1212
import moment from 'moment';
1313
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';
1516

1617
export function HomePage() {
1718
const [runsTimestamp, setRunsTimestamp] = React.useState("");
@@ -49,7 +50,13 @@ export function HomePage() {
4950
history.push(`/protocol/${created.id}`);
5051
}
5152
};
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+
5360
// Create new run
5461
const created = await runUpsert({
5562
status: 'todo',
@@ -64,7 +71,7 @@ export function HomePage() {
6471
});
6572
// Redirect to the new run page editor
6673
history.push(`/run/${created.id}`);
67-
};
74+
});
6875
const refresh = () => {
6976
setRunsTimestamp(moment().format());
7077
setProtocolsTimestamp(moment().format());
@@ -95,7 +102,7 @@ export function HomePage() {
95102
<Dropdown.Menu>
96103
{
97104
protocols && protocols.map(protocol =>
98-
<Dropdown.Item key={protocol.id} onClick={createRun(protocol)}>
105+
<Dropdown.Item key={protocol.id} onClick={() => createRun(protocol)}>
99106
{protocol.name || <i>Untitled Protocol</i>}
100107
</Dropdown.Item>
101108
)

0 commit comments

Comments
 (0)