Skip to content

Commit

Permalink
refactor(app): Untangle labware organisms (#16295)
Browse files Browse the repository at this point in the history
Another in the vein of the app code reorganization PRs. This time, take
the organisms that make up the labware page and move them into an
`organisms/Desktop/Labware` directory (which will eventually mirror
`organisms/Desktop/Devices`, since there's already `organisms/Devices`)
as a new home.

Also, get rid of the things they import from `pages/Desktop/Labware` by
moving them to a new home: `local-resources`.

In the same way that resources/ provides app-specific wrappers around
robot api concerns, local-resources/ provides app-specific wrappers
around code and handling of other opentrons resources, like (for now)
labware.
  • Loading branch information
sfoster1 authored Sep 19, 2024
1 parent f2e03cc commit 3c3ce0a
Show file tree
Hide file tree
Showing 115 changed files with 185 additions and 192 deletions.
File renamed without changes.
1 change: 1 addition & 0 deletions app/src/local-resources/labware/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useAllLabware'
50 changes: 50 additions & 0 deletions app/src/local-resources/labware/hooks/useAllLabware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useSelector } from 'react-redux'
import { getValidCustomLabware } from '/app/redux/custom-labware'
import { getAllDefinitions } from '../utils'
import type { LabwareSort, LabwareFilter, LabwareDefAndDate } from '../types'

export function useAllLabware(
sortBy: LabwareSort,
filterBy: LabwareFilter
): LabwareDefAndDate[] {
const fullLabwareList: LabwareDefAndDate[] = []
const labwareDefinitions = getAllDefinitions()
labwareDefinitions.forEach(def => fullLabwareList.push({ definition: def }))
const customLabwareList = useSelector(getValidCustomLabware)
customLabwareList.forEach(customLabware =>
'definition' in customLabware
? fullLabwareList.push({
modified: customLabware.modified,
definition: customLabware.definition,
filename: customLabware.filename,
})
: null
)
const sortLabware = (a: LabwareDefAndDate, b: LabwareDefAndDate): number => {
if (
a.definition.metadata.displayName.toUpperCase() <
b.definition.metadata.displayName.toUpperCase()
) {
return sortBy === 'alphabetical' ? -1 : 1
}
if (
a.definition.metadata.displayName.toUpperCase() >
b.definition.metadata.displayName.toUpperCase()
) {
return sortBy === 'alphabetical' ? 1 : -1
}
return 0
}

if (filterBy === 'customLabware') {
return (customLabwareList as LabwareDefAndDate[]).sort(sortLabware)
}
fullLabwareList.sort(sortLabware)
if (filterBy !== 'all') {
return fullLabwareList.filter(
labwareItem =>
labwareItem.definition.metadata.displayCategory === filterBy
)
}
return fullLabwareList
}
3 changes: 3 additions & 0 deletions app/src/local-resources/labware/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './hooks'
export * from './utils'
export type * from './types'
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,12 @@ import type {
LabwareBrand,
} from '@opentrons/shared-data'

export type {
LabwareDefinition2 as LabwareDefinition,
LabwareParameters,
LabwareOffset,
LabwareWell,
LabwareWellShapeProperties,
LabwareWellProperties,
LabwareWellMap,
LabwareWellGroupMetadata,
LabwareVolumeUnits,
LabwareDisplayCategory,
LabwareBrand,
} from '@opentrons/shared-data'

export interface LabwareWellGroupProperties {
xOffsetFromLeft: number
yOffsetFromTop: number
xSpacing: number | null
ySpacing: number | null
wellCount: number
shape: LabwareWellShapeProperties | null
depth: number | null
totalLiquidVolume: number | null
metadata: LabwareWellGroupMetadata
brand: LabwareBrand | null
export interface LabwareDefAndDate {
definition: LabwareDefinition
modified?: number
filename?: string
}

export type LabwareList = LabwareDefinition[]

export type LabwareFilter =
| 'all'
| 'wellPlate'
Expand All @@ -45,3 +22,16 @@ export type LabwareFilter =
| 'adapter'

export type LabwareSort = 'alphabetical' | 'reverse'

export interface LabwareWellGroupProperties {
xOffsetFromLeft: number
yOffsetFromTop: number
xSpacing: number | null
ySpacing: number | null
wellCount: number
shape: LabwareWellShapeProperties | null
depth: number | null
totalLiquidVolume: number | null
metadata: LabwareWellGroupMetadata
brand: LabwareBrand | null
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import groupBy from 'lodash/groupBy'
import { LABWAREV2_DO_NOT_LIST } from '@opentrons/shared-data'
import { getAllDefs } from './getAllDefs'
import type { LabwareDefinition2 } from '@opentrons/shared-data'
import { getAllDefs } from './getAllDefs'

const getOnlyLatestDefs = (
export const getOnlyLatestDefs = (
labwareList: LabwareDefinition2[]
): LabwareDefinition2[] => {
// group by namespace + loadName
Expand Down
1 change: 1 addition & 0 deletions app/src/local-resources/labware/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './getAllDefinitions'
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { renderWithProviders } from '/app/__testing-utils__'
import { AddCustomLabwareSlideout } from '..'

vi.mock('/app/redux/custom-labware')
vi.mock('/app/pages/Desktop/Labware/helpers/getAllDefs')
vi.mock('/app/local-resources/labware')
vi.mock('/app/redux/analytics')

let mockTrackEvent: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '@opentrons/components'

import { Divider } from '/app/atoms/structure'
import { getTopPortalEl } from '../../App/portal'
import { getTopPortalEl } from '/app/App/portal'
import {
deleteCustomLabwareFile,
openCustomLabwareDirectory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { screen } from '@testing-library/react'
import { describe, it, vi, beforeEach } from 'vitest'
import { renderWithProviders, nestedTextMatcher } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { useAllLabware } from '/app/pages/Desktop/Labware/hooks'
import { useAllLabware } from '/app/local-resources/labware'
import { mockDefinition } from '/app/redux/custom-labware/__fixtures__'
import { CustomLabwareOverflowMenu } from '../CustomLabwareOverflowMenu'
import { LabwareCard } from '..'

import type * as OpentronsComponents from '@opentrons/components'

vi.mock('/app/pages/Desktop/Labware/hooks')
vi.mock('/app/local-resources/labware')
vi.mock('../CustomLabwareOverflowMenu')

vi.mock('@opentrons/components', async importOriginal => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {

import { UNIVERSAL_FLAT_ADAPTER_X_DIMENSION } from '../LabwareDetails/Gallery'
import { CustomLabwareOverflowMenu } from './CustomLabwareOverflowMenu'
import type { LabwareDefAndDate } from '/app/pages/Desktop/Labware/hooks'
import type { LabwareDefAndDate } from '/app/local-resources/labware'

export interface LabwareCardProps {
labware: LabwareDefAndDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import round from 'lodash/round'
import { Box, SPACING, getFootprintDiagram } from '@opentrons/components'
import { LabeledValue } from './StyledComponents/LabeledValue'
import { ExpandingTitle } from './StyledComponents/ExpandingTitle'
import type { LabwareDefinition } from '/app/pages/Desktop/Labware/types'
import type { LabwareDefinition2 as LabwareDefinition } from '@opentrons/shared-data'

const toFixed = (n: number): string => round(n, 2).toFixed(2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
SPACING_AUTO,
SPACING,
} from '@opentrons/components'

import { labwareImages } from './labware-images'

import type { LabwareDefinition } from '/app/pages/Desktop/Labware/types'
import type { LabwareDefinition2 as LabwareDefinition } from '@opentrons/shared-data'

export const UNIVERSAL_FLAT_ADAPTER_X_DIMENSION = 127.4

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { WellProperties } from './WellProperties'
import { WellDimensions } from './WellDimensions'
import { ManufacturerDetails } from './ManufacturerDetails'

import type { LabwareDefinition } from '/app/pages/Desktop/Labware/types'
import type { LabwareDefinition2 as LabwareDefinition } from '@opentrons/shared-data'

export interface InsertDetailsProps {
definition: LabwareDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
SPACING,
LegacyStyledText,
} from '@opentrons/components'
import type { LabwareBrand } from '/app/pages/Desktop/Labware/types'
import type { LabwareBrand } from '@opentrons/shared-data'

export interface ManufacturerDetailsProps {
brand: LabwareBrand
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import { Box, SPACING, getMeasurementDiagram } from '@opentrons/components'
import { LabeledValue } from './StyledComponents/LabeledValue'
import { ExpandingTitle } from './StyledComponents/ExpandingTitle'

import type {
LabwareWellGroupProperties,
LabwareParameters,
} from '/app/pages/Desktop/Labware/types'
import type { LabwareParameters } from '@opentrons/shared-data'
import type { LabwareWellGroupProperties } from '/app/local-resources/labware'

const toFixed = (n: number): string => round(n, 2).toFixed(2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ import {
} from '@opentrons/components'
import { getDisplayVolume } from '@opentrons/shared-data'

import type { LabwareWellGroupProperties } from '/app/local-resources/labware'

import type {
LabwareDefinition,
LabwareWellGroupProperties,
LabwareDefinition2 as LabwareDefinition,
LabwareVolumeUnits,
} from '/app/pages/Desktop/Labware/types'
} from '@opentrons/shared-data'

export interface AllWellPropertiesProps {
definition: LabwareDefinition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getSpacingDiagram } from '@opentrons/components'
import { LabeledValue } from './StyledComponents/LabeledValue'
import { ExpandingTitle } from './StyledComponents/ExpandingTitle'

import type { LabwareWellGroupProperties } from '/app/pages/Desktop/Labware/types'
import type { LabwareWellGroupProperties } from '/app/local-resources/labware'

const toFixed = (n: number): string => round(n, 2).toFixed(2)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { describe, it, beforeEach, afterEach, vi, expect } from 'vitest'

import { renderWithProviders } from '/app/__testing-utils__'
import { i18n } from '/app/i18n'
import { useAllLabware } from '/app/pages/Desktop/Labware/hooks'
import { useAllLabware } from '/app/local-resources/labware'
import { mockOpentronsLabwareDetailsDefinition } from '/app/redux/custom-labware/__fixtures__'
import { CustomLabwareOverflowMenu } from '../../LabwareCard/CustomLabwareOverflowMenu'
import { Dimensions } from '../Dimensions'
Expand All @@ -17,7 +17,7 @@ import { WellSpacing } from '../WellSpacing'

import { LabwareDetails } from '..'

vi.mock('/app/pages/Desktop/Labware/hooks')
vi.mock('/app/local-resources/labware')
vi.mock('../../LabwareCard/CustomLabwareOverflowMenu')
vi.mock('../Dimensions')
vi.mock('../Gallery')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import uniqBy from 'lodash/uniqBy'
import type {
LabwareWellGroupProperties,
LabwareDefinition,
} from '/app/pages/Desktop/Labware/types'
import type { LabwareWellGroupProperties } from '/app/local-resources/labware'
import type { LabwareDefinition2 as LabwareDefinition } from '@opentrons/shared-data'

const WELL_TYPE_BY_CATEGORY = {
tubeRack: 'tube',
tipRack: 'tip',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { ManufacturerDetails } from './ManufacturerDetails'
import { InsertDetails } from './InsertDetails'
import { Gallery } from './Gallery'
import { CustomLabwareOverflowMenu } from '../LabwareCard/CustomLabwareOverflowMenu'
import type { LabwareDefAndDate } from '/app/pages/Desktop/Labware/hooks'
import type { LabwareDefAndDate } from '/app/local-resources/labware'

const CLOSE_ICON_STYLE = css`
border-radius: 50%;
Expand Down
Loading

0 comments on commit 3c3ce0a

Please sign in to comment.