Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrine33 committed Nov 6, 2024
1 parent a283d53 commit 164906e
Show file tree
Hide file tree
Showing 20 changed files with 1,710 additions and 1,485 deletions.
27 changes: 0 additions & 27 deletions src/components/forms/FormikFieldValue.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions src/graphql/fragments/BioRiskFields.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fragment BioRiskFields on BioRisk {
code
enabled
}
5 changes: 5 additions & 0 deletions src/graphql/mutations/AddBioRisk.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation AddBioRisk($code: String!) {
addBioRisk(code: $code) {
...BioRiskFields
}
}
5 changes: 5 additions & 0 deletions src/graphql/mutations/SetBioRiskEnabled.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mutation SetBioRiskEnabled($code: String!, $enabled: Boolean!) {
setBioRiskEnabled(code: $code, enabled: $enabled) {
...BioRiskFields
}
}
5 changes: 5 additions & 0 deletions src/graphql/queries/GetBioRisks.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
query GetBioRisks($includeDisabled: Boolean) {
bioRisks(includeDisabled: $includeDisabled) {
...BioRiskFields
}
}
3 changes: 3 additions & 0 deletions src/graphql/queries/GetConfiguration.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@ query GetConfiguration {
dnapStudies(includeDisabled: true) {
...DnapStudyFields
}
bioRisks(includeDisabled: true){
...BioRiskFields
}
}
3 changes: 3 additions & 0 deletions src/graphql/queries/GetRegistrationInfo.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ query GetRegistrationInfo {
slotRegions {
name
}
bioRisks {
code
}
}
9 changes: 9 additions & 0 deletions src/lib/factories/bioRiskFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Factory } from 'fishery';
import { BioRisk } from '../../types/sdk';
import { faker } from '@faker-js/faker';

export default Factory.define<BioRisk>(({ params, sequence }) => ({
__typename: 'BioRisk',
code: faker.lorem.word() + sequence,
enabled: params.enabled ?? true
}));
4 changes: 3 additions & 1 deletion src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import segmentationHandlers from './handlers/segmentationHandlers';
import cleanOutHandlers from './handlers/cleanOutHandlers';
import regionOfInterestHandlers from './handlers/regionOfInterestHandlers';
import omeroProjectHandlers from './handlers/omeroProjectHandlers';
import bioRiskHandler from './handlers/bioRiskHandler';

export const handlers = [
...labwareHandlers,
Expand Down Expand Up @@ -123,5 +124,6 @@ export const handlers = [
...cleanOutHandlers,
...regionOfInterestHandlers,
...projectHandlers,
...omeroProjectHandlers
...omeroProjectHandlers,
...bioRiskHandler
];
53 changes: 53 additions & 0 deletions src/mocks/handlers/bioRiskHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { graphql, HttpResponse } from 'msw';
import {
AddBioRiskMutation,
AddBioRiskMutationVariables,
GetBioRisksQuery,
GetBioRisksQueryVariables,
SetBioRiskEnabledMutation,
SetBioRiskEnabledMutationVariables
} from '../../types/sdk';
import { isEnabled } from '../../lib/helpers';
import BioRiskRepository from '../repositories/bioRiskRepository';
import bioRiskRepository from '../repositories/bioRiskRepository';
import bioRiskFactory from '../../lib/factories/bioRiskFactory';

const bioRiskHandler = [
graphql.mutation<AddBioRiskMutation, AddBioRiskMutationVariables>('AddBioRisk', ({ variables }) => {
const bioRisk = bioRiskFactory.build({
code: variables.code
});
bioRiskRepository.save(bioRisk);
return HttpResponse.json({ data: { addBioRisk: bioRisk } }, { status: 200 });
}),

graphql.mutation<SetBioRiskEnabledMutation, SetBioRiskEnabledMutationVariables>(
'SetBioRiskEnabled',
({ variables }) => {
const comment = bioRiskRepository.find('code', variables.code);
if (comment) {
comment.enabled = variables.enabled;
bioRiskRepository.save(comment);
return HttpResponse.json({ data: { setBioRiskEnabled: comment } }, { status: 200 });
} else {
return HttpResponse.json(
{ errors: [{ message: `Could not find comment: "${variables.code}"` }] },
{ status: 404 }
);
}
}
),

graphql.query<GetBioRisksQuery, GetBioRisksQueryVariables>('GetBioRisks', ({ variables }) => {
return HttpResponse.json(
{
data: {
bioRisks: BioRiskRepository.findAll().filter((bioRisk) => variables.includeDisabled || isEnabled(bioRisk))
}
},
{ status: 200 }
);
})
];

export default bioRiskHandler;
4 changes: 3 additions & 1 deletion src/mocks/handlers/configurationHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import programRepository from '../repositories/programRepository';
import omeroProjectRepository from '../repositories/omeroProjectRepository';
import dnapStudyRepository from '../repositories/dnapStudyRepository';
import probePanelRepository from '../repositories/probePanelRepository';
import bioRiskRepository from '../repositories/bioRiskRepository';

const configurationHandlers = [
graphql.query<GetConfigurationQuery, GetConfigurationQueryVariables>('GetConfiguration', () => {
Expand All @@ -38,7 +39,8 @@ const configurationHandlers = [
programs: programRepository.findAll(),
omeroProjects: omeroProjectRepository.findAll(),
dnapStudies: dnapStudyRepository.findAll(),
probePanels: probePanelRepository.findAll()
probePanels: probePanelRepository.findAll(),
bioRisks: bioRiskRepository.findAll()
}
});
})
Expand Down
4 changes: 3 additions & 1 deletion src/mocks/handlers/registrationHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import speciesRepository from '../repositories/speciesRepository';
import hmdmcRepository from '../repositories/hmdmcRepository';
import solutionRepository from '../repositories/solutionRepository';
import slotRegionRepository from '../repositories/slotRegionRepository';
import bioRiskRepository from '../repositories/bioRiskRepository';

const registrationHandlers = [
graphql.query<GetRegistrationInfoQuery, GetRegistrationInfoQueryVariables>('GetRegistrationInfo', ({ variables }) => {
Expand Down Expand Up @@ -108,7 +109,8 @@ const registrationHandlers = [
fixatives: [{ name: 'None' }, { name: 'Formalin' }],
mediums: [{ name: 'OCT' }, { name: 'Paraffin' }, { name: 'None' }],
solutions: solutionRepository.findAll().filter((sample) => sample.enabled),
slotRegions: slotRegionRepository.findAll().filter((region) => region.enabled)
slotRegions: slotRegionRepository.findAll().filter((region) => region.enabled),
bioRisks: bioRiskRepository.findAll().filter((bioRisk) => bioRisk.enabled)
}
},
{ status: 200 }
Expand Down
6 changes: 3 additions & 3 deletions src/mocks/handlers/userHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const userHandlers = [
user: {
__typename: 'User',
username,
role: UserRole.Normal
role: UserRole.Admin
}
}
}
Expand All @@ -53,7 +53,7 @@ const userHandlers = [
user: {
__typename: 'User',
username: 'jb1',
role: UserRole.Normal
role: UserRole.Admin
}
}
});
Expand All @@ -63,7 +63,7 @@ const userHandlers = [
user: {
__typename: 'User',
username: currentUser,
role: UserRole.Normal
role: UserRole.Admin
}
}
});
Expand Down
11 changes: 11 additions & 0 deletions src/mocks/repositories/bioRiskRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BioRisk } from '../../types/sdk';
import { createSessionStorageRepository } from './index';
import bioRiskFactory from '../../lib/factories/bioRiskFactory';

const seeds: Array<BioRisk> = bioRiskFactory.buildList(5);
seeds.push(bioRiskFactory.build({ enabled: false }));
seeds.push(bioRiskFactory.build({ code: 'bioRisk1' }));

const bioRiskRepository = createSessionStorageRepository('BIORISKS', 'code', seeds);

export default bioRiskRepository;
7 changes: 5 additions & 2 deletions src/pages/BlockRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export interface RegistrationFormTissue {
sampleCollectionDate?: Date | string;
blocks: RegistrationFormBlock[];
workNumber: string;
bioRiskCode: string;
}

export interface RegistrationFormValues {
Expand Down Expand Up @@ -80,7 +81,8 @@ export function getRegistrationFormTissue(): RegistrationFormTissue {
tissueType: '',
blocks: [getRegistrationFormBlock()],
sampleCollectionDate: '',
workNumber: ''
workNumber: '',
bioRiskCode: ''
};
}

Expand Down Expand Up @@ -149,7 +151,8 @@ export function buildRegisterTissuesMutationVariables(
? tissue.sampleCollectionDate instanceof Date
? tissue.sampleCollectionDate.toLocaleDateString()
: tissue.sampleCollectionDate
: undefined
: undefined,
bioRiskCode: tissue.bioRiskCode
};

if (!ignoreExistingTissues && existingTissues.includes(blockRegisterRequest.externalIdentifier)) {
Expand Down
24 changes: 24 additions & 0 deletions src/pages/Configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default function Configuration() {

//Listed in alphabetical order
const configElements = [
'Biological Risk Assessment Numbers',
'Comments',
'Cost Codes',
'Destruction Reasons',
Expand Down Expand Up @@ -58,6 +59,29 @@ export default function Configuration() {
//Fill in the Config panels in same order as config Elements
const configPanels = React.useMemo(() => {
return [
/**BioRisk Codes**/
<div data-testid="config">
<Heading level={2}>Biological Risk Assessment Numbers</Heading>
<p className="mt-3 mb-6 text-lg" />
<EntityManager
initialEntities={configuration.bioRisks}
displayKeyColumnName={'code'}
valueColumnName={'enabled'}
onChangeValue={(entity, value) => {
const enabled = typeof value === 'boolean' ? value : false;
return stanCore
.SetBioRiskEnabled({
enabled,
code: entity.code
})
.then((res) => res.setBioRiskEnabled);
}}
valueFieldComponentInfo={{
type: 'CHECKBOX'
}}
onCreate={(code) => stanCore.AddBioRisk({ code }).then((res) => res.addBioRisk)}
/>
</div>,
/**Comments**/
<div className="space-y-8">
{Object.keys(groupedComments)
Expand Down
3 changes: 2 additions & 1 deletion src/pages/OriginalSampleRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export function getRegistrationFormTissueSample(): RegistrationFormOriginalSampl
tissueType: '',
blocks: [getRegistrationFormSample()],
sampleCollectionDate: '',
workNumber: ''
workNumber: '',
bioRiskCode: ''
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/ProbeHybridisationXenium.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const ProbeHybridisationXenium: React.FC = () => {
<FormikInput
label={'Sample Prep Reagent Lot'}
name={'samplePrepReagentLot'}
onChange={async (e: React.ChangeEvent<HTMLSelectElement>) => {
onChange={async (e: React.ChangeEvent<HTMLInputElement>) => {
await setValues((prev) => ({
...prev,
samplePrepReagentLot: e.target.value,
Expand Down
9 changes: 9 additions & 0 deletions src/pages/registration/RegistrationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ const RegistrationForm = <T extends TissueValues<B>, B>({
options={selectOptionValues(registrationInfo.tissueTypes, 'name', 'name')}
value={values.tissues[currentIndex].tissueType}
/>
<CustomReactSelect
label="Biological Risk Assessment Numbers"
emptyOption
name={`tissues.${currentIndex}.bioRiskCode`}
className="mt-2"
dataTestId="bioRisks"
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 164906e

Please sign in to comment.