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

refactor(protocol-designer): migrate i18n instances to use useTranslation hook #14326

Merged
merged 14 commits into from
Jan 18, 2024

Conversation

jerader
Copy link
Collaborator

@jerader jerader commented Jan 17, 2024

closes RAUT-542

Overview

This PR fixes all instances of i18n in the protocol-designer directory by using the useTranslation hook instead. This is because the previous way we were doing it wasn't properly implementing react-i18next.

Additionally, several usages of the class components + connect function were refactored in order to use the useTranslation hook properly (this is part of a chore that needs to be done anyway to remove all the class components)

Test Plan

Smoke test PD, try to go through every flow as much as possible and call out anything that doesn't work correctly or whitescreens.

Here is the sandbox to smoke test on: https://sandbox.designer.opentrons.com/pd_update-i18n/

Changelog

  • update i18ninit function
  • update the i18next and react-i18next dependencies to be the latest
  • update all instances of i18n in the components
  • fix tests
  • refactor several class components + connect functions

Review requests

see test plan

Risk assessment

medium-ish since it touches a bunch of code but it'll be internal

Copy link

codecov bot commented Jan 17, 2024

Codecov Report

Attention: 509 lines in your changes are missing coverage. Please review.

Comparison is base (15ece39) 68.13% compared to head (a5c98c6) 68.05%.
Report is 2 commits behind head on edge.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #14326      +/-   ##
==========================================
- Coverage   68.13%   68.05%   -0.09%     
==========================================
  Files        2512     2505       -7     
  Lines       71478    71621     +143     
  Branches     9077     9084       +7     
==========================================
+ Hits        48705    48739      +34     
- Misses      20670    20772     +102     
- Partials     2103     2110       +7     
Flag Coverage Δ
app 65.49% <ø> (-0.05%) ⬇️
protocol-designer 34.88% <11.47%> (-0.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...omponents/BatchEditForm/makeBatchEditFieldProps.ts 100.00% <100.00%> (ø)
...c/components/LabwareSelectionModal/LabwareItem.tsx 58.33% <100.00%> (+3.78%) ⬆️
...l-designer/src/components/LiquidPlacementModal.tsx 0.00% <ø> (ø)
.../components/StepEditForm/StepEditFormComponent.tsx 0.00% <ø> (ø)
...tepEditForm/fields/PathField/getDisabledPathMap.ts 0.00% <ø> (ø)
...ts/StepEditForm/fields/makeSingleEditFieldProps.ts 90.90% <100.00%> (ø)
...ents/StepEditForm/forms/HeaterShakerForm/index.tsx 88.88% <100.00%> (+1.38%) ⬆️
...rotocol-designer/src/components/alerts/PDAlert.tsx 80.00% <100.00%> (+5.00%) ⬆️
...als/AutoAddPauseUntilHeaterShakerTempStepModal.tsx 100.00% <100.00%> (ø)
...mponents/modals/AutoAddPauseUntilTempStepModal.tsx 100.00% <100.00%> (ø)
... and 120 more

... and 9 files with indirect coverage changes

@jerader jerader changed the title refactor(protocol-designer): use useTranslation hook for all i18n instances refactor(protocol-designer): migrate i18n instances to using useTranslation hook Jan 17, 2024
@jerader jerader marked this pull request as ready for review January 17, 2024 20:47
@jerader jerader requested a review from a team January 17, 2024 20:47
@jerader jerader requested a review from a team as a code owner January 17, 2024 20:47
@jerader jerader requested a review from b-cooper January 17, 2024 20:47
@jerader jerader changed the title refactor(protocol-designer): migrate i18n instances to using useTranslation hook refactor(protocol-designer): migrate i18n instances to use useTranslation hook Jan 17, 2024
@@ -41,7 +41,7 @@
"react-dnd": "6.0.0",
"react-dnd-mouse-backend": "0.1.2",
"react-dom": "18.2.0",
"react-i18next": "13.5.0",
"react-i18next": "14.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess If 13.5.0 works for PD, it will be good to keep the same version as well as app.
Also, we could move these two packages into the top level package.json like app-shell and app-shell-odd do.

@koji
Copy link
Contributor

koji commented Jan 18, 2024

Seems that minimum (5} uL part would have an issue.

2024-01-18 14_34_38-Opentrons Protocol Designer BETA

</a>
<a className={styles.overlay_button} onClick={deleteLabware}>
{!isOver && <Icon className={styles.overlay_icon} name="close" />}
{i18n.t('deck.overlay.edit.delete')}
{'Delete'}
Copy link
Contributor

Choose a reason for hiding this comment

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

question
Any specific reason to pass the word directly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i'll fix this in a follow up pr where i remove the usage of all connect functions. I think i was lazy here and just changed it to not using i18n 😓

@@ -37,37 +37,53 @@ export interface WellOrderModalProps {
firstValue?: WellOrderOption | null,
secondValue?: WellOrderOption | null
) => void
t: any
Copy link
Contributor

@koji koji Jan 18, 2024

Choose a reason for hiding this comment

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

oh, we need to upgrade packages...
https://www.i18next.com/overview/typescript

Could you leave a comment?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, for some reason the t was typing as any so i left it as any whenever i needed to use it as a prop. I'll link this url in the comment!

@@ -36,21 +37,20 @@ export const ErrorContents = (
case 'NO_TIP_ON_PIPETTE':
return (
<>
{i18n.t(`alert.timeline.error.${props.errorType}.body1`)}
{t(`timeline.error.${props.errorType}.body1`)}
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe deconstruct props in the future?

import { selectors as loadFileSelectors } from './load-file'

export const initialize = (store: Record<string, any>): void => {
if (process.env.NODE_ENV === 'production') {
window.onbeforeunload = (_e: unknown) => {
// NOTE: the custom text will be ignored in modern browsers
return loadFileSelectors.getHasUnsavedChanges(store.getState())
? i18n.t('alert.window.confirm_leave')
? 'Are you sure you want to leave? You will lose any unsaved changes.'
Copy link
Contributor

Choose a reason for hiding this comment

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

don't need to add this text to a json file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i am not sure how to import the useTranslation hook here since this const is used to initialize redux. I left a comment to go back to it though. After all the connect fns are refactored out, i can do an audit of the remainder text that is not in i18n yet.


export const getModuleShortNames = (type: ModuleType): string => {
switch (type) {
case 'heaterShakerModuleType':
Copy link
Contributor

@koji koji Jan 18, 2024

Choose a reason for hiding this comment

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

maybe importing const from shared-data would be good?

import { 
  HEATERSHAKER_MODULE_TYPE,
  MAGNETIC_MODULE_TYPE,
  TEMPERATURE_MODULE_TYPE,
  THERMOCYCLER_MODULE_TYPE
} from ''

@koji koji self-requested a review January 18, 2024 21:03
Copy link
Contributor

@koji koji left a comment

Choose a reason for hiding this comment

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

Did the smoke test and didn't see any typical text display issue on PD.
Thank you for converting class component -> functional component! That is awesome.

@jerader jerader merged commit 6b725a2 into edge Jan 18, 2024
22 of 23 checks passed
@jerader jerader deleted the pd_update-i18n branch January 18, 2024 21:17
mjhuff pushed a commit that referenced this pull request Jan 23, 2024
ncdiehl11 pushed a commit that referenced this pull request Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants