-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useAllLabware' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './hooks' | ||
export * from './utils' | ||
export type * from './types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
34
app/src/local-resources/labware/utils/getAllDefinitions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './getAllDefinitions' |