Skip to content

Commit

Permalink
fixup: forgot to commit these
Browse files Browse the repository at this point in the history
  • Loading branch information
sfoster1 committed Sep 19, 2024
1 parent e39ba5f commit 5592402
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
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'
37 changes: 37 additions & 0 deletions app/src/local-resources/labware/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type {
LabwareDefinition2 as LabwareDefinition,
LabwareWellShapeProperties,
LabwareWellGroupMetadata,
LabwareBrand,
} from '@opentrons/shared-data'

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

export type LabwareFilter =
| 'all'
| 'wellPlate'
| 'tipRack'
| 'tubeRack'
| 'reservoir'
| 'aluminumBlock'
| 'customLabware'
| '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
}
34 changes: 34 additions & 0 deletions app/src/local-resources/labware/utils/getAllDefinitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import groupBy from 'lodash/groupBy'
import { LABWAREV2_DO_NOT_LIST } from '@opentrons/shared-data'
import type { LabwareDefinition2 } from '@opentrons/shared-data'
import { getAllDefs } from './getAllDefs'

export const getOnlyLatestDefs = (
labwareList: LabwareDefinition2[]
): LabwareDefinition2[] => {
// group by namespace + loadName
const labwareDefGroups: {
[groupKey: string]: LabwareDefinition2[]
} = groupBy<LabwareDefinition2>(
labwareList,
d => `${d.namespace}/${d.parameters.loadName}`
)
return Object.keys(labwareDefGroups).map((groupKey: string) => {
const group = labwareDefGroups[groupKey]
const allVersions = group.map(d => d.version)
const highestVersionNum = Math.max(...allVersions)
const resultIdx = group.findIndex(d => d.version === highestVersionNum)
return group[resultIdx]
})
}

export function getAllDefinitions(): LabwareDefinition2[] {
const allDefs = getAllDefs().filter(
(d: LabwareDefinition2) =>
// eslint-disable-next-line @typescript-eslint/prefer-includes
LABWAREV2_DO_NOT_LIST.indexOf(d.parameters.loadName) === -1
)
const definitions = getOnlyLatestDefs(allDefs)

return definitions
}
6 changes: 6 additions & 0 deletions app/src/local-resources/labware/utils/getAllDefs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { getAllDefinitions } from '@opentrons/shared-data'
import type { LabwareDefinition2 } from '@opentrons/shared-data'

export function getAllDefs(): LabwareDefinition2[] {
return Object.values(getAllDefinitions())
}
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'

0 comments on commit 5592402

Please sign in to comment.