Skip to content

Commit

Permalink
refactor(app): move code to stop importing lw page
Browse files Browse the repository at this point in the history
There were a couple helpers and types that lived in
app/src/pages/Desktop/Labware that were imported all over the place in
organisms. Let's give them 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 committed Sep 19, 2024
1 parent f5e287d commit 9b736a6
Show file tree
Hide file tree
Showing 27 changed files with 48 additions and 186 deletions.
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 @@ -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
2 changes: 1 addition & 1 deletion app/src/organisms/Desktop/Labware/LabwareCard/index.tsx
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
3 changes: 2 additions & 1 deletion app/src/organisms/Desktop/Labware/LabwareDetails/Gallery.tsx
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
2 changes: 1 addition & 1 deletion app/src/organisms/Desktop/Labware/LabwareDetails/index.tsx
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
4 changes: 2 additions & 2 deletions app/src/organisms/ProtocolDetails/ProtocolLabwareDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import {
import { getLabwareDefURI } from '@opentrons/shared-data'
import { Divider } from '/app/atoms/structure'
import { getTopPortalEl } from '/app/App/portal'
import { LabwareDetails } from '../Desktop/LabwareDetails'
import { LabwareDetails } from '../Desktop/Labware/LabwareDetails'

import type { LoadLabwareRunTimeCommand } from '@opentrons/shared-data'
import type { LabwareDefAndDate } from '/app/pages/Desktop/Labware/hooks'
import type { LabwareDefAndDate } from '/app/local-resources/labware'

interface ProtocolLabwareDetailsProps {
requiredLabwareDetails: LoadLabwareRunTimeCommand[] | null
Expand Down
2 changes: 1 addition & 1 deletion app/src/organisms/QuickTransferFlow/SelectDestLabware.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getCompatibleLabwareByCategory } from './utils'

import type { LabwareDefinition2 } from '@opentrons/shared-data'
import type { SmallButton } from '/app/atoms/buttons'
import type { LabwareFilter } from '/app/pages/Desktop/Labware/types'
import type { LabwareFilter } from '/app/local-resources/labware'
import type {
QuickTransferWizardState,
QuickTransferWizardAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { getCompatibleLabwareByCategory } from './utils'

import type { LabwareDefinition2 } from '@opentrons/shared-data'
import type { SmallButton } from '/app/atoms/buttons'
import type { LabwareFilter } from '/app/pages/Desktop/Labware/types'
import type { LabwareFilter } from '/app/local-resources/labware'
import type {
QuickTransferWizardState,
QuickTransferWizardAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeWellSetHelpers, getLabwareDefURI } from '@opentrons/shared-data'
import { getAllDefinitions as getAllLatestDefValues } from '/app/pages/Desktop/Labware/helpers/definitions'
import { getAllDefinitions as getAllLatestDefValues } from '/app/local-resources/labware'

import type { PipetteV2Specs, WellSetHelpers } from '@opentrons/shared-data'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../constants'

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

export function getCompatibleLabwareByCategory(
pipetteChannels: 1 | 8 | 96,
Expand Down
8 changes: 5 additions & 3 deletions app/src/pages/Desktop/Labware/__tests__/Labware.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ import {
useTrackEvent,
ANALYTICS_OPEN_LABWARE_CREATOR_FROM_BOTTOM_OF_LABWARE_LIBRARY_LIST,
} from '/app/redux/analytics'
import { LabwareCard } from '/app/organisms/Desktop/LabwareCard'
import { AddCustomLabwareSlideout } from '/app/organisms/Desktop/AddCustomLabwareSlideout'
import { LabwareCard } from '/app/organisms/Desktop/Labware/LabwareCard'
import { AddCustomLabwareSlideout } from '/app/organisms/Desktop/Labware/AddCustomLabwareSlideout'
import { useToaster } from '/app/organisms/ToasterOven'
import { useAllLabware, useLabwareFailure, useNewLabwareName } from '../hooks'
import { useLabwareFailure, useNewLabwareName } from '../hooks'
import { Labware } from '..'
import { useAllLabware } from '/app/local-resources/labware'
import { mockDefinition } from '/app/redux/custom-labware/__fixtures__'

vi.mock('/app/organisms/LabwareCard')
vi.mock('/app/organisms/AddCustomLabwareSlideout')
vi.mock('/app/organisms/ToasterOven')
vi.mock('../hooks')
vi.mock('/app/redux/analytics')
vi.mock('/app/local-resources/labware')

const mockTrackEvent = vi.fn()
const mockMakeSnackbar = vi.fn()
Expand Down
7 changes: 4 additions & 3 deletions app/src/pages/Desktop/Labware/__tests__/hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { vi, it, describe, expect, beforeEach, afterEach } from 'vitest'
import { renderHook } from '@testing-library/react'
import { i18n } from '/app/i18n'
import { I18nextProvider } from 'react-i18next'
import { getAllDefs } from '../helpers/getAllDefs'
import { getAllDefs } from '/app/local-resources/labware/utils/getAllDefs'

import {
getValidCustomLabware,
Expand All @@ -17,14 +17,15 @@ import {
mockValidLabware,
} from '/app/redux/custom-labware/__fixtures__'

import { useAllLabware, useLabwareFailure, useNewLabwareName } from '../hooks'
import { useLabwareFailure, useNewLabwareName } from '../hooks'
import { useAllLabware } from '/app/local-resources/labware'

import type { Store } from 'redux'
import type { State } from '/app/redux/types'
import type { FailedLabwareFile } from '/app/redux/custom-labware/types'

vi.mock('/app/redux/custom-labware')
vi.mock('../helpers/getAllDefs')
vi.mock('/app/local-resources/labware/utils/getAllDefs')

describe('useAllLabware hook', () => {
const store: Store<State> = createStore(vi.fn(), {})
Expand Down
34 changes: 0 additions & 34 deletions app/src/pages/Desktop/Labware/helpers/definitions.ts

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/pages/Desktop/Labware/helpers/getAllDefs.ts

This file was deleted.

57 changes: 0 additions & 57 deletions app/src/pages/Desktop/Labware/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,66 +5,9 @@ import {
clearAddCustomLabwareFailure,
getAddNewLabwareName,
clearNewLabwareName,
getValidCustomLabware,
} from '/app/redux/custom-labware'
import { getAllDefinitions } from './helpers/definitions'
import type { Dispatch } from '/app/redux/types'

import type { LabwareDefinition2 as LabwareDefinition } from '@opentrons/shared-data'
import type { LabwareFilter, LabwareSort } from './types'

export interface LabwareDefAndDate {
definition: LabwareDefinition
modified?: number
filename?: string
}

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
}

export function useLabwareFailure(): {
labwareFailureMessage: string | null
clearLabwareFailure: () => unknown
Expand Down
16 changes: 10 additions & 6 deletions app/src/pages/Desktop/Labware/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ import {
ANALYTICS_OPEN_LABWARE_CREATOR_FROM_BOTTOM_OF_LABWARE_LIBRARY_LIST,
} from '/app/redux/analytics'
import { addCustomLabwareFileFromCreator } from '/app/redux/custom-labware'
import { LabwareCard } from '/app/organisms/Desktop/LabwareCard'
import { AddCustomLabwareSlideout } from '/app/organisms/Desktop/AddCustomLabwareSlideout'
import { LabwareDetails } from '/app/organisms/Desktop/LabwareDetails'
import { LabwareCard } from '/app/organisms/Desktop/Labware/LabwareCard'
import { AddCustomLabwareSlideout } from '/app/organisms/Desktop/Labware/AddCustomLabwareSlideout'
import { LabwareDetails } from '/app/organisms/Desktop/Labware/LabwareDetails'
import { useToaster } from '/app/organisms/ToasterOven'
import { useFeatureFlag } from '/app/redux/config'
import { useAllLabware, useLabwareFailure, useNewLabwareName } from './hooks'
import { useLabwareFailure, useNewLabwareName } from './hooks'
import { useAllLabware } from '/app/local-resources/labware'

import type { DropdownOption } from '@opentrons/components'
import type { LabwareFilter, LabwareSort } from './types'
import type { LabwareDefAndDate } from './hooks'
import type {
LabwareFilter,
LabwareSort,
LabwareDefAndDate,
} from '/app/local-resources/labware'

const LABWARE_CREATOR_HREF = 'https://labware.opentrons.com/create/'
const labwareDisplayCategoryFilters: LabwareFilter[] = [
Expand Down
Loading

0 comments on commit 9b736a6

Please sign in to comment.