-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(app): create utils to format value for rtp #14720
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
87 changes: 87 additions & 0 deletions
87
app/src/organisms/ProtocolDetails/ProtocolParameters/__tests__/utils.test.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,87 @@ | ||
import { describe, it, expect } from 'vitest' | ||
|
||
import { formatRunTimeParameterValue } from '../utils' | ||
|
||
import type { RunTimeParameter } from '@opentrons/shared-data' | ||
|
||
describe('utils-formatRunTimeParameterValue', () => { | ||
it('should return value with suffix when type is int', () => { | ||
const mockData = { | ||
value: 6, | ||
displayName: 'PCR Cycles', | ||
variableName: 'PCR_CYCLES', | ||
description: 'number of PCR cycles on a thermocycler', | ||
type: 'int', | ||
min: 1, | ||
max: 10, | ||
default: 6, | ||
} as RunTimeParameter | ||
const result = formatRunTimeParameterValue(mockData) | ||
expect(result).toEqual('6') | ||
}) | ||
|
||
it('should return value with suffix when type is float', () => { | ||
const mockData = { | ||
value: 6.5, | ||
displayName: 'EtoH Volume', | ||
variableName: 'ETOH_VOLUME', | ||
description: '70% ethanol volume', | ||
type: 'float', | ||
suffix: 'mL', | ||
min: 1.5, | ||
max: 10.0, | ||
default: 6.5, | ||
} as RunTimeParameter | ||
const result = formatRunTimeParameterValue(mockData) | ||
expect(result).toEqual('6.5 mL') | ||
}) | ||
|
||
it('should return value with suffix when type is str', () => { | ||
const mockData = { | ||
value: 'left', | ||
displayName: 'pipette mount', | ||
variableName: 'mont', | ||
description: 'pipette mount', | ||
type: 'str', | ||
choices: [ | ||
{ | ||
displayName: 'Left', | ||
value: 'left', | ||
}, | ||
{ | ||
displayName: 'Right', | ||
value: 'right', | ||
}, | ||
], | ||
default: 'left', | ||
} as RunTimeParameter | ||
const result = formatRunTimeParameterValue(mockData) | ||
expect(result).toEqual('Left') | ||
}) | ||
|
||
it('should return value with suffix when type is boolean true', () => { | ||
const mockData = { | ||
value: true, | ||
displayName: 'Deactivate Temperatures', | ||
variableName: 'DEACTIVATE_TEMP', | ||
description: 'deactivate temperature on the module', | ||
type: 'boolean', | ||
default: true, | ||
} as RunTimeParameter | ||
const result = formatRunTimeParameterValue(mockData) | ||
expect(result).toEqual('On') | ||
}) | ||
|
||
it('should return value with suffix when type is boolean false', () => { | ||
const mockData = { | ||
value: false, | ||
displayName: 'Dry Run', | ||
variableName: 'DRYRUN', | ||
description: 'Is this a dry or wet run? Wet is true, dry is false', | ||
type: 'boolean', | ||
default: false, | ||
} as RunTimeParameter | ||
const result = formatRunTimeParameterValue(mockData) | ||
expect(result).toEqual('Off') | ||
}) | ||
}) |
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
31 changes: 31 additions & 0 deletions
31
app/src/organisms/ProtocolDetails/ProtocolParameters/utils.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,31 @@ | ||
import type { RunTimeParameter } from '@opentrons/shared-data' | ||
|
||
export const formatRunTimeParameterValue = ( | ||
runTimeParameter: RunTimeParameter | ||
): 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': | ||
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 '' | ||
} |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe the util should take in
t
as a prop soOn
andOff
can be a in i18n?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the util function.