From dcc8f76d6be83ff2900a695cbdccf6d2d6c66cce Mon Sep 17 00:00:00 2001 From: syao1226 <146495172+syao1226@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:30:12 -0400 Subject: [PATCH] fix(protocol-designer): preserve uppercase letters of step name (#16584) fixes RQA-3398 # Overview Fixes the issue where renaming a step name with uppercase characters caused everything after the first character to be lowercased. ## Test Plan and Hands on Testing ## Changelog - added a `capitalizeFirstLetter()` to `StepForm/utils` to capitalize onlt the first character while leaving the rest of the string unchanged ## Review requests ## Risk assessment --------- Co-authored-by: shiyaochen --- .../src/organisms/RenameStepModal/index.tsx | 6 +++--- .../ProtocolSteps/StepForm/StepFormToolbox.tsx | 3 ++- .../ProtocolSteps/StepForm/__tests__/utils.test.ts | 14 +++++++++++++- .../pages/Designer/ProtocolSteps/StepForm/utils.ts | 3 +++ 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/protocol-designer/src/organisms/RenameStepModal/index.tsx b/protocol-designer/src/organisms/RenameStepModal/index.tsx index 2b98546751a..9ee1d607fbe 100644 --- a/protocol-designer/src/organisms/RenameStepModal/index.tsx +++ b/protocol-designer/src/organisms/RenameStepModal/index.tsx @@ -17,7 +17,7 @@ import { TYPOGRAPHY, InputField, } from '@opentrons/components' -import { i18n } from '../../assets/localization' +import { capitalizeFirstLetter } from '../../pages/Designer/ProtocolSteps/StepForm/utils' import { getTopPortalEl } from '../../components/portals/TopPortal' import { renameStep } from '../../labware-ingred/actions' import type { FormData } from '../../form-types' @@ -31,7 +31,7 @@ export function RenameStepModal(props: RenameStepModalProps): JSX.Element { const { onClose, formData } = props const dispatch = useDispatch() const { t } = useTranslation(['form', 'shared', 'protocol_steps']) - const initialName = i18n.format(t(formData.stepName), 'capitalize') + const initialName = capitalizeFirstLetter(String(formData.stepName)) const [stepName, setStepName] = useState(initialName) const [stepDetails, setStepDetails] = useState( String(formData.stepDetails) @@ -43,7 +43,7 @@ export function RenameStepModal(props: RenameStepModalProps): JSX.Element { renameStep({ stepId, update: { - stepName: stepName, + stepName: stepName !== '' ? stepName : initialName, stepDetails: stepDetails, }, }) diff --git a/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/StepFormToolbox.tsx b/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/StepFormToolbox.tsx index 1f5f5d0ac64..d18bee31915 100644 --- a/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/StepFormToolbox.tsx +++ b/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/StepFormToolbox.tsx @@ -39,6 +39,7 @@ import { getSaveStepSnackbarText, getVisibleFormErrors, getVisibleFormWarnings, + capitalizeFirstLetter, } from './utils' import type { StepFieldName } from '../../../../steplist/fieldLevel' import type { FormData, StepType } from '../../../../form-types' @@ -238,7 +239,7 @@ export function StepFormToolbox(props: StepFormToolboxProps): JSX.Element { word-break: break-all `} > - {i18n.format(t(formData.stepName), 'capitalize')} + {capitalizeFirstLetter(String(formData.stepName))} } diff --git a/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/__tests__/utils.test.ts b/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/__tests__/utils.test.ts index e95aad5d427..3d3e3a47393 100644 --- a/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/__tests__/utils.test.ts +++ b/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/__tests__/utils.test.ts @@ -3,7 +3,10 @@ import { SOURCE_WELL_BLOWOUT_DESTINATION, DEST_WELL_BLOWOUT_DESTINATION, } from '@opentrons/step-generation' -import { getBlowoutLocationOptionsForForm } from '../utils' +import { + capitalizeFirstLetter, + getBlowoutLocationOptionsForForm, +} from '../utils' describe('getBlowoutLocationOptionsForForm', () => { const destOption = { @@ -57,3 +60,12 @@ describe('getBlowoutLocationOptionsForForm', () => { expect(result).toEqual([]) }) }) + +describe('capitalizeFirstLetter', () => { + it('should capitalize the first letter of a step name and leave the rest unchanged', () => { + const stepName = 'move labware to D3 on top of Magnetic Block' + expect(capitalizeFirstLetter(stepName)).toBe( + 'Move labware to D3 on top of Magnetic Block' + ) + }) +}) diff --git a/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/utils.ts b/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/utils.ts index 9293b6b6c64..00f4749a71b 100644 --- a/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/utils.ts +++ b/protocol-designer/src/pages/Designer/ProtocolSteps/StepForm/utils.ts @@ -322,3 +322,6 @@ export const getSaveStepSnackbarText = ( return t(`protocol_steps:save_no_errors`, { stepType: stepTypeDisplayName }) } } + +export const capitalizeFirstLetter = (stepName: string): string => + `${stepName.charAt(0).toUpperCase()}${stepName.slice(1)}`