Skip to content

Commit

Permalink
fix(protocol-designer): form warnings always show in form (#16846)
Browse files Browse the repository at this point in the history
clsoes RQA-3598
  • Loading branch information
jerader authored Nov 15, 2024
1 parent 112ea83 commit 0110e17
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 47 deletions.
25 changes: 8 additions & 17 deletions protocol-designer/src/organisms/Alerts/FormAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type { ProfileFormError } from '../../steplist/formLevel/profileErrors'
import type { MakeAlert } from './types'

interface FormAlertsProps {
showFormErrorsAndWarnings: boolean
showFormErrors: boolean
focusedField?: StepFieldName | null
dirtyFields?: StepFieldName[]
page: number
Expand All @@ -41,7 +41,7 @@ interface WarningType {
}

function FormAlertsComponent(props: FormAlertsProps): JSX.Element | null {
const { showFormErrorsAndWarnings, focusedField, dirtyFields, page } = props
const { showFormErrors, focusedField, dirtyFields, page } = props

const { t } = useTranslation('alert')
const dispatch = useDispatch()
Expand Down Expand Up @@ -78,7 +78,7 @@ function FormAlertsComponent(props: FormAlertsProps): JSX.Element | null {
dirtyFields: dirtyFields ?? [],
errors: formLevelErrorsForUnsavedForm,
page,
showErrors: showFormErrorsAndWarnings,
showErrors: showFormErrors,
})

const profileItemsById: Record<string, ProfileItem> | null | undefined =
Expand Down Expand Up @@ -180,28 +180,19 @@ function FormAlertsComponent(props: FormAlertsProps): JSX.Element | null {
}
}

if (showFormErrorsAndWarnings) {
return [...formErrors, ...formWarnings].length > 0 ? (
<Flex
flexDirection={DIRECTION_COLUMN}
gridGap={SPACING.spacing4}
padding={`${SPACING.spacing16} ${SPACING.spacing16} 0`}
>
{formErrors.map((error, key) => makeAlert('error', error, key))}
{formWarnings.map((warning, key) => makeAlert('warning', warning, key))}
</Flex>
) : null
}

return timelineWarnings.length > 0 ? (
return [...formErrors, ...timelineWarnings, ...formWarnings].length > 0 ? (
<Flex
flexDirection={DIRECTION_COLUMN}
gridGap={SPACING.spacing4}
padding={`${SPACING.spacing16} ${SPACING.spacing16} 0`}
>
{showFormErrors
? formErrors.map((error, key) => makeAlert('error', error, key))
: null}
{timelineWarnings.map((warning, key) =>
makeAlert('warning', warning, key)
)}
{formWarnings.map((warning, key) => makeAlert('warning', warning, key))}
</Flex>
) : null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('FormAlerts', () => {
props = {
focusedField: null,
dirtyFields: [],
showFormErrorsAndWarnings: false,
showFormErrors: false,
page: 0,
}
vi.mocked(getFormLevelErrorsForUnsavedForm).mockReturnValue([])
Expand All @@ -64,7 +64,6 @@ describe('FormAlerts', () => {
expect(vi.mocked(dismissTimelineWarning)).toHaveBeenCalled()
})
it('renders a form level warning that is dismissible', () => {
props.showFormErrorsAndWarnings = true
vi.mocked(getFormWarningsForSelectedStep).mockReturnValue([
{
type: 'TIP_POSITIONED_LOW_IN_TUBE',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
}))
const timeline = useSelector(getRobotStateTimeline)
const [toolboxStep, setToolboxStep] = useState<number>(0)
const [
showFormErrorsAndWarnings,
setShowFormErrorsAndWarnings,
] = useState<boolean>(false)
const [showFormErrors, setShowFormErrors] = useState<boolean>(false)
const [tab, setTab] = useState<LiquidHandlingTab>('aspirate')
const visibleFormWarnings = getVisibleFormWarnings({
focusedField,
Expand All @@ -140,7 +137,7 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
...dynamicFormLevelErrorsForUnsavedForm,
],
page: toolboxStep,
showErrors: showFormErrorsAndWarnings,
showErrors: showFormErrors,
})
const [isRename, setIsRename] = useState<boolean>(false)
const icon = stepIconsByType[formData.stepType]
Expand Down Expand Up @@ -187,7 +184,6 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
})
}
}

const handleSaveClick = (): void => {
if (canSave) {
const duration = new Date().getTime() - analyticsStartTime.getTime()
Expand All @@ -212,7 +208,7 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
)
dispatch(analyticsEvent(stepDuration))
} else {
setShowFormErrorsAndWarnings(true)
setShowFormErrors(true)
if (tab === 'aspirate' && isDispenseError && !isAspirateError) {
setTab('dispense')
}
Expand All @@ -227,9 +223,9 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
if (isMultiStepToolbox && toolboxStep === 0) {
if (!isErrorOnCurrentPage) {
setToolboxStep(1)
setShowFormErrorsAndWarnings(false)
setShowFormErrors(false)
} else {
setShowFormErrorsAndWarnings(true)
setShowFormErrors(true)
handleScrollToTop()
}
} else {
Expand Down Expand Up @@ -279,7 +275,7 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
width="100%"
onClick={() => {
setToolboxStep(0)
setShowFormErrorsAndWarnings(false)
setShowFormErrors(false)
}}
>
{i18n.format(t('shared:back'), 'capitalize')}
Expand Down Expand Up @@ -308,7 +304,7 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
<FormAlerts
focusedField={focusedField}
dirtyFields={dirtyFields}
showFormErrorsAndWarnings={showFormErrorsAndWarnings}
showFormErrors={showFormErrors}
page={toolboxStep}
/>
<ToolsComponent
Expand All @@ -318,9 +314,9 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
focusHandlers,
toolboxStep,
visibleFormErrors,
showFormErrors: showFormErrorsAndWarnings,
showFormErrors,
focusedField,
setShowFormErrorsAndWarnings,
setShowFormErrors,
tab,
setTab,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function MoveLiquidTools(props: StepFormProps): JSX.Element {
propsForFields,
formData,
visibleFormErrors,
setShowFormErrorsAndWarnings,
setShowFormErrors,
tab,
setTab,
} = props
Expand Down Expand Up @@ -101,7 +101,7 @@ export function MoveLiquidTools(props: StepFormProps): JSX.Element {
isActive: tab === 'aspirate',
onClick: () => {
setTab('aspirate')
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
},
}
const dispenseTab = {
Expand All @@ -110,7 +110,7 @@ export function MoveLiquidTools(props: StepFormProps): JSX.Element {
isActive: tab === 'dispense',
onClick: () => {
setTab('dispense')
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
},
}
const hideWellOrderField =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ import type { ChangeEvent } from 'react'
import type { StepFormProps } from '../../types'

export function PauseTools(props: StepFormProps): JSX.Element {
const {
propsForFields,
visibleFormErrors,
setShowFormErrorsAndWarnings,
} = props
const { propsForFields, visibleFormErrors, setShowFormErrors } = props

const tempModuleLabwareOptions = useSelector(
uiModuleSelectors.getTemperatureLabwareOptions
Expand Down Expand Up @@ -101,7 +97,7 @@ export function PauseTools(props: StepFormProps): JSX.Element {
<RadioButton
onChange={(e: ChangeEvent<any>) => {
propsForFields.pauseAction.updateValue(e.currentTarget.value)
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
}}
buttonLabel={t(
'form:step_edit_form.field.pauseAction.options.untilResume'
Expand All @@ -113,7 +109,7 @@ export function PauseTools(props: StepFormProps): JSX.Element {
<RadioButton
onChange={(e: ChangeEvent<any>) => {
propsForFields.pauseAction.updateValue(e.currentTarget.value)
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
}}
buttonLabel={t(
'form:step_edit_form.field.pauseAction.options.untilTime'
Expand All @@ -125,7 +121,7 @@ export function PauseTools(props: StepFormProps): JSX.Element {
<RadioButton
onChange={(e: ChangeEvent<any>) => {
propsForFields.pauseAction.updateValue(e.currentTarget.value)
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
}}
buttonLabel={t(
'form:step_edit_form.field.pauseAction.options.untilTemperature'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function ThermocyclerTools(props: StepFormProps): JSX.Element {
showFormErrors = true,
visibleFormErrors,
focusedField,
setShowFormErrorsAndWarnings,
setShowFormErrors,
} = props
const { t } = useTranslation('form')

Expand All @@ -49,7 +49,7 @@ export function ThermocyclerTools(props: StepFormProps): JSX.Element {
onChange={() => {
setContentType('thermocyclerState')
propsForFields.thermocyclerFormType.updateValue('thermocyclerState')
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
}}
isSelected={contentType === 'thermocyclerState'}
/>
Expand All @@ -64,7 +64,7 @@ export function ThermocyclerTools(props: StepFormProps): JSX.Element {
propsForFields.thermocyclerFormType.updateValue(
'thermocyclerProfile'
)
setShowFormErrorsAndWarnings?.(false)
setShowFormErrors?.(false)
}}
isSelected={contentType === 'thermocyclerProfile'}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface StepFormProps {
visibleFormErrors: StepFormErrors
showFormErrors: boolean
focusedField?: string | null
setShowFormErrorsAndWarnings?: React.Dispatch<React.SetStateAction<boolean>>
setShowFormErrors?: React.Dispatch<React.SetStateAction<boolean>>
tab: LiquidHandlingTab
setTab: React.Dispatch<React.SetStateAction<LiquidHandlingTab>>
}

0 comments on commit 0110e17

Please sign in to comment.