Skip to content

Commit

Permalink
rename formatRunTimeParameterDefaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader committed Apr 2, 2024
1 parent 80e8fe6 commit 3f80cf0
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'

import { formatRunTimeParameterValue } from '@opentrons/shared-data'
import { formatRunTimeParameterDefaultValue } from '@opentrons/shared-data'
import {
ALIGN_CENTER,
BORDERS,
Expand Down Expand Up @@ -255,7 +255,7 @@ export function ProtocolRunRuntimeParameters({
gridGap={SPACING.spacing16}
>
<StyledText as="p">
{formatRunTimeParameterValue(parameter, t)}
{formatRunTimeParameterDefaultValue(parameter, t)}
</StyledText>
{/* ToDo (kk:03/19/2024) need to implement a logic when be is ready */}
{index % 2 === 0 ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import { formatRunTimeParameterValue } from '@opentrons/shared-data'
import { formatRunTimeParameterDefaultValue } from '@opentrons/shared-data'
import {
ALIGN_CENTER,
BORDERS,
Expand Down Expand Up @@ -94,7 +94,7 @@ export function ViewOnlyParameters({
gridGap={SPACING.spacing8}
>
<StyledText as="p" maxWidth="15rem" color={COLORS.grey60}>
{formatRunTimeParameterValue(parameter, t)}
{formatRunTimeParameterDefaultValue(parameter, t)}
</StyledText>
{hasCustomValue ? (
<Chip
Expand Down
6 changes: 5 additions & 1 deletion app/src/organisms/ProtocolSetupParameters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export function ProtocolSetupParameters({
const [resetValuesModal, showResetValuesModal] = React.useState<boolean>(
false
)
const parameters = runTimeParameters ?? []
const parameters = mockData

const [newRunTimeParameters, setNewRunTimeParameters] = React.useState<
RunTimeParameter[]
Expand Down Expand Up @@ -248,6 +248,10 @@ export function ProtocolSetupParameters({
paddingX={SPACING.spacing8}
>
{newRunTimeParameters.map((parameter, index) => {
console.log(
'parameter',
parameter.type === 'boolean' ? parameter : undefined
)
return (
<React.Fragment key={`${parameter.displayName}_${index}`}>
<ProtocolSetupStep
Expand Down
4 changes: 2 additions & 2 deletions app/src/pages/ProtocolDetails/Parameters.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { useTranslation } from 'react-i18next'
import styled from 'styled-components'
import { formatRunTimeParameterValue } from '@opentrons/shared-data'
import { formatRunTimeParameterDefaultValue } from '@opentrons/shared-data'
import {
BORDERS,
COLORS,
Expand Down Expand Up @@ -118,7 +118,7 @@ export const Parameters = (props: { protocolId: string }): JSX.Element => {
</TableDatum>
<TableDatum>
<Flex paddingLeft={SPACING.spacing24} color={COLORS.grey60}>
{formatRunTimeParameterValue(parameter, t)}
{formatRunTimeParameterDefaultValue(parameter, t)}
</Flex>
</TableDatum>
<TableDatum>
Expand Down
4 changes: 2 additions & 2 deletions components/src/molecules/ParametersTable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import styled from 'styled-components'
import { formatRunTimeParameterValue } from '@opentrons/shared-data'
import { formatRunTimeParameterDefaultValue } from '@opentrons/shared-data'
import { BORDERS } from '../../helix-design-system'
import { SPACING, TYPOGRAPHY } from '../../ui-style-constants/index'
import { StyledText } from '../../atoms/StyledText'
Expand Down Expand Up @@ -69,7 +69,7 @@ export function ParametersTable({
</StyledTableCell>
<StyledTableCell isLast={index === runTimeParameters.length - 1}>
<StyledText as="p">
{formatRunTimeParameterValue(parameter, t)}
{formatRunTimeParameterDefaultValue(parameter, t)}
</StyledText>
</StyledTableCell>
<StyledTableCell isLast={index === runTimeParameters.length - 1}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from 'vitest'
import { formatRunTimeParameterValue } from '../formatRunTimeParameterValue'
import { formatRunTimeParameterDefaultValue } from '../formatRunTimeParameterDefaultValue'

import type { RunTimeParameter } from '../../types'

Expand All @@ -9,7 +9,7 @@ const capitalizeFirstLetter = (str: string): string => {

const mockTFunction = vi.fn(str => capitalizeFirstLetter(str))

describe('utils-formatRunTimeParameterValue', () => {
describe('utils-formatRunTimeParameterDefaultValue', () => {
it('should return value with suffix when type is int', () => {
const mockData = {
value: 6,
Expand All @@ -21,7 +21,7 @@ describe('utils-formatRunTimeParameterValue', () => {
max: 10,
default: 6,
} as RunTimeParameter
const result = formatRunTimeParameterValue(mockData, mockTFunction)
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('6')
})

Expand All @@ -37,7 +37,7 @@ describe('utils-formatRunTimeParameterValue', () => {
max: 10.0,
default: 6.5,
} as RunTimeParameter
const result = formatRunTimeParameterValue(mockData, mockTFunction)
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('6.5 mL')
})

Expand All @@ -60,7 +60,7 @@ describe('utils-formatRunTimeParameterValue', () => {
],
default: 'left',
} as RunTimeParameter
const result = formatRunTimeParameterValue(mockData, mockTFunction)
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('Left')
})

Expand All @@ -73,7 +73,7 @@ describe('utils-formatRunTimeParameterValue', () => {
type: 'boolean',
default: true,
} as RunTimeParameter
const result = formatRunTimeParameterValue(mockData, mockTFunction)
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('On')
})

Expand All @@ -86,7 +86,7 @@ describe('utils-formatRunTimeParameterValue', () => {
type: 'boolean',
default: false,
} as RunTimeParameter
const result = formatRunTimeParameterValue(mockData, mockTFunction)
const result = formatRunTimeParameterDefaultValue(mockData, mockTFunction)
expect(result).toEqual('Off')
})
})
36 changes: 36 additions & 0 deletions shared-data/js/helpers/formatRunTimeParameterDefaultValue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { RunTimeParameter } from '../types'

export const formatRunTimeParameterDefaultValue = (
runTimeParameter: RunTimeParameter,
t?: any
): string => {
const { type, default: defaultValue } = runTimeParameter
const suffix =
'suffix' in runTimeParameter && runTimeParameter.suffix != null
? runTimeParameter.suffix
: null
switch (type) {
case 'int':
case 'float':
return suffix !== null
? `${defaultValue.toString()} ${suffix}`
: defaultValue.toString()
case 'boolean':
if (t != null) {
return Boolean(defaultValue) ? t('on') : t('off')
} else {
return Boolean(defaultValue) ? 'On' : 'Off'
}
case 'str':
if ('choices' in runTimeParameter && runTimeParameter.choices != null) {
const choice = runTimeParameter.choices.find(
choice => choice.value === defaultValue
)
if (choice != null) {
return choice.displayName
}
}
break
}
return ''
}
21 changes: 9 additions & 12 deletions shared-data/js/helpers/formatRunTimeParameterValue.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { RunTimeParameter } from '../types'
import type { RunTimeParameter } from '../types'

export const formatRunTimeParameterValue = (
runTimeParameter: RunTimeParameter,
t?: any
t: any
): string => {
const { type, default: defaultValue } = runTimeParameter
const { type, value } = runTimeParameter
const suffix =
'suffix' in runTimeParameter && runTimeParameter.suffix != null
? runTimeParameter.suffix
Expand All @@ -13,18 +13,15 @@ export const formatRunTimeParameterValue = (
case 'int':
case 'float':
return suffix !== null
? `${defaultValue.toString()} ${suffix}`
: defaultValue.toString()
case 'boolean':
if (t != null) {
return Boolean(defaultValue) ? t('on') : t('off')
} else {
return Boolean(defaultValue) ? 'On' : 'Off'
}
? `${value.toString()} ${suffix}`
: value.toString()
case 'boolean': {
return Boolean(value) ? t('on') : t('off')
}
case 'str':
if ('choices' in runTimeParameter && runTimeParameter.choices != null) {
const choice = runTimeParameter.choices.find(
choice => choice.value === defaultValue
choice => choice.value === value
)
if (choice != null) {
return choice.displayName
Expand Down
1 change: 1 addition & 0 deletions shared-data/js/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export * from './getOccludedSlotCountForModule'
export * from './labwareInference'
export * from './getAddressableAreasInProtocol'
export * from './getSimplestFlexDeckConfig'
export * from './formatRunTimeParameterDefaultValue'
export * from './formatRunTimeParameterValue'

export const getLabwareDefIsStandard = (def: LabwareDefinition2): boolean =>
Expand Down

0 comments on commit 3f80cf0

Please sign in to comment.