Skip to content

Commit

Permalink
fix(protocol-designer): timeline warnings appear when reopening form (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader authored Oct 30, 2024
1 parent 094be6e commit cbadc4d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
38 changes: 24 additions & 14 deletions protocol-designer/src/organisms/Alerts/FormAlerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ import type { ProfileFormError } from '../../steplist/formLevel/profileErrors'
import type { MakeAlert } from './types'

interface FormAlertsProps {
showFormErrorsAndWarnings: boolean
focusedField?: StepFieldName | null
dirtyFields?: StepFieldName[]
}

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

const { t } = useTranslation('alert')
const dispatch = useDispatch()
const formLevelErrorsForUnsavedForm = useSelector(
Expand Down Expand Up @@ -120,17 +122,13 @@ function FormAlertsComponent(props: FormAlertsProps): JSX.Element | null {
</Banner>
</Flex>
)

const formErrors = [
...visibleFormErrors.reduce((acc, error) => {
return error.showAtForm ?? true
? {
...acc,
title: error.title,
description: error.body || null,
showAtForm: error.showAtForm ?? true,
}
: acc
}, []),
...visibleFormErrors.map(error => ({
title: error.title,
description: error.body ?? null,
showAtForm: error.showAtForm ?? true,
})),
...visibleDynamicFieldFormErrors.map(error => ({
title: error.title,
description: error.body || null,
Expand Down Expand Up @@ -161,14 +159,26 @@ function FormAlertsComponent(props: FormAlertsProps): JSX.Element | null {
)
}
}
return [...formErrors, ...formWarnings, ...timelineWarnings].length > 0 ? (

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 ? (
<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))}
{timelineWarnings.map((warning, key) =>
makeAlert('warning', warning, key)
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('FormAlerts', () => {
props = {
focusedField: null,
dirtyFields: [],
showFormErrorsAndWarnings: false,
}
vi.mocked(getFormLevelErrorsForUnsavedForm).mockReturnValue([])
vi.mocked(getFormWarningsForSelectedStep).mockReturnValue([])
Expand All @@ -62,6 +63,7 @@ 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 @@ -244,9 +244,11 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element {
</Flex>
}
>
{showFormErrorsAndWarnings ? (
<FormAlerts focusedField={focusedField} dirtyFields={dirtyFields} />
) : null}
<FormAlerts
focusedField={focusedField}
dirtyFields={dirtyFields}
showFormErrorsAndWarnings={showFormErrorsAndWarnings}
/>
<ToolsComponent
{...{
formData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function MoveLiquidTools(props: StepFormProps): JSX.Element {
nozzles={String(propsForFields.nozzles.value) ?? null}
hasFormError={
visibleFormErrors?.some(error =>
error.dependentFields.includes('aspirate_labware')
error.dependentFields.includes('aspirate_wells')
) ?? false
}
/>
Expand Down

0 comments on commit cbadc4d

Please sign in to comment.