Skip to content

Commit

Permalink
Add display color to liquid type
Browse files Browse the repository at this point in the history
  • Loading branch information
smb2268 committed Jun 29, 2022
1 parent 1ca6d69 commit 2176de7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 37 deletions.
15 changes: 14 additions & 1 deletion components/src/ui-style-constants/colors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const alphaToOpacity35 = '35'

export const backgroundOverlay = `${darkBlack}${alphaToOpacity35}`

// colors pd liquid
// colors liquid
export const electricPurple = '#b925ff'
export const goldenYellow = '#ffd600'
export const aquamarine = '#9dffd8'
Expand All @@ -70,3 +70,16 @@ export const richBlue = '#0380fb'
export const springGreen = '#7eff42'
export const tartRed = '#ff4f4f'
export const whaleGrey = '#9395a0'

export const liquidColors = [
electricPurple,
goldenYellow,
aquamarine,
orangePeel,
skyBlue,
popPink,
richBlue,
springGreen,
tartRed,
whaleGrey,
]
4 changes: 0 additions & 4 deletions protocol-designer/src/components/ColorPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ interface ColorPickerProps {
export function ColorPicker(props: ColorPickerProps): JSX.Element {
const [showColorPicker, setShowColorPicker] = React.useState<boolean>(false)

React.useEffect(() => {
console.log(props.value)
}, [props.value])

return (
<div>
<div
Expand Down
27 changes: 17 additions & 10 deletions protocol-designer/src/components/LiquidsPage/LiquidEditForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as React from 'react'
import { Formik, FormikProps } from 'formik'
import { useSelector } from 'react-redux'
import { Field, Formik, FormikProps } from 'formik'
import * as Yup from 'yup'
import { i18n } from '../../localization'
import { swatchColors } from '../swatchColors'
import {
Card,
CheckboxField,
Expand All @@ -10,6 +12,7 @@ import {
OutlineButton,
PrimaryButton,
} from '@opentrons/components'
import { selectors } from '../../labware-ingred/selectors'
import styles from './LiquidEditForm.css'
import formStyles from '../forms/forms.css'

Expand Down Expand Up @@ -47,26 +50,25 @@ export const liquidEditFormSchema: Yup.Schema<

export function LiquidEditForm(props: Props): JSX.Element {
const { deleteLiquidGroup, cancelForm, canDelete, saveForm } = props
const selectedLiquid = useSelector(selectors.getSelectedLiquidGroupState)
const nextGroupId = useSelector(selectors.getNextLiquidGroupId)
const liquidId = selectedLiquid.liquidGroupId ?? nextGroupId

const initialValues: LiquidEditFormValues = {
name: props.name || '',
displayColor: props.displayColor || '',
displayColor: props.displayColor ?? swatchColors(liquidId),
description: props.description || '',
serialize: props.serialize || false,
}

const [currentColor, setCurrentColor] = React.useState<ColorResult['hex']>(
props.displayColor || '#000'
)

return (
<Formik
initialValues={initialValues}
validationSchema={liquidEditFormSchema}
onSubmit={(values: LiquidEditFormValues) => {
saveForm({
name: values.name,
displayColor: currentColor,
displayColor: values.displayColor,
description: values.description || null,
serialize: values.serialize || false,
})
Expand All @@ -76,6 +78,7 @@ export function LiquidEditForm(props: Props): JSX.Element {
handleChange,
handleBlur,
handleSubmit,
setFieldValue,
dirty,
errors,
isValid,
Expand Down Expand Up @@ -112,9 +115,13 @@ export function LiquidEditForm(props: Props): JSX.Element {
/>
</FormGroup>
<FormGroup label={'Liquid'} className={formStyles.column_1_3}>
<ColorPicker
value={currentColor}
onChange={setCurrentColor}
<Field
name="displayColor"
component={ColorPicker}
value={values.displayColor}
onChange={(color: ColorResult['hex']) => {
setFieldValue('displayColor', color)
}}
/>
</FormGroup>
</div>
Expand Down
6 changes: 4 additions & 2 deletions protocol-designer/src/components/LiquidsSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ function LiquidsSidebarComponent(props: Props): JSX.Element {
const { liquids, selectedLiquid, createNewLiquid, selectLiquid } = props
return (
<SidePanel title="Liquids">
{liquids.map(({ ingredientId, name }) => (
{liquids.map(({ ingredientId, name, displayColor }) => (
<PDTitledList
key={ingredientId}
selected={selectedLiquid === ingredientId}
onClick={() => selectLiquid(ingredientId)}
iconName="circle"
iconProps={{ style: { fill: swatchColors(ingredientId) } }}
iconProps={{
style: { fill: displayColor ?? swatchColors(ingredientId) },
}}
title={name || `Unnamed Ingredient ${ingredientId}`} // fallback, should not happen
/>
))}
Expand Down
18 changes: 2 additions & 16 deletions protocol-designer/src/components/swatchColors.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import { AIR } from '@opentrons/step-generation'
import { COLORS } from '@opentrons/components'
export const MIXED_WELL_COLOR = '#9b9b9b' // NOTE: matches `--c-med-gray` in colors.css

// TODO factor into CSS or constants or elsewhere
export const colors = [
COLORS.electricPurple,
COLORS.goldenYellow,
COLORS.aquamarine,
COLORS.orangePeel,
COLORS.skyBlue,
COLORS.popPink,
COLORS.richBlue,
COLORS.springGreen,
COLORS.tartRed,
COLORS.whaleGrey,
]
export const MIXED_WELL_COLOR = '#9b9b9b' // NOTE: matches `--c-med-gray` in COLORS.liquidColors.css

export const swatchColors = (ingredGroupId: string): string => {
const num = Number(ingredGroupId)
Expand All @@ -29,5 +15,5 @@ export const swatchColors = (ingredGroupId: string): string => {
return 'transparent'
}

return colors[num % colors.length]
return COLORS.liquidColors[num % COLORS.liquidColors.length]
}
8 changes: 5 additions & 3 deletions protocol-designer/src/labware-ingred/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import max from 'lodash/max'
import reduce from 'lodash/reduce'
import { Options } from '@opentrons/components'
import { LabwareLiquidState } from '@opentrons/step-generation'
// import { swatchColors } from '../components/swatchColors'
import {
RootState,
ContainersState,
Expand Down Expand Up @@ -105,12 +106,13 @@ const allIngredientGroupFields: Selector<
const allIngredientNamesIds: Selector<
RootSlice,
OrderedLiquids
> = createSelector(getLiquidGroupsById, ingreds =>
Object.keys(ingreds).map(ingredId => ({
> = createSelector(getLiquidGroupsById, ingreds => {
return Object.keys(ingreds).map(ingredId => ({
ingredientId: ingredId,
name: ingreds[ingredId].name,
displayColor: ingreds[ingredId].displayColor,
}))
)
})
const getLabwareSelectionMode: Selector<RootSlice, boolean> = createSelector(
rootSelector,
rootState => {
Expand Down
2 changes: 1 addition & 1 deletion protocol-designer/src/labware-ingred/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface WellContentsByLabware {
export type OrderedLiquids = Array<{
ingredientId: string
name: string | null | undefined
displayColor: string
displayColor: string | null | undefined
}>
// TODO: Ian 2018-10-15 audit & rename these confusing types
export interface LiquidGroup {
Expand Down

0 comments on commit 2176de7

Please sign in to comment.