From 4b842ffa483371af6b6f1607dd8432fb8dddfb4f Mon Sep 17 00:00:00 2001 From: CaseyBatten Date: Wed, 10 Apr 2024 16:56:56 -0400 Subject: [PATCH] lint corrections for app hardware and shared data --- .../DeviceDetailsDeckConfiguration/index.tsx | 45 ++++--- .../ChooseModuleToConfigureModal.tsx | 68 +++++++---- .../LocationConflictModal.tsx | 14 ++- .../OT2MultipleModulesHelp.tsx | 110 +++++++++--------- app/src/pages/Protocols/hooks/index.ts | 62 ++++++---- .../DeckConfigurator/MagneticBlockFixture.tsx | 10 +- .../hardware-sim/DeckConfigurator/index.tsx | 17 ++- shared-data/js/constants.ts | 9 +- shared-data/js/fixtures.ts | 38 +++--- 9 files changed, 217 insertions(+), 156 deletions(-) diff --git a/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx b/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx index f13533a2aad..97194aa90d7 100644 --- a/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx +++ b/app/src/organisms/DeviceDetailsDeckConfiguration/index.tsx @@ -53,7 +53,6 @@ interface DeviceDetailsDeckConfigurationProps { robotName: string } - function getDisplayLocationForCutoutIds(cutouts: CutoutId[]): string { return cutouts.map(cutoutId => getCutoutDisplayName(cutoutId)).join(' + ') } @@ -109,28 +108,32 @@ export function DeviceDetailsDeckConfiguration({ let newDeckConfig = deckConfig if (cutoutId in fixtureGroup) { - const groupMap = fixtureGroup[cutoutId]?.find(group => ( - Object.entries(group).every(([cId, cfId]) => ( - deckConfig.find(config => config.cutoutId === cId && config.cutoutFixtureId === cfId) - )) - )) ?? {} - newDeckConfig = deckConfig.map(cutoutConfig => ( + const groupMap = + fixtureGroup[cutoutId]?.find(group => + Object.entries(group).every(([cId, cfId]) => + deckConfig.find( + config => + config.cutoutId === cId && config.cutoutFixtureId === cfId + ) + ) + ) ?? {} + newDeckConfig = deckConfig.map(cutoutConfig => cutoutConfig.cutoutId in groupMap ? { - ...cutoutConfig, - cutoutFixtureId: replacementFixtureId, - opentronsModuleSerialNumber: undefined, - } + ...cutoutConfig, + cutoutFixtureId: replacementFixtureId, + opentronsModuleSerialNumber: undefined, + } : cutoutConfig - )) + ) } else { newDeckConfig = deckConfig.map(cutoutConfig => cutoutConfig.cutoutId === cutoutId ? { - ...cutoutConfig, - cutoutFixtureId: replacementFixtureId, - opentronsModuleSerialNumber: undefined, - } + ...cutoutConfig, + cutoutFixtureId: replacementFixtureId, + opentronsModuleSerialNumber: undefined, + } : cutoutConfig ) } @@ -159,7 +162,15 @@ export function DeviceDetailsDeckConfiguration({ deckDef.cutoutFixtures.find(cf => cf.id === cutoutFixtureId) ?.fixtureGroup ?? {} if (cutoutId in fixtureGroup) { - const groupMap = fixtureGroup[cutoutId]?.find(group => Object.entries(group).every(([cId, cfId]) => (deckConfig.find(config => config.cutoutId === cId && config.cutoutFixtureId === cfId)))) ?? {} + const groupMap = + fixtureGroup[cutoutId]?.find(group => + Object.entries(group).every(([cId, cfId]) => + deckConfig.find( + config => + config.cutoutId === cId && config.cutoutFixtureId === cfId + ) + ) + ) ?? {} const groupedCutoutIds = Object.keys(groupMap) as CutoutId[] const displayLocation = getDisplayLocationForCutoutIds(groupedCutoutIds) if (acc.groupedCutoutIds.includes(cutoutId)) { diff --git a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/ChooseModuleToConfigureModal.tsx b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/ChooseModuleToConfigureModal.tsx index 4921b3a7455..3eb9611dc86 100644 --- a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/ChooseModuleToConfigureModal.tsx +++ b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/ChooseModuleToConfigureModal.tsx @@ -64,18 +64,28 @@ export const ChooseModuleToConfigureModal = ( paddingTop={SPACING.spacing8} gridGap={SPACING.spacing8} > - {attachedModules.filter(m => m.moduleModel === requiredModuleModel).map(attachedModule => { - const moduleFixtures = getCutoutFixturesForModuleModel(attachedModule.moduleModel, deckDef) - return ( - handleConfigureModule(attachedModule.serialNumber)} - optionName={getFixtureDisplayName(moduleFixtures[0].id, attachedModule.usbPort.port)} - buttonText={t('shared:add')} - isOnDevice={isOnDevice} - /> - ) - })} + {attachedModules + .filter(m => m.moduleModel === requiredModuleModel) + .map(attachedModule => { + const moduleFixtures = getCutoutFixturesForModuleModel( + attachedModule.moduleModel, + deckDef + ) + return ( + + handleConfigureModule(attachedModule.serialNumber) + } + optionName={getFixtureDisplayName( + moduleFixtures[0].id, + attachedModule.usbPort.port + )} + buttonText={t('shared:add')} + isOnDevice={isOnDevice} + /> + ) + })} @@ -104,18 +114,28 @@ export const ChooseModuleToConfigureModal = ( paddingTop={SPACING.spacing8} gridGap={SPACING.spacing8} > - {attachedModules.filter(m => m.moduleModel === requiredModuleModel).map(attachedModule => { - const moduleFixtures = getCutoutFixturesForModuleModel(attachedModule.moduleModel, deckDef) - return ( - handleConfigureModule(attachedModule.serialNumber)} - optionName={getFixtureDisplayName(moduleFixtures[0].id, attachedModule.usbPort.port)} - buttonText={t('shared:add')} - isOnDevice={isOnDevice} - /> - ) - })} + {attachedModules + .filter(m => m.moduleModel === requiredModuleModel) + .map(attachedModule => { + const moduleFixtures = getCutoutFixturesForModuleModel( + attachedModule.moduleModel, + deckDef + ) + return ( + + handleConfigureModule(attachedModule.serialNumber) + } + optionName={getFixtureDisplayName( + moduleFixtures[0].id, + attachedModule.usbPort.port + )} + buttonText={t('shared:add')} + isOnDevice={isOnDevice} + /> + ) + })} diff --git a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx index fa256f5e3e9..b1e9858527c 100644 --- a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx +++ b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/LocationConflictModal.tsx @@ -117,10 +117,10 @@ export const LocationConflictModal = ( ) return cutoutId === fixture.cutoutId && replacementFixture != null ? { - ...fixture, - cutoutFixtureId: replacementFixture?.id, - opentronsModuleSerialNumber: moduleSerialNumber - } + ...fixture, + cutoutFixtureId: replacementFixture?.id, + opentronsModuleSerialNumber: moduleSerialNumber, + } : fixture }) updateDeckConfiguration(newDeckConfig) @@ -134,7 +134,11 @@ export const LocationConflictModal = ( } else if (requiredFixtureId != null) { const newRequiredFixtureDeckConfig = deckConfig.map(fixture => fixture.cutoutId === cutoutId - ? { ...fixture, cutoutFixtureId: requiredFixtureId, opentronsModuleSerialNumber: undefined } + ? { + ...fixture, + cutoutFixtureId: requiredFixtureId, + opentronsModuleSerialNumber: undefined, + } : fixture ) updateDeckConfiguration(newRequiredFixtureDeckConfig) diff --git a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/OT2MultipleModulesHelp.tsx b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/OT2MultipleModulesHelp.tsx index c1375ecf422..eaac0c079a6 100644 --- a/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/OT2MultipleModulesHelp.tsx +++ b/app/src/organisms/Devices/ProtocolRun/SetupModuleAndDeck/OT2MultipleModulesHelp.tsx @@ -29,7 +29,9 @@ export function OT2MultipleModulesHelp(): JSX.Element { setShowMultipleModulesModal, ] = React.useState(false) - const onCloseClick = (): void => { setShowMultipleModulesModal(false) } + const onCloseClick = (): void => { + setShowMultipleModulesModal(false) + } return ( <> @@ -59,62 +61,62 @@ export function OT2MultipleModulesHelp(): JSX.Element { {showMultipleModulesModal ? createPortal( - - - - - - {t('multiple_modules_explanation')} - - - {t('multiple_modules_learn_more')} - - - - {t('example')} - + + + + + + {t('multiple_modules_explanation')} + + + {t('multiple_modules_learn_more')} + + + + {t('example')} + - - {t('multiple_modules_example')} - + + {t('multiple_modules_example')} + + + 2 temperature modules plugged into the usb ports - 2 temperature modules plugged into the usb ports + + {t('shared:close')} + - - {t('shared:close')} - - - , - getTopPortalEl() - ) + , + getTopPortalEl() + ) : null} ) diff --git a/app/src/pages/Protocols/hooks/index.ts b/app/src/pages/Protocols/hooks/index.ts index 31511195536..a2c5b8df957 100644 --- a/app/src/pages/Protocols/hooks/index.ts +++ b/app/src/pages/Protocols/hooks/index.ts @@ -97,26 +97,37 @@ export const useRequiredProtocolHardwareFromAnalysis = ( const requiredGripper: ProtocolGripper[] = getProtocolUsesGripper(analysis) ? [ - { - hardwareType: 'gripper', - connected: - attachedInstruments.some(i => i.instrumentType === 'gripper') ?? - false, - }, - ] + { + hardwareType: 'gripper', + connected: + attachedInstruments.some(i => i.instrumentType === 'gripper') ?? + false, + }, + ] : [] const requiredModules: ProtocolModule[] = analysis.modules.map( ({ location, model }) => { - const cutoutIdForSlotName = getCutoutIdForSlotName(location.slotName, deckDef) + const cutoutIdForSlotName = getCutoutIdForSlotName( + location.slotName, + deckDef + ) const moduleFixtures = getCutoutFixturesForModuleModel(model, deckDef) - const configuredModuleSerialNumber = deckConfig.find(({ cutoutId, cutoutFixtureId }) => ( - cutoutId === cutoutIdForSlotName - && moduleFixtures.map(mf => mf.id).includes(cutoutFixtureId) - ))?.opentronsModuleSerialNumber ?? null - const isConnected = moduleFixtures.every(mf => mf.expectOpentronsModuleSerialNumber) - ? attachedModules.some(m => m.moduleModel === model && m.serialNumber === configuredModuleSerialNumber) + const configuredModuleSerialNumber = + deckConfig.find( + ({ cutoutId, cutoutFixtureId }) => + cutoutId === cutoutIdForSlotName && + moduleFixtures.map(mf => mf.id).includes(cutoutFixtureId) + )?.opentronsModuleSerialNumber ?? null + const isConnected = moduleFixtures.every( + mf => mf.expectOpentronsModuleSerialNumber + ) + ? attachedModules.some( + m => + m.moduleModel === model && + m.serialNumber === configuredModuleSerialNumber + ) : true return { hardwareType: 'module', @@ -162,17 +173,20 @@ export const useRequiredProtocolHardwareFromAnalysis = ( const requiredFixtures = requiredDeckConfigCompatibility // filter out all module fixtures as they're handled in the requiredModules section via hardwareType === 'module' - .filter(({ requiredAddressableAreas }) => !FLEX_MODULE_ADDRESSABLE_AREAS.some(modAA => requiredAddressableAreas.includes(modAA))) - .map( - ({ cutoutFixtureId, cutoutId, compatibleCutoutFixtureIds }) => ({ - hardwareType: 'fixture' as const, - cutoutFixtureId: compatibleCutoutFixtureIds[0], - location: { cutout: cutoutId }, - hasSlotConflict: - cutoutFixtureId != null && - !compatibleCutoutFixtureIds.includes(cutoutFixtureId), - }) + .filter( + ({ requiredAddressableAreas }) => + !FLEX_MODULE_ADDRESSABLE_AREAS.some(modAA => + requiredAddressableAreas.includes(modAA) + ) ) + .map(({ cutoutFixtureId, cutoutId, compatibleCutoutFixtureIds }) => ({ + hardwareType: 'fixture' as const, + cutoutFixtureId: compatibleCutoutFixtureIds[0], + location: { cutout: cutoutId }, + hasSlotConflict: + cutoutFixtureId != null && + !compatibleCutoutFixtureIds.includes(cutoutFixtureId), + })) return { requiredProtocolHardware: [ diff --git a/components/src/hardware-sim/DeckConfigurator/MagneticBlockFixture.tsx b/components/src/hardware-sim/DeckConfigurator/MagneticBlockFixture.tsx index ac01c7b1a41..a9f1485c2bd 100644 --- a/components/src/hardware-sim/DeckConfigurator/MagneticBlockFixture.tsx +++ b/components/src/hardware-sim/DeckConfigurator/MagneticBlockFixture.tsx @@ -47,7 +47,7 @@ export function MagneticBlockFixture( fixtureLocation, handleClickRemove, cutoutFixtureId, - hasStagingArea + hasStagingArea, } = props const standardSlotCutout = deckDefinition.locations.cutouts.find( @@ -63,7 +63,9 @@ export function MagneticBlockFixture( standardSlotCutout?.position ?? [] let x = xSlotPosition let width = 0 - let displayName = hasStagingArea ? STAGING_AREA_WITH_MAGNETIC_BLOCK_DISPLAY_NAME : MAGNETIC_BLOCK_FIXTURE_DISPLAY_NAME + let displayName = hasStagingArea + ? STAGING_AREA_WITH_MAGNETIC_BLOCK_DISPLAY_NAME + : MAGNETIC_BLOCK_FIXTURE_DISPLAY_NAME switch (fixtureLocation) { case 'cutoutA1': case 'cutoutB1': @@ -79,7 +81,7 @@ export function MagneticBlockFixture( case 'cutoutD2': { x = xSlotPosition + COLUMN_2_X_ADJUSTMENT width = COLUMN_2_SINGLE_SLOT_FIXTURE_WIDTH - displayName = 'Mag' + displayName = 'Mag' break } case 'cutoutA3': @@ -115,7 +117,7 @@ export function MagneticBlockFixture( onClick={ handleClickRemove != null ? () => handleClickRemove(fixtureLocation, cutoutFixtureId) - : () => { } + : () => {} } > {displayName} diff --git a/components/src/hardware-sim/DeckConfigurator/index.tsx b/components/src/hardware-sim/DeckConfigurator/index.tsx index bd4ab16c8d7..81731591b7c 100644 --- a/components/src/hardware-sim/DeckConfigurator/index.tsx +++ b/components/src/hardware-sim/DeckConfigurator/index.tsx @@ -96,10 +96,10 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { const emptyFixtures = readOnly ? [] : configurableDeckConfig.filter( - ({ cutoutFixtureId }) => - cutoutFixtureId != null && - SINGLE_SLOT_FIXTURES.includes(cutoutFixtureId) - ) + ({ cutoutFixtureId }) => + cutoutFixtureId != null && + SINGLE_SLOT_FIXTURES.includes(cutoutFixtureId) + ) const trashBinFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => cutoutFixtureId === TRASH_BIN_ADAPTER_FIXTURE ) @@ -114,7 +114,10 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { ) const magneticBlockFixtures = configurableDeckConfig.filter( ({ cutoutFixtureId }) => - ([MAGNETIC_BLOCK_V1_FIXTURE, STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE] as CutoutFixtureId[]).includes(cutoutFixtureId) + ([ + MAGNETIC_BLOCK_V1_FIXTURE, + STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE, + ] as CutoutFixtureId[]).includes(cutoutFixtureId) ) return ( @@ -205,7 +208,9 @@ export function DeckConfigurator(props: DeckConfiguratorProps): JSX.Element { handleClickRemove={readOnly ? undefined : handleClickRemove} fixtureLocation={cutoutId} cutoutFixtureId={cutoutFixtureId} - hasStagingArea={cutoutFixtureId === STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE} + hasStagingArea={ + cutoutFixtureId === STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE + } /> ))} {thermocyclerFixtures.map(({ cutoutId, cutoutFixtureId }) => ( diff --git a/shared-data/js/constants.ts b/shared-data/js/constants.ts index b2f2db6c5d8..aaef2eb2430 100644 --- a/shared-data/js/constants.ts +++ b/shared-data/js/constants.ts @@ -1,8 +1,4 @@ -import type { - CutoutFixtureId, - CutoutId, - AddressableAreaName, -} from '../deck' +import type { CutoutFixtureId, CutoutId, AddressableAreaName } from '../deck' import type { ModuleModel, ModuleType } from './types' // constants for dealing with robot coordinate system (eg in labwareTools) @@ -470,7 +466,8 @@ export const HEATERSHAKER_MODULE_V1_FIXTURE: 'heaterShakerModuleV1' = export const TEMPERATURE_MODULE_V2_FIXTURE: 'temperatureModuleV2' = 'temperatureModuleV2' export const MAGNETIC_BLOCK_V1_FIXTURE: 'magneticBlockV1' = 'magneticBlockV1' -export const STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE: 'stagingAreaSlotWithMagneticBlockV1' = 'stagingAreaSlotWithMagneticBlockV1' +export const STAGING_AREA_SLOT_WITH_MAGNETIC_BLOCK_V1_FIXTURE: 'stagingAreaSlotWithMagneticBlockV1' = + 'stagingAreaSlotWithMagneticBlockV1' export const THERMOCYCLER_V2_REAR_FIXTURE: 'thermocyclerModuleV2Rear' = 'thermocyclerModuleV2Rear' export const THERMOCYCLER_V2_FRONT_FIXTURE: 'thermocyclerModuleV2Front' = diff --git a/shared-data/js/fixtures.ts b/shared-data/js/fixtures.ts index 9aafc4ee628..09f6a5c38a4 100644 --- a/shared-data/js/fixtures.ts +++ b/shared-data/js/fixtures.ts @@ -135,10 +135,10 @@ export function getPositionFromSlotId( const slotPosition: CoordinateTuple | null = cutoutPosition != null ? [ - cutoutPosition[0] + offsetFromCutoutFixture[0], - cutoutPosition[1] + offsetFromCutoutFixture[1], - cutoutPosition[2] + offsetFromCutoutFixture[2], - ] + cutoutPosition[0] + offsetFromCutoutFixture[0], + cutoutPosition[1] + offsetFromCutoutFixture[1], + cutoutPosition[2] + offsetFromCutoutFixture[2], + ] : null return slotPosition @@ -179,12 +179,14 @@ export function getCutoutIdsFromModuleSlotName( deckDef: DeckDefinition ): CutoutId[] { const anchorCutoutId = getCutoutIdForSlotName(slotName, deckDef) - // find the first fixture for this specific module model that may mount to the cutout implied by the slotName - const anchorFixture = moduleFixtures.find(fixture => fixture.mayMountTo.some(cutoutId => cutoutId === anchorCutoutId)) + // find the first fixture for this specific module model that may mount to the cutout implied by the slotName + const anchorFixture = moduleFixtures.find(fixture => + fixture.mayMountTo.some(cutoutId => cutoutId === anchorCutoutId) + ) if (anchorCutoutId != null && anchorFixture != null) { const groupedFixtures = anchorFixture.fixtureGroup[anchorCutoutId] return groupedFixtures != null - ? Object.keys((groupedFixtures ?? [])[0] ?? {}) as CutoutId[] + ? (Object.keys((groupedFixtures ?? [])[0] ?? {}) as CutoutId[]) : [anchorCutoutId] } return [] @@ -196,7 +198,11 @@ export function getAddressableAreaNamesFromLoadedModule( deckDef: DeckDefinition ): AddressableAreaName[] { const moduleFixtures = getCutoutFixturesForModuleModel(moduleModel, deckDef) - const cutoutIds = getCutoutIdsFromModuleSlotName(slotName, moduleFixtures, deckDef) + const cutoutIds = getCutoutIdsFromModuleSlotName( + slotName, + moduleFixtures, + deckDef + ) return moduleFixtures.reduce((acc, cutoutFixture) => { const providedAddressableAreas = cutoutIds.reduce( (innerAcc, cutoutId) => { @@ -230,14 +236,14 @@ export function getFixtureDisplayName( case HEATERSHAKER_MODULE_V1_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - HEATERSHAKER_MODULE_V1 - )} in USB-${usbPortNumber}` + HEATERSHAKER_MODULE_V1 + )} in USB-${usbPortNumber}` : getModuleDisplayName(HEATERSHAKER_MODULE_V1) case TEMPERATURE_MODULE_V2_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - TEMPERATURE_MODULE_V2 - )} in USB-${usbPortNumber}` + TEMPERATURE_MODULE_V2 + )} in USB-${usbPortNumber}` : getModuleDisplayName(TEMPERATURE_MODULE_V2) case MAGNETIC_BLOCK_V1_FIXTURE: return `${getModuleDisplayName(MAGNETIC_BLOCK_V1)}` @@ -246,14 +252,14 @@ export function getFixtureDisplayName( case THERMOCYCLER_V2_REAR_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - THERMOCYCLER_MODULE_V2 - )} in USB-${usbPortNumber}` + THERMOCYCLER_MODULE_V2 + )} in USB-${usbPortNumber}` : getModuleDisplayName(THERMOCYCLER_MODULE_V2) case THERMOCYCLER_V2_FRONT_FIXTURE: return usbPortNumber != null ? `${getModuleDisplayName( - THERMOCYCLER_MODULE_V2 - )} in USB-${usbPortNumber}` + THERMOCYCLER_MODULE_V2 + )} in USB-${usbPortNumber}` : getModuleDisplayName(THERMOCYCLER_MODULE_V2) default: return 'Slot'