Skip to content
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

fix(app): fix choose csv file button label #15529

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import { renderWithProviders } from '../../../__testing-utils__'
import { ProtocolSetupParameters } from '..'
import { ChooseEnum } from '../ChooseEnum'
import { mockRunTimeParameterData } from '../../../pages/ProtocolDetails/fixtures'
import { useFeatureFlag } from '../../../redux/config'

import type * as ReactRouterDom from 'react-router-dom'
import type { HostConfig } from '@opentrons/api-client'
import type {
CompletedProtocolAnalysis,
RunTimeParameter,
} from '@opentrons/shared-data'

const mockGoBack = vi.fn()

Expand All @@ -27,16 +33,24 @@ vi.mock('react-router-dom', async importOriginal => {
useHistory: () => ({ goBack: mockGoBack } as any),
}
})
vi.mock('../../../redux/config')

const MOCK_HOST_CONFIG: HostConfig = { hostname: 'MOCK_HOST' }
const mockCreateProtocolAnalysis = vi.fn()
const mockCreateRun = vi.fn()
const mockMostRecentAnalysis = ({
commands: [],
labware: [],
} as unknown) as CompletedProtocolAnalysis

const render = (
props: React.ComponentProps<typeof ProtocolSetupParameters>
) => {
return renderWithProviders(<ProtocolSetupParameters {...props} />, {
i18nInstance: i18n,
})
}

describe('ProtocolSetupParameters', () => {
let props: React.ComponentProps<typeof ProtocolSetupParameters>

Expand All @@ -45,6 +59,7 @@ describe('ProtocolSetupParameters', () => {
protocolId: 'mockId',
labwareOffsets: [],
runTimeParameters: mockRunTimeParameterData,
mostRecentAnalysis: mockMostRecentAnalysis,
}
vi.mocked(ChooseEnum).mockReturnValue(<div>mock ChooseEnum</div>)
vi.mocked(useHost).mockReturnValue(MOCK_HOST_CONFIG)
Expand All @@ -54,6 +69,9 @@ describe('ProtocolSetupParameters', () => {
when(vi.mocked(useCreateRunMutation))
.calledWith(expect.anything())
.thenReturn({ createRun: mockCreateRun } as any)
when(vi.mocked(useFeatureFlag))
.calledWith('enableCsvFile')
.thenReturn(false)
})

it('renders the parameters labels and mock data', () => {
Expand Down Expand Up @@ -109,4 +127,38 @@ describe('ProtocolSetupParameters', () => {
fireEvent.click(screen.getByRole('button', { name: 'Go back' }))
expect(title).not.toBeInTheDocument()
})

it('render csv file when a protocol requires a csv file', () => {
when(vi.mocked(useFeatureFlag)).calledWith('enableCsvFile').thenReturn(true)
const mockMostRecentAnalysisForCsv = ({
commands: [],
labware: [],
result: 'parameter-value-required',
} as unknown) as CompletedProtocolAnalysis
const mockCSVData = {
file: { id: 'test', file: { name: 'mock.csv' } as File },
displayName: 'My CSV File',
variableName: 'CSVFILE',
description: 'CSV File for a protocol',
type: 'csv_file' as const,
} as RunTimeParameter
const mockRunTimeParameterDataForCsv = [
...mockRunTimeParameterData,
mockCSVData,
]

render({
...props,
runTimeParameters: mockRunTimeParameterDataForCsv,
mostRecentAnalysis: mockMostRecentAnalysisForCsv,
})
screen.getByText('CSV File')
screen.getByText('Required')
const button = screen.getByRole('button', { name: 'Confirm values' })
expect(button).toBeDisabled()
})

it.todo(
'render csv file name when a protocol analysis result is not parameter-value-required'
)
})
42 changes: 37 additions & 5 deletions app/src/organisms/ProtocolSetupParameters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ import { ChildNavigation } from '../ChildNavigation'
import { ResetValuesModal } from './ResetValuesModal'
import { ChooseEnum } from './ChooseEnum'
import { ChooseNumber } from './ChooseNumber'
import { useFeatureFlag } from '../../redux/config'

import type {
CompletedProtocolAnalysis,
ChoiceParameter,
NumberParameter,
RunTimeParameter,
Expand All @@ -37,14 +39,17 @@ interface ProtocolSetupParametersProps {
protocolId: string
runTimeParameters: RunTimeParameter[]
labwareOffsets?: LabwareOffsetCreateData[]
mostRecentAnalysis?: CompletedProtocolAnalysis | null
}

export function ProtocolSetupParameters({
protocolId,
labwareOffsets,
runTimeParameters,
mostRecentAnalysis,
}: ProtocolSetupParametersProps): JSX.Element {
const { t } = useTranslation('protocol_setup')
const enableCsvFile = useFeatureFlag('enableCsvFile')
const history = useHistory()
const host = useHost()
const queryClient = useQueryClient()
Expand Down Expand Up @@ -157,6 +162,10 @@ export function ProtocolSetupParameters({
}}
onClickButton={handleConfirmValues}
buttonText={t('confirm_values')}
buttonIsDisabled={
enableCsvFile &&
mostRecentAnalysis?.result === 'parameter-value-required'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the getAnalysisStatus utility in this PR, but this works for now!

}
iconName={isLoading || startSetup ? 'ot-spinner' : undefined}
iconPlacement="startIcon"
secondaryButtonProps={{
Expand All @@ -178,21 +187,44 @@ export function ProtocolSetupParameters({
>
{sortRuntimeParameters(runTimeParametersOverrides).map(
(parameter, index) => {
const detailLabelForCsv =
mostRecentAnalysis?.result === 'parameter-value-required'
? t('required')
: parameter.displayName

let setupStatus: 'ready' | 'not ready' | 'general' | 'inform' =
'inform'
if (
enableCsvFile &&
parameter.type === 'csv_file' &&
mostRecentAnalysis?.result === 'parameter-value-required'
) {
setupStatus = 'not ready'
}
if (
enableCsvFile &&
parameter.type === 'csv_file' &&
mostRecentAnalysis?.result === 'ok'
) {
setupStatus = 'ready'
}
return (
<React.Fragment key={`${parameter.displayName}_${index}`}>
<ProtocolSetupStep
hasRightIcon={!(parameter.type === 'bool')}
hasLeftIcon={false}
status={
parameter.type === 'csv_file' ? 'not ready' : 'inform'
status={setupStatus}
title={
parameter.type === 'csv_file'
? t('csv_file')
: parameter.displayName
}
title={parameter.displayName}
onClickSetupStep={() => {
handleSetParameter(parameter)
}}
detail={
parameter.type === 'csv_file'
? t('required')
enableCsvFile && parameter.type === 'csv_file'
? detailLabelForCsv
: formatRunTimeParameterValue(parameter, t)
}
description={
Expand Down
1 change: 1 addition & 0 deletions app/src/pages/ProtocolDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ export function ProtocolDetails(): JSX.Element | null {
protocolId={protocolId}
labwareOffsets={labwareOffsets}
runTimeParameters={runTimeParameters}
mostRecentAnalysis={mostRecentAnalysis}
/>
) : (
<>
Expand Down
Loading