Skip to content

Commit

Permalink
refactor: parameter object
Browse files Browse the repository at this point in the history
  • Loading branch information
mjhuff committed Oct 9, 2024
1 parent 480dfba commit eae73b5
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 134 deletions.
22 changes: 13 additions & 9 deletions app/src/organisms/WellSelection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export function WellSelection(props: WellSelectionProps): JSX.Element {
const primaryWells: WellGroup = reduce(
selectedWells,
(acc: WellGroup, _, wellName: string): WellGroup => {
const wellSet = getWellSetForMultichannel(
definition,
const wellSet = getWellSetForMultichannel({
labwareDef: definition,
wellName,
channels
)
channels,
})
if (!wellSet) return acc
return { ...acc, [wellSet[0]]: null }
},
Expand All @@ -74,7 +74,11 @@ export function WellSelection(props: WellSelectionProps): JSX.Element {
selectedWells,
(acc: WellGroup, _, wellName: string): WellGroup => {
const wellSetForMulti =
getWellSetForMultichannel(definition, wellName, channels) || []
getWellSetForMultichannel({
labwareDef: definition,
wellName,
channels,
}) || []
const channelWells = arrayToWellGroup(wellSetForMulti)
return {
...acc,
Expand Down Expand Up @@ -102,11 +106,11 @@ export function WellSelection(props: WellSelectionProps): JSX.Element {
? reduce<WellGroup, WellGroup>(
selectedPrimaryWells,
(acc, _, wellName): WellGroup => {
const wellSet = getWellSetForMultichannel(
definition,
const wellSet = getWellSetForMultichannel({
labwareDef: definition,
wellName,
channels
)
channels,
})
if (!wellSet) return acc
return { ...acc, ...arrayToWellGroup(wellSet) }
},
Expand Down
23 changes: 12 additions & 11 deletions protocol-designer/src/components/labware/SelectableLabware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ export const SelectableLabware = (props: Props): JSX.Element => {
const primaryWells: WellGroup = reduce(
selectedWells,
(acc: WellGroup, _, wellName: string): WellGroup => {
const wellSet = getWellSetForMultichannel(
const wellSet = getWellSetForMultichannel({
labwareDef,
wellName,
channels
)
channels,
})
if (!wellSet) return acc
return { ...acc, [wellSet[0]]: null }
},
Expand Down Expand Up @@ -109,7 +109,8 @@ export const SelectableLabware = (props: Props): JSX.Element => {
selectedWells,
(acc: WellGroup, _, wellName: string): WellGroup => {
const wellSetForMulti =
getWellSetForMultichannel(labwareDef, wellName, channels) || []
getWellSetForMultichannel({ labwareDef, wellName, channels }) ||
[]
const channelWells = arrayToWellGroup(wellSetForMulti)
return {
...acc,
Expand Down Expand Up @@ -144,11 +145,11 @@ export const SelectableLabware = (props: Props): JSX.Element => {
const handleMouseEnterWell: (args: WellMouseEvent) => void = args => {
if (nozzleType != null) {
const channels = getChannelsFromNozleType(nozzleType)
const wellSet = getWellSetForMultichannel(
const wellSet = getWellSetForMultichannel({
labwareDef,
args.wellName,
channels
)
wellName: args.wellName,
channels,
})
const nextHighlightedWells = arrayToWellGroup(wellSet || [])
nextHighlightedWells && updateHighlightedWells(nextHighlightedWells)
} else {
Expand All @@ -163,11 +164,11 @@ export const SelectableLabware = (props: Props): JSX.Element => {
selectedPrimaryWells,
(acc, _, wellName): WellGroup => {
const channels = getChannelsFromNozleType(nozzleType)
const wellSet = getWellSetForMultichannel(
const wellSet = getWellSetForMultichannel({
labwareDef,
wellName,
channels
)
channels,
})
if (!wellSet) return acc
return { ...acc, ...arrayToWellGroup(wellSet) }
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ export function getAllWellsFromPrimaryWells(
channels: 8 | 96
): string[] {
const allWells = primaryWells.reduce((acc: string[], well: string) => {
const nextWellSet = getWellSetForMultichannel(labwareDef, well, channels)
const nextWellSet = getWellSetForMultichannel({
labwareDef,
wellName: well,
channels,
})

// filter out any nulls (but you shouldn't get any)
if (!nextWellSet) {
Expand Down
20 changes: 10 additions & 10 deletions protocol-designer/src/top-selectors/substep-highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ function _getSelectedWellsForStep(
wells.push(commandWellName)
} else if (channels === 8 || channels === 96) {
const wellSet =
getWellSetForMultichannel(
invariantContext.labwareEntities[labwareId].def,
commandWellName,
channels
) || []
getWellSetForMultichannel({
labwareDef: invariantContext.labwareEntities[labwareId].def,
wellName: commandWellName,
channels,
}) || []
wells.push(...wellSet)
} else {
console.error(
Expand Down Expand Up @@ -241,11 +241,11 @@ function _getSelectedWellsForSubstep(
activeTips.labwareId === labwareId &&
channels !== 1
) {
const multiTipWellSet = getWellSetForMultichannel(
invariantContext.labwareEntities[labwareId].def,
activeTips.wellName,
channels
)
const multiTipWellSet = getWellSetForMultichannel({
labwareDef: invariantContext.labwareEntities[labwareId].def,
wellName: activeTips.wellName,
channels,
})
if (multiTipWellSet) tipWellSet = multiTipWellSet
}
} else {
Expand Down
160 changes: 76 additions & 84 deletions shared-data/js/helpers/__tests__/wellSets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,92 +226,86 @@ describe('getWellSetForMultichannel (integration test)', () => {
it('96-flat', () => {
const labwareDef = fixture96Plate

expect(getWellSetForMultichannel(labwareDef, 'A1', EIGHT_CHANNEL)).toEqual([
'A1',
'B1',
'C1',
'D1',
'E1',
'F1',
'G1',
'H1',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'A1',
channels: EIGHT_CHANNEL,
})
).toEqual(['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1'])

expect(getWellSetForMultichannel(labwareDef, 'B1', EIGHT_CHANNEL)).toEqual([
'A1',
'B1',
'C1',
'D1',
'E1',
'F1',
'G1',
'H1',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'B1',
channels: EIGHT_CHANNEL,
})
).toEqual(['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1'])

expect(getWellSetForMultichannel(labwareDef, 'H1', EIGHT_CHANNEL)).toEqual([
'A1',
'B1',
'C1',
'D1',
'E1',
'F1',
'G1',
'H1',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'H1',
channels: EIGHT_CHANNEL,
})
).toEqual(['A1', 'B1', 'C1', 'D1', 'E1', 'F1', 'G1', 'H1'])

expect(getWellSetForMultichannel(labwareDef, 'A2', EIGHT_CHANNEL)).toEqual([
'A2',
'B2',
'C2',
'D2',
'E2',
'F2',
'G2',
'H2',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'A2',
channels: EIGHT_CHANNEL,
})
).toEqual(['A2', 'B2', 'C2', 'D2', 'E2', 'F2', 'G2', 'H2'])

// 96-channel
expect(
getWellSetForMultichannel(labwareDef, 'A1', NINETY_SIX_CHANNEL)
getWellSetForMultichannel({
labwareDef,
wellName: 'A1',
channels: NINETY_SIX_CHANNEL,
})
).toEqual(wellsFor96WellPlate)
})

it('invalid well', () => {
const labwareDef = fixture96Plate

expect(
getWellSetForMultichannel(labwareDef, 'A13', EIGHT_CHANNEL)
getWellSetForMultichannel({
labwareDef,
wellName: 'A13',
channels: EIGHT_CHANNEL,
})
).toBeFalsy()
})

it('trough-12row', () => {
const labwareDef = fixture12Trough

expect(getWellSetForMultichannel(labwareDef, 'A1', EIGHT_CHANNEL)).toEqual([
'A1',
'A1',
'A1',
'A1',
'A1',
'A1',
'A1',
'A1',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'A1',
channels: EIGHT_CHANNEL,
})
).toEqual(['A1', 'A1', 'A1', 'A1', 'A1', 'A1', 'A1', 'A1'])

expect(getWellSetForMultichannel(labwareDef, 'A2', EIGHT_CHANNEL)).toEqual([
'A2',
'A2',
'A2',
'A2',
'A2',
'A2',
'A2',
'A2',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'A2',
channels: EIGHT_CHANNEL,
})
).toEqual(['A2', 'A2', 'A2', 'A2', 'A2', 'A2', 'A2', 'A2'])

// 96-channel
expect(
getWellSetForMultichannel(labwareDef, 'A1', NINETY_SIX_CHANNEL)
getWellSetForMultichannel({
labwareDef,
wellName: 'A1',
channels: NINETY_SIX_CHANNEL,
})
).toEqual(wellsForReservoir)
})

Expand All @@ -324,31 +318,29 @@ describe('getWellSetForMultichannel (integration test)', () => {
well96Channel
)

expect(getWellSetForMultichannel(labwareDef, 'C1', EIGHT_CHANNEL)).toEqual([
'A1',
'C1',
'E1',
'G1',
'I1',
'K1',
'M1',
'O1',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'C1',
channels: EIGHT_CHANNEL,
})
).toEqual(['A1', 'C1', 'E1', 'G1', 'I1', 'K1', 'M1', 'O1'])

expect(getWellSetForMultichannel(labwareDef, 'F2', EIGHT_CHANNEL)).toEqual([
'B2',
'D2',
'F2',
'H2',
'J2',
'L2',
'N2',
'P2',
])
expect(
getWellSetForMultichannel({
labwareDef,
wellName: 'F2',
channels: EIGHT_CHANNEL,
})
).toEqual(['B2', 'D2', 'F2', 'H2', 'J2', 'L2', 'N2', 'P2'])

// 96-channel
expect(
getWellSetForMultichannel(labwareDef, well96Channel, NINETY_SIX_CHANNEL)
getWellSetForMultichannel({
labwareDef,
wellName: well96Channel,
channels: NINETY_SIX_CHANNEL,
})
).toEqual(ninetySixChannelWells)
})
})
Expand Down
Loading

0 comments on commit eae73b5

Please sign in to comment.