Skip to content

Commit

Permalink
Merge pull request #801 from sanger/x1247-sample-bioRisk
Browse files Browse the repository at this point in the history
X1247 sample bio risk
  • Loading branch information
sabrine33 authored Nov 20, 2024
2 parents 08eea58 + eac8fc6 commit 7037f2d
Show file tree
Hide file tree
Showing 9 changed files with 1,452 additions and 1,456 deletions.
4 changes: 0 additions & 4 deletions cypress/e2e/pages/blockRegistration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ describe('Block Registration Page', () => {
cy.findByLabelText('Labware Type').focus().blur();
cy.findByText('Labware Type is a required field').should('be.visible');
});
it('requires Biological Risk Assessment Numbers ', () => {
cy.findByLabelText('Biological Risk Assessment Numbers').focus().blur();
cy.findByText('Biological Risk Assessment Numbers is a required field').should('be.visible');
});
});

describe('submission', () => {
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/pages/originalSampleRegistration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ function fillInForm() {
cy.findByTestId('External Identifier').type('EXT_ID_1');
selectOption('HuMFre', 'HuMFre1');
selectOption('Tissue Type', 'Liver');
selectOption('bioRiskCode', 'bioRisk1');
selectOption('Spatial Location', '3 - Surface central region');
cy.findByTestId('Replicate Number').type('2');
selectOption('Labware Type', 'Pot');
Expand Down
5 changes: 5 additions & 0 deletions cypress/e2e/shared/registration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export function shouldBehaveLikeARegistrationForm(registrationType: Registration
}
);

it('requires Biological Risk Assessment Numbers ', () => {
cy.findByLabelText('Biological Risk Assessment Numbers').focus().blur();
cy.findByText('Biological Risk Assessment Numbers is a required field').should('be.visible');
});

it('requires Replicate Number to be suitable', () => {
cy.findByTestId('Replicate Number').type('1+1').blur();
checkReplicateWarningIsVisible();
Expand Down
1 change: 0 additions & 1 deletion src/pages/BlockRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ function BlockRegistration() {
successDisplayTableColumns={resultColumns}
formatSuccessData={(registrationResult) => registrationResult.labware}
isBlock={true}
withBioRiskOption={true}
/>
);

Expand Down
2 changes: 2 additions & 0 deletions src/pages/OriginalSampleRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ function buildRegistrationSchema(registrationInfo: GetRegistrationInfoQuery) {
species: validation.species,
hmdmc: validation.hmdmc,
tissueType: validation.tissueType,
bioRiskCode: validation.bioRiskCode,
sampleCollectionDate: validation.sampleCollectionDate,
blocks: Yup.array()
.min(1)
Expand Down Expand Up @@ -164,6 +165,7 @@ function OriginalSampleRegistration() {
labwareType: block.labwareType.trim(),
lifeStage: Object.values(LifeStage).includes(tissue.lifeStage) ? tissue.lifeStage : undefined,
tissueType: tissue.tissueType.trim(),
bioRiskCode: tissue.bioRiskCode,
spatialLocation: block.spatialLocation,
replicateNumber: block.replicateNumber ?? undefined,
fixative: block.fixative.trim(),
Expand Down
13 changes: 6 additions & 7 deletions src/pages/registration/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { motion } from 'framer-motion';
import variants from '../../lib/motionVariants';
import Heading from '../../components/Heading';
import WorkNumberSelect from '../../components/WorkNumberSelect';
import { FormikErrorMessage } from '../../components/forms';
import PromptOnLeave from '../../components/notifications/PromptOnLeave';
import { FormikErrorMessage } from '../../components/forms';

/**
* Expect form input interface
Expand Down Expand Up @@ -85,8 +85,6 @@ interface RegistrationParams<M, T, R extends Object> {
*/
keywordsMap?: Map<TextType, string>;
isBlock?: boolean;

withBioRiskOption?: boolean;
}

/**
Expand All @@ -107,8 +105,7 @@ function Registration<M, T extends TissueValues<B>, B, R extends Required<Labwar
formatSuccessData,
defaultFormTissueValues,
keywordsMap,
isBlock = false,
withBioRiskOption = false
isBlock = false
}: RegistrationParams<M, T, R>) {
const registrationMachine = React.useMemo(() => {
return createRegistrationMachine<FormInput<T>, M>(buildRegistrationInput, registrationService);
Expand Down Expand Up @@ -190,12 +187,15 @@ function Registration<M, T extends TissueValues<B>, B, R extends Required<Labwar
'tissues',
values.tissues.map((tissue) => ({ ...tissue, workNumber }))
);
if ('workNumber' in defaultFormTissueValues) {
defaultFormTissueValues.workNumber = workNumber;
}
}}
workNumber={values.workNumbers}
multiple={isBlock}
emptyOption={false}
/>
{values.workNumbers.length <= 0 && <FormikErrorMessage name={'workNumbers'} />}
{isBlock && values.workNumbers.length <= 0 && <FormikErrorMessage name={'workNumbers'} />}
</motion.div>
</motion.div>

Expand All @@ -204,7 +204,6 @@ function Registration<M, T extends TissueValues<B>, B, R extends Required<Labwar
availableLabwareTypes={availableLabwareTypes}
defaultFormTissueValues={defaultFormTissueValues}
keywordsMap={keywordsMap}
withBioRiskOption={withBioRiskOption}
/>

{current.matches('clashed') && registrationResult && (
Expand Down
28 changes: 10 additions & 18 deletions src/pages/registration/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,13 @@ interface RegistrationFormParams<T> {
* Change in default keywords to display
*/
keywordsMap?: Map<TextType, string>;

/**
* boolean bio Risk Code option until we add the feature for rhe Original Sample Registration
* **/
withBioRiskOption?: boolean;
}

const RegistrationForm = <T extends TissueValues<B>, B>({
registrationInfo,
availableLabwareTypes,
defaultFormTissueValues,
keywordsMap,
withBioRiskOption = false
keywordsMap
}: RegistrationFormParams<T>) => {
const [currentIndex, setCurrentIndex] = useState(0);
const { setFieldValue, values, errors, touched, isSubmitting } = useFormikContext<RegistrationFormValues>();
Expand Down Expand Up @@ -156,17 +150,15 @@ const RegistrationForm = <T extends TissueValues<B>, B>({
options={selectOptionValues(registrationInfo.tissueTypes, 'name', 'name')}
value={values.tissues[currentIndex].tissueType}
/>
{withBioRiskOption && (
<CustomReactSelect
label="Biological Risk Assessment Numbers"
emptyOption
name={`tissues.${currentIndex}.bioRiskCode`}
className="mt-2"
dataTestId="bioRiskCode"
options={selectOptionValues(registrationInfo.bioRisks, 'code', 'code')}
value={values.tissues[currentIndex].bioRiskCode}
/>
)}
<CustomReactSelect
label="Biological Risk Assessment Numbers"
emptyOption
name={`tissues.${currentIndex}.bioRiskCode`}
className="mt-2"
dataTestId="bioRiskCode"
options={selectOptionValues(registrationInfo.bioRisks, 'code', 'code')}
value={values.tissues[currentIndex].bioRiskCode}
/>
</motion.div>

<motion.div variants={variants.fadeInWithLift} className="space-y-4">
Expand Down
Loading

0 comments on commit 7037f2d

Please sign in to comment.