Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add store func. on the cell segmentation page #889

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 42 additions & 21 deletions src/pages/CellSegmentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@ import AppShell from '../components/AppShell';
import { Form, Formik } from 'formik';
import {
CommentFieldsFragment,
LabwareFieldsFragment,
LabwareFlaggedFieldsFragment,
SegmentationLabware,
SegmentationMutation,
SegmentationRequest,
SlideCosting
} from '../types/sdk';
import { formatDateTimeForCore, getCurrentDateTime } from '../types/stan';
import { createSessionStorageForLabwareAwaiting, formatDateTimeForCore, getCurrentDateTime } from '../types/stan';
import React, { useContext } from 'react';
import BlueButton from '../components/buttons/BlueButton';
import { useLoaderData } from 'react-router-dom';
import { useLoaderData, useNavigate } from 'react-router-dom';
import * as Yup from 'yup';
import OperationCompleteModal from '../components/modal/OperationCompleteModal';
import { StanCoreContext } from '../lib/sdk';
Expand All @@ -20,6 +21,7 @@ import { fromPromise } from 'xstate';
import { useMachine } from '@xstate/react';
import Warning from '../components/notifications/Warning';
import { Segmentation } from '../components/CellSegmentation/CellSegmentation';
import WhiteButton from '../components/buttons/WhiteButton';

type CellSegmentationProps = {
labware: LabwareFlaggedFieldsFragment;
Expand Down Expand Up @@ -80,6 +82,7 @@ const toSegmentationRequest = (values: CellSegmentationFormProps): SegmentationR

export const CellSegmentation = ({ initialFormValues = defaultFormValues }) => {
const comments = useLoaderData() as CommentFieldsFragment[];
const navigate = useNavigate();
const stanCore = useContext(StanCoreContext);
const formMachine = React.useMemo(() => {
return createFormMachine<SegmentationRequest, SegmentationMutation>().provide({
Expand Down Expand Up @@ -114,28 +117,46 @@ export const CellSegmentation = ({ initialFormValues = defaultFormValues }) => {
validateOnMount={true}
>
{({ isValid, values }) => (
<Form>
<Segmentation comments={comments} isQc={false} />
{values.cellSegmentation.length > 0 && (
<div className={'sm:flex mt-4 sm:flex-row justify-end'}>
<BlueButton type="submit" disabled={!isValid}>
Save
</BlueButton>
</div>
)}
</Form>
<>
<Form>
<Segmentation comments={comments} isQc={false} />
{values.cellSegmentation.length > 0 && (
<div className={'sm:flex mt-4 sm:flex-row justify-end'}>
<BlueButton type="submit" disabled={!isValid}>
Save
</BlueButton>
</div>
)}
</Form>

<OperationCompleteModal
show={submissionResult !== undefined}
message={'Cell Segmentation recorded on all labware'}
additionalButtons={
<WhiteButton
type="button"
style={{ marginLeft: 'auto' }}
className="w-full text-base md:ml-0 sm:ml-3 sm:w-auto sm:text:sm"
onClick={() => {
createSessionStorageForLabwareAwaiting(
values.cellSegmentation.map((cellSeg) => cellSeg.labware as LabwareFieldsFragment)
);
navigate('/store');
}}
>
Store
</WhiteButton>
}
>
<p>
If you wish to start the process again, click the "Reset Form" button. Otherwise you can return to
the Home screen.
</p>
</OperationCompleteModal>
</>
)}
</Formik>
</div>
<OperationCompleteModal
show={submissionResult !== undefined}
message={'Cell Segmentation recorded on all labware'}
>
<p>
If you wish to start the process again, click the "Reset Form" button. Otherwise you can return to the
Home screen.
</p>
</OperationCompleteModal>
</div>
</AppShell.Main>
</AppShell>
Expand Down
Loading