-
Notifications
You must be signed in to change notification settings - Fork 179
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
feat(protocol-designer): wire up rename step #16437
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
be90fc3
feat(protocol-designer): wire up rename step
446d856
Merge branch 'edge' into protocol_designer-rename-step
f966158
create RenameStepModal
fdfb6cd
link save rename step name
ced0262
add max length
540ac71
add step notes
b990bb6
format file
21c912f
add test
cbe1898
solve unsafe type
26df497
solve null stepDetails
b4b4e54
cast stepDetails to String
be789f5
update max step name length to 60 and add CHANGE_STEP_DETAILS type to…
b58acff
update test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
protocol-designer/src/organisms/RenameStepModal/__tests__/RenameStepModal.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { fireEvent, screen } from '@testing-library/react' | ||
import { describe, it, beforeEach, vi, expect } from 'vitest' | ||
import { renderWithProviders } from '../../../__testing-utils__' | ||
import { i18n } from '../../../assets/localization' | ||
import { PAUSE_UNTIL_RESUME } from '../../../constants' | ||
import { renameStep } from '../../../labware-ingred/actions' | ||
import { RenameStepModal } from '..' | ||
|
||
vi.mock('../../../labware-ingred/actions') | ||
|
||
const render = (props: React.ComponentProps<typeof RenameStepModal>) => { | ||
return renderWithProviders(<RenameStepModal {...props} />, { | ||
i18nInstance: i18n, | ||
})[0] | ||
} | ||
|
||
describe('EditNickNameModal', () => { | ||
let props: React.ComponentProps<typeof RenameStepModal> | ||
|
||
beforeEach(() => { | ||
props = { | ||
onClose: vi.fn(), | ||
formData: { | ||
stepType: 'pause', | ||
id: 'test_id', | ||
pauseAction: PAUSE_UNTIL_RESUME, | ||
description: 'some description', | ||
pauseMessage: 'some message', | ||
stepName: 'pause', | ||
stepDetails: '', | ||
}, | ||
} | ||
}) | ||
it('renders the text and add a step name and a step notes', () => { | ||
render(props) | ||
screen.getByText('Name step') | ||
screen.getByText('Step Name') | ||
screen.getByText('Step Notes') | ||
|
||
fireEvent.click(screen.getByText('Cancel')) | ||
expect(props.onClose).toHaveBeenCalled() | ||
|
||
const stepName = screen.getAllByRole('textbox', { name: '' })[0] | ||
fireEvent.change(stepName, { target: { value: 'mockStepName' } }) | ||
|
||
const stepDetails = screen.getAllByRole('textbox', { name: '' })[1] | ||
fireEvent.change(stepDetails, { target: { value: 'mockStepDetails' } }) | ||
|
||
fireEvent.click(screen.getByText('Save')) | ||
expect(vi.mocked(renameStep)).toHaveBeenCalled() | ||
expect(props.onClose).toHaveBeenCalled() | ||
}) | ||
it('renders the too long step name error', () => { | ||
render(props) | ||
const stepName = screen.getAllByRole('textbox', { name: '' })[0] | ||
fireEvent.change(stepName, { | ||
target: { | ||
value: | ||
'mockStepNameisthelongeststepnameihaveeverseen mockstepNameisthelongeststepnameihaveeverseen mockstepNameisthelongest', | ||
}, | ||
}) | ||
screen.getByText('Oops! Your step name is too long.') | ||
}) | ||
}) |
129 changes: 129 additions & 0 deletions
129
protocol-designer/src/organisms/RenameStepModal/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { useState } from 'react' | ||
import { useDispatch } from 'react-redux' | ||
import { useTranslation } from 'react-i18next' | ||
import { createPortal } from 'react-dom' | ||
import styled from 'styled-components' | ||
import { | ||
BORDERS, | ||
COLORS, | ||
DIRECTION_COLUMN, | ||
Flex, | ||
JUSTIFY_END, | ||
Modal, | ||
PrimaryButton, | ||
SecondaryButton, | ||
SPACING, | ||
StyledText, | ||
TYPOGRAPHY, | ||
InputField, | ||
} from '@opentrons/components' | ||
import { i18n } from '../../assets/localization' | ||
import { getTopPortalEl } from '../../components/portals/TopPortal' | ||
import { renameStep } from '../../labware-ingred/actions' | ||
import type { FormData } from '../../form-types' | ||
|
||
const MAX_STEP_NAME_LENGTH = 60 | ||
interface RenameStepModalProps { | ||
formData: FormData | ||
onClose: () => void | ||
} | ||
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 [stepName, setStepName] = useState<string>(initialName) | ||
const [stepDetails, setStepDetails] = useState<string>( | ||
String(formData.stepDetails) | ||
) | ||
|
||
const handleSave = (): void => { | ||
const { stepId } = formData | ||
dispatch( | ||
renameStep({ | ||
stepId, | ||
update: { | ||
stepName: stepName, | ||
stepDetails: stepDetails, | ||
}, | ||
}) | ||
) | ||
onClose() | ||
} | ||
|
||
return createPortal( | ||
<Modal | ||
title={t('shared:name_step')} | ||
type="info" | ||
closeOnOutsideClick | ||
onClose={onClose} | ||
childrenPadding={SPACING.spacing24} | ||
footer={ | ||
<Flex | ||
justifyContent={JUSTIFY_END} | ||
padding={`0 ${SPACING.spacing24} ${SPACING.spacing24}`} | ||
gridGap={SPACING.spacing8} | ||
> | ||
<SecondaryButton onClick={onClose}> | ||
{t('shared:cancel')} | ||
</SecondaryButton> | ||
<PrimaryButton | ||
data-testid="RenameStepModal_saveButton" | ||
disabled={stepName.length >= MAX_STEP_NAME_LENGTH} | ||
onClick={() => { | ||
handleSave() | ||
}} | ||
> | ||
{t('shared:save')} | ||
</PrimaryButton> | ||
</Flex> | ||
} | ||
> | ||
<form> | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing12}> | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}> | ||
<StyledText color={COLORS.grey60} desktopStyle="captionRegular"> | ||
{t('form:step_edit_form.field.step_name.label')} | ||
</StyledText> | ||
<InputField | ||
error={ | ||
stepName.length >= MAX_STEP_NAME_LENGTH | ||
? t('protocol_steps:rename_error') | ||
: null | ||
} | ||
value={stepName} | ||
autoFocus | ||
onChange={e => { | ||
setStepName(e.target.value) | ||
}} | ||
type="text" | ||
/> | ||
</Flex> | ||
<Flex flexDirection={DIRECTION_COLUMN} gridGap={SPACING.spacing4}> | ||
<StyledText color={COLORS.grey60} desktopStyle="captionRegular"> | ||
{t('form:step_edit_form.field.step_notes.label')} | ||
</StyledText> | ||
|
||
<DescriptionField | ||
value={stepDetails} | ||
onChange={e => { | ||
setStepDetails(e.target.value) | ||
}} | ||
/> | ||
</Flex> | ||
</Flex> | ||
</form> | ||
</Modal>, | ||
getTopPortalEl() | ||
) | ||
} | ||
|
||
const DescriptionField = styled.textarea` | ||
min-height: 5rem; | ||
width: 100%; | ||
border: ${BORDERS.lineBorder}; | ||
border-radius: ${BORDERS.borderRadius4}; | ||
padding: ${SPACING.spacing8}; | ||
font-size: ${TYPOGRAPHY.fontSizeH3}; | ||
resize: none; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.