Skip to content

PORTALS-2624: remove bootstrap-4-backport class from CreateProjectModal #158

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

Merged

Conversation

hallieswan
Copy link
Contributor

Before:
main_CreateProjectModal

After:
feature_CreateProjectModal

@hallieswan hallieswan force-pushed the PORTALS-2624_CreateProjectModal branch from 77eadf6 to 9f1aa5a Compare April 25, 2023 18:58
@hallieswan hallieswan force-pushed the PORTALS-2624_CreateProjectModal branch from 9f1aa5a to cdb0407 Compare April 25, 2023 19:05
Comment on lines +55 to +56
inputProps={{
onKeyDown: (event: React.KeyboardEvent<HTMLInputElement>) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TextField doesn't expose onKeyDown as a prop, so pass to Input via inputProps, see here

Copy link
Collaborator

Choose a reason for hiding this comment

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

Makes sense. Ideally this would all be wrapped in a form and confirm button would trigger the form submission event so we don't have to add this custom handler. I'm guessing that was originally difficult to do with a Bootstrap modal and probably equally difficult in a MUI Dialog.

content={dialogContent}
confirmButtonText="Save"
onConfirm={onCreateProject}
onCancel={hide}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, clicking the modal close button called hide, which cleared the alert and text entered into the input before calling onClose whereas clicking "Cancel" only called onClose.

Now, ConfirmationDialog will call hide both when clicking "Cancel" or when clicking the modal close button.

Comment on lines +56 to +61
it('Creates project on enter', async () => {
const { user, input, saveButton } = setUp()

await user.type(input, MOCK_PROJECT_NAME)
expect(input.value).toBe(MOCK_PROJECT_NAME)
await user.keyboard('{ENTER}')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Separate test for pressing enter rather than clicking "Save" button

Comment on lines +78 to +108
it('Clears alert and project name on cancel', async () => {
const { user, input, saveButton } = setUp()

await user.type(input, MOCK_INVALID_PROJECT_NAME)
await user.click(saveButton)

const alert = await screen.findByRole('alert')
expect(alert).toHaveTextContent('Invalid project name')

const cancelButton = screen.getByRole('button', { name: /cancel/i })
await user.click(cancelButton)

expect(alert).not.toBeInTheDocument()
expect(input.value).toBe('')
})

it('Clears alert and project name on closing dialog', async () => {
const { user, input, saveButton } = setUp()

await user.type(input, MOCK_INVALID_PROJECT_NAME)
await user.click(saveButton)

const alert = await screen.findByRole('alert')
expect(alert).toHaveTextContent('Invalid project name')

const closeButton = screen.getByRole('button', { name: /close/i })
await user.click(closeButton)

expect(alert).not.toBeInTheDocument()
expect(input.value).toBe('')
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Test that clicking "Cancel" button or clicking modal close button result in the same side effects

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you for this thorough testing backfill!

onConfirm: () => void
onConfirm: () => unknown | Promise<void>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update type to handle CreateProjectModal passing an async function (onCreateProject) to onConfirm. Using unknown rather than void because Typescript doesn't handle the union type of void and Promise<void>, see here. I wasn't sure if there was a better way to handle this, so happy to adjust as needed!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nothing is listening to onConfirm, so it doesn't need to return a promise. You could just do onConfirm: () => void and then in code wrap an asynchronous call in a non-async function.

async function callback(): Promise<void> {
 //...
}
//...
return <ConfirmationDialog
        onConfirm={() => {
          callback()
        }}
  />

In IntelliJ (not sure about VSCode), this shows a warning that the returned value of the promise is ignored. Apparently, we can use the void operator to return undefined and essentially assert that we don't care about the result. See StackOverflow.

So it seems like the best thing to do would be to use () => void and write the prop as:

<ConfirmationDialog
    onConfirm={() => {
      void callback()
    }}
  />

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, thanks for the better solution and explanation! I'll update in the next commit

@hallieswan hallieswan marked this pull request as ready for review April 25, 2023 21:52
@hallieswan hallieswan requested a review from nickgros April 25, 2023 21:52
Copy link
Collaborator

@nickgros nickgros left a comment

Choose a reason for hiding this comment

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

Suggest reverting the prop to () => void as mentioned, but otherwise changes look great!

@hallieswan hallieswan merged commit 88909a3 into Sage-Bionetworks:main Apr 26, 2023
@hallieswan hallieswan deleted the PORTALS-2624_CreateProjectModal branch April 26, 2023 17:23
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