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

X1234 section planning #769

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
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
36 changes: 29 additions & 7 deletions src/components/planning/LabwarePlan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ type LabwarePlanProps = {
operationType: string;

sampleColors: Map<number, string>;

/** Specified number of labware when setting the plan */
numLabware: number;

/** Specified section thickness when setting the plan */
sectionThickness: number;
/**
* Callback triggered when the delete button is clicked
* @param cid the client ID of the {@link LabwarePlan}
Expand All @@ -66,7 +72,20 @@ type LabwarePlanProps = {
};

const LabwarePlan = React.forwardRef<HTMLDivElement, LabwarePlanProps>(
({ cid, outputLabware, onDeleteButtonClick, onComplete, sampleColors, operationType, sourceLabware }, ref) => {
(
{
cid,
outputLabware,
onDeleteButtonClick,
onComplete,
sampleColors,
operationType,
sourceLabware,
numLabware,
sectionThickness
},
ref
) => {
const labwarePlanMachine = React.useMemo(() => {
return createLabwarePlanMachine(buildInitialLayoutPlan(sourceLabware, sampleColors, outputLabware));
}, [sourceLabware, sampleColors, outputLabware]);
Expand Down Expand Up @@ -120,7 +139,7 @@ const LabwarePlan = React.forwardRef<HTMLDivElement, LabwarePlanProps>(
className="relative p-3 shadow"
>
<Formik<FormValues>
initialValues={buildInitialValues(operationType, outputLabware.labwareType)}
initialValues={buildInitialValues(operationType, outputLabware.labwareType, numLabware, sectionThickness)}
validationSchema={buildValidationSchema(outputLabware.labwareType)}
onSubmit={async (values) => {
const newValues = {
Expand Down Expand Up @@ -336,18 +355,21 @@ type FormValues = {
/**
* The initial values for the labware plan form
*/
function buildInitialValues(operationType: string, labwareType: LabwareTypeFieldsFragment): FormValues {
function buildInitialValues(
operationType: string,
labwareType: LabwareTypeFieldsFragment,
quantity: number,
sectionThickness: number
): FormValues {
let formValues: FormValues = {
operationType,
quantity: 1
quantity,
sectionThickness
};

if (labwareType.name === LabwareTypeName.VISIUM_LP) {
formValues.barcode = '';
}
if (labwareType.name !== LabwareTypeName.FETAL_WASTE_CONTAINER) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this bit about fetal waste removed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sabrine33

Why was this bit about fetal waste removed?

formValues.sectionThickness = 0;
}
if (
labwareType.name === LabwareTypeName.VISIUM_LP ||
labwareType.name === LabwareTypeName.VISIUM_TO ||
Expand Down
44 changes: 35 additions & 9 deletions src/pages/sectioning/Plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function Plan() {

const [selectedLabwareType, setSelectedLabwareType] = React.useState<string>(LabwareTypeName.TUBE);

const [numLabware, setNumLabware] = React.useState<number>(1);

const [sectionThickness, setSectionThickness] = React.useState<number>(1);

const sectioningInfo = useLoaderData() as GetSectioningInfoQuery;
/**
* Limit the labware types the user can Section on to.
Expand Down Expand Up @@ -89,24 +93,46 @@ function Plan() {
sourceLabware={sourceLabware}
onDeleteButtonClick={deleteAction}
onComplete={confirmAction!}
numLabware={numLabware}
sectionThickness={sectionThickness}
/>
))}
</>
);
},
[]
[sectionThickness, numLabware]
);
const buildPlanCreationSettings = React.useCallback(() => {
return (
<CustomReactSelect
className="mt-1 block w-full md:w-1/2"
dataTestId={'labware-type'}
handleChange={(val) => setSelectedLabwareType((val as OptionType).label)}
value={selectedLabwareType}
options={selectOptionValues(allowedLabwareTypes, 'name', 'name')}
/>
<div className="mt-4 grid grid-cols-3 gap-x-2 gap-y-1 text-center">
<div className="text-gray-500">Labware type</div>
<div className="text-gray-500">Number of labware</div>
<div className="text-gray-500">Section Thickness</div>
<CustomReactSelect
dataTestId={'labware-type'}
handleChange={(val) => setSelectedLabwareType((val as OptionType).label)}
value={selectedLabwareType}
options={selectOptionValues(allowedLabwareTypes, 'name', 'name')}
/>
<input
type="number"
className="block h-10 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-sdb-100 focus:border-sdb-100"
onChange={(e) => setNumLabware(Number(e.currentTarget.value))}
value={numLabware}
data-testid={'numLabware'}
min={1}
/>
<input
type="number"
className="block h-10 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-sdb-100 focus:border-sdb-100"
onChange={(e) => setSectionThickness(Number(e.currentTarget.value))}
value={sectionThickness}
data-testid={'sectionThickness'}
min={1}
/>
</div>
);
}, [allowedLabwareTypes, setSelectedLabwareType, selectedLabwareType]);
}, [allowedLabwareTypes, setSelectedLabwareType, selectedLabwareType, setNumLabware, numLabware, sectionThickness]);

return (
<AppShell>
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/components/planning/labwarePlan.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { LabwareType } from '../../../../src/types/sdk';
import { createLabwarePlanMachine } from '../../../../src/components/planning/labwarePlan.machine';
import { createActor } from 'xstate';
import { convertLabwareToFlaggedLabware } from '../../../../src/lib/helpers/labwareHelper';

beforeAll(() => {
enableMapSet();
});
Expand Down Expand Up @@ -246,17 +247,17 @@ describe('Fields validations', () => {
});
});
const expectDisplayNumberOfLabwareAndSectionThicknessInputs = () => {
expect(screen.getByTestId('Number of Labware')).toBeVisible();
expect(screen.getByTestId('Section Thickness')).toBeVisible();
expect(screen.getByTestId('Number of Labware')).toHaveValue(2);
expect(screen.getByTestId('Section Thickness')).toHaveValue(3);
expect(screen.queryByTestId('formInput')).toBeNull();
expect(screen.queryByTestId('slide-costing')).toBeNull();
};

const expectDisplayNumberOfLabwareSectionThicknessLotNumberAndSlideCosting = () => {
expect(screen.getByTestId('formInput')).toBeVisible();
expect(screen.getByTestId('Number of Labware')).toBeVisible();
expect(screen.getByTestId('Number of Labware')).toHaveValue(2);
expect(screen.getByTestId('Barcode')).toBeVisible();
expect(screen.getByTestId('Section Thickness')).toBeVisible();
expect(screen.getByTestId('Section Thickness')).toHaveValue(3);
};

const renderLabwarePlan = (outputLabwareType: string) => {
Expand All @@ -271,6 +272,8 @@ const renderLabwarePlan = (outputLabwareType: string) => {
sourceLabware={[buildFlaggedLabware(LabwareTypeName.TUBE)]}
onDeleteButtonClick={jest.fn()}
onComplete={jest.fn()}
numLabware={2}
sectionThickness={3}
/>
</div>
);
Expand Down
Loading