Skip to content

Commit

Permalink
feat(protocol-designer): introduce LiquidEntities and update ingredie…
Browse files Browse the repository at this point in the history
…nts JSON key to match

closes AUTH-1382
  • Loading branch information
jerader committed Jan 30, 2025
1 parent 4f3acfc commit d6b5964
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ function getInvariantContextAndRobotState(
moduleEntities: {},
pipetteEntities,
additionalEquipmentEntities,
liquidEntities: {},
config: { OT_PD_DISABLE_MODULE_RESTRICTIONS: false },
}
const moduleLocations = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
},
"ingredients": {
"0": {
"name": "Water",
"displayName": "Water",
"displayColor": "#b925ff",
"description": null,
"serialize": false,
"pythonName": "liquid_0",
"liquidGroupId": "0"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
},
"ingredients": {
"0": {
"name": "Water",
"displayName": "Water",
"displayColor": "#b925ff",
"description": null,
"serialize": false,
"pythonName": "liquid_0",
"liquidGroupId": "0"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
},
"ingredients": {
"0": {
"name": "Water",
"displayName": "Water",
"displayColor": "#b925ff",
"description": null,
"serialize": false,
"pythonName": "liquid_0",
"liquidGroupId": "0"
},
"1": {
"name": "Samples",
"displayName": "Samples",
"displayColor": "#ffd600",
"description": null,
"serialize": false,
"pythonName": "liquid_1",
"liquidGroupId": "1"
}
},
Expand Down
10 changes: 5 additions & 5 deletions protocol-designer/fixtures/protocol/8/doItAllV8.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@
},
"ingredients": {
"0": {
"name": "h20",
"displayName": "h20",
"displayColor": "#b925ff",
"description": null,
"serialize": false,
"pythonName": "liquid_0",
"liquidGroupId": "0"
},
"1": {
"name": "sample",
"displayName": "sample",
"displayColor": "#ffd600",
"description": null,
"serialize": false,
"liquidGroupId": "1"
"liquidGroupId": "1",
"pythonName": "liquid_1"
}
},
"ingredLocations": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@
},
"ingredients": {
"0": {
"name": "samples",
"displayName": "samples",
"description": null,
"serialize": false,
"displayColor": "#b925ff",
"pythonName": "liquid_0",
"liquidGroupId": "0"
},
"1": {
"name": "dna",
"displayName": "dna",
"description": null,
"serialize": false,
"pythonName": "liquid_1",
"displayColor": "#ffd600",
"liquidGroupId": "1"
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
},
"ingredients": {
"0": {
"name": "123",
"displayName": "123",
"displayColor": "#b925ff",
"description": null,
"serialize": false,
"pythonName": "liquid_0",
"liquidGroupId": "0"
}
},
Expand Down
19 changes: 8 additions & 11 deletions protocol-designer/src/labware-ingred/__tests__/ingredients.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, it, expect, vi } from 'vitest'
import { ingredients, ingredLocations } from '../reducers'
import type { LiquidEntities } from '@opentrons/step-generation'
vi.mock('../../labware-defs/utils')

describe('DUPLICATE_LABWARE action', () => {
Expand All @@ -13,24 +14,20 @@ describe('DUPLICATE_LABWARE action', () => {
},
}

const prevIngredState = {
const prevIngredState: LiquidEntities = {
ingred3: {
name: 'Buffer',
wellDetailsByLocation: null,
concentration: '50 mol/ng',
displayName: 'Buffer',
description: '',
liquidClass: null,
displayColor: '#b925ff',
serialize: false,
liquidGroupId: '0',
pythonName: 'python_0',
},
ingred4: {
name: 'Other Ingred',
wellDetailsByLocation: null,
concentration: '100%',
displayName: 'Other Ingred',
description: '',
liquidClass: null,
displayColor: '#ffd600',
serialize: false,
liquidGroupId: '1',
pythonName: 'liquid_1',
},
}

Expand Down
45 changes: 0 additions & 45 deletions protocol-designer/src/labware-ingred/__tests__/selectors.test.ts

This file was deleted.

24 changes: 22 additions & 2 deletions protocol-designer/src/load-file/migration/8_5_0.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import floor from 'lodash/floor'
import { swatchColors } from '../../organisms/DefineLiquidsModal/swatchColors'
import type {
LabwareDefinition2,
LoadLabwareCreateCommand,
ProtocolFile,
} from '@opentrons/shared-data'
import type { LiquidEntities } from '@opentrons/step-generation'
import type { DesignerApplicationDataV8 } from '../../file-data/selectors'
import type { DesignerApplicationData } from './utils/getLoadLiquidCommands'

const getMigratedPositionFromTop = (
Expand Down Expand Up @@ -48,15 +51,31 @@ const getMigratedPositionFromTop = (

export const migrateFile = (
appData: ProtocolFile<DesignerApplicationData>
): ProtocolFile<DesignerApplicationData> => {
const { designerApplication, commands, labwareDefinitions } = appData
): ProtocolFile<DesignerApplicationDataV8> => {
const { designerApplication, commands, labwareDefinitions, liquids } = appData

if (designerApplication == null || designerApplication?.data == null) {
throw Error('The designerApplication key in your file is corrupt.')
}
const savedStepForms = designerApplication.data
?.savedStepForms as DesignerApplicationData['savedStepForms']

const ingredients = designerApplication.data.ingredients

const migratedIngredients: LiquidEntities = Object.entries(
ingredients
).reduce<LiquidEntities>((acc, [id, ingredient]) => {
acc[id] = {
displayName: ingredient.name ?? '',
liquidClass: ingredient.liquidClass,
description: ingredient.description ?? null,
liquidGroupId: id,
pythonName: `liquid_${id}`,
displayColor: liquids[id].displayColor ?? swatchColors(id),
}
return acc
}, {})

const loadLabwareCommands = commands.filter(
(command): command is LoadLabwareCreateCommand =>
command.commandType === 'loadLabware'
Expand Down Expand Up @@ -153,6 +172,7 @@ export const migrateFile = (
...designerApplication,
data: {
...designerApplication.data,
ingredients: migratedIngredients,
savedStepForms: {
...designerApplication.data.savedStepForms,
...savedStepsWithUpdatedMoveLiquidFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import reduce from 'lodash/reduce'
import { uuid } from '../../../utils'
import type { LoadLiquidCreateCommand } from '@opentrons/shared-data/protocol/types/schemaV6/command/setup'
import type { DismissedWarningState } from '../../../dismiss/reducers'
import { DesignerApplicationDataV8 } from '../../../file-data/selectors'
import { LiquidEntities, LiquidEntity } from '@opentrons/step-generation'
import type { LiquidEntities } from '@opentrons/step-generation'

export interface DesignerApplicationData {
ingredients: Record<
string,
{
name?: string | null
description?: string | null
liquidClass?: string
serialize: boolean
}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { i18n } from '../../assets/localization'
import { configureStore } from '../../configureStore'
import { MaterialsListModal as MaterialsListModalComponent } from '.'

import type { LiquidEntities } from '@opentrons/step-generation'
import type { Meta, StoryObj } from '@storybook/react'
import type { LabwareOnDeck, ModuleOnDeck } from '../../step-forms'
import type { FixtureInList } from '.'
Expand Down Expand Up @@ -45,8 +46,7 @@ const mockLabware = [
},
] as LabwareOnDeck[]

// ToDo (kk:09/03/2024) add test when implementing liquids part completely
const mockLiquids = [] as any[]
const mockLiquids = {} as LiquidEntities

const meta: Meta<typeof MaterialsListModalComponent> = {
title: 'Protocol-Designer/Organisms/MaterialsListModal',
Expand Down Expand Up @@ -80,6 +80,6 @@ export const EmptyMaterialsListModal: Story = {
hardware: [],
fixtures: [],
labware: [],
liquids: [],
liquids: {},
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('MaterialsListModal', () => {
hardware: [],
fixtures: [],
labware: [],
liquids: [],
liquids: {},
setShowMaterialsListModal: mockSetShowMaterialsListModal,
}
vi.mocked(getInitialDeckSetup).mockReturnValue({
Expand Down Expand Up @@ -157,14 +157,15 @@ describe('MaterialsListModal', () => {
props = {
...props,

liquids: [
{
ingredientId: mockId,
name: 'mockName',
liquids: {
[mockId]: {
liquidGroupId: mockId,
displayName: 'mockName',
displayColor: 'mockDisplayColor',
liquidClass: null,
description: null,
pythonName: 'mockPythonName',
},
],
},
}
render(props)
screen.getByText('Liquids')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRef } from 'react'
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { fireEvent, screen } from '@testing-library/react'
import { i18n } from '../../../assets/localization'
import { selectors as labwareIngredSelectors } from '../../../labware-ingred/selectors'
import { getLiquidEntities } from '../../../step-forms/selectors'
import * as labwareIngredActions from '../../../labware-ingred/actions'
import { renderWithProviders } from '../../../__testing-utils__'
import { LiquidsOverflowMenu } from '../LiquidsOverflowMenu'
Expand All @@ -12,6 +12,7 @@ import type { NavigateFunction } from 'react-router-dom'

const mockLocation = vi.fn()

vi.mock('../../../step-forms/selectors')
vi.mock('../../../labware-ingred/selectors')
vi.mock('../../../labware-ingred/actions')
vi.mock('react-router-dom', async importOriginal => {
Expand All @@ -37,14 +38,15 @@ describe('SlotOverflowMenu', () => {
showLiquidsModal: vi.fn(),
overflowWrapperRef: createRef(),
}
vi.mocked(labwareIngredSelectors.allIngredientNamesIds).mockReturnValue([
{
vi.mocked(getLiquidEntities).mockReturnValue({
'0': {
displayColor: 'mockColor',
name: 'mockname',
ingredientId: '0',
liquidClass: null,
displayName: 'mockname',
liquidGroupId: '0',
description: null,
pythonName: 'python_0',
},
])
})
})
it('renders the overflow buttons with 1 liquid defined', () => {
render(props)
Expand Down
Loading

0 comments on commit d6b5964

Please sign in to comment.