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

[Pre-release] Enable bulk invitations on onboarding step #835

Merged
merged 21 commits into from
Sep 19, 2023

Conversation

gazayas
Copy link
Contributor

@gazayas gazayas commented Aug 10, 2023

Joint PR

Note:
This PR is shipping a new feature that will be disabled by default. The feature is only partially complete, but we want to get this merged so that other team members can work on additional parts of the feature.

If you'd like to opt-in to this work-in-progress feature, you can add a line to config/initializers/bullet_train.rb like this:

  # Enable bulk invitations on the user onboarding step.
  config.enable_bulk_invitations = true

@gazayas gazayas force-pushed the features/onboarding-invitations branch from a61c20d to 0ae8bed Compare August 19, 2023 14:04
@gazayas
Copy link
Contributor Author

gazayas commented Aug 19, 2023

All of the core tests are working! This one is ready for review now.

@gazayas gazayas marked this pull request as ready for review August 19, 2023 14:33
@jagthedrummer
Copy link
Contributor

@gazayas this looks like a super handy feature, but I wonder if we should make a config setting that controls whether it's active or not. It's a pretty big new change and I'm not sure we want to force it on people who have an existing app running. If they have custom tests that cover sign-up & any custom onboarding flows that they've built then this change would break all of those tests.

Maybe we could add a toggle to config/initializers/bullet_train.rb and have it default to being turned off? (And possibly have bin/configure toggle it to on so that new apps get it by default?)

@gazayas
Copy link
Contributor Author

gazayas commented Aug 23, 2023

@jagthedrummer Done!

bin/configure Outdated
end
line
end
File.write("config/initializers/bullet_train.rb", bt_config_lines.join)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@jagthedrummer
Copy link
Contributor

@gazayas, that looks great! There's just one test failing both on the Core: tests here, and on the joint PR in core. Once that's fixed up I think this should be good to go.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 24, 2023

@jagthedrummer Hmm, I'm not quite sure what's going on with the OpenAPI test, but that's the only one that's failing when HIDE_THINGS is true. It looks like we have null: true in the migration?

add_reference :memberships, :added_by, null: true, foreign_key: {to_table: :memberships}

I'm also not entirely sure what removing TangibleThings has to do with this 🤔 Any thoughts?

I got the other tests to pass, as well as the tests in the joint PR by the way.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 24, 2023

I'll work on the merge conflict here, I also saw that #912 was opened though so I might wait until we resolve that because the only test that's failing here is the OpenAPI test for Core: Minitest with HIDE_THINGS.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 24, 2023

Yeah, since the OpenAPI stuff is revolving around Invitations API and the subject of this PR is invitations, I'll go ahead and wait a bit.

@gazayas
Copy link
Contributor Author

gazayas commented Aug 28, 2023

@jagthedrummer Besides the release tests (as expected), the tests are passing!

Copy link
Contributor

@jagthedrummer jagthedrummer left a comment

Choose a reason for hiding this comment

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

@gazayas I just pulled this branch down and gave it a run. I have a few more suggestions that I'm going to put here, just so its' all in one place. I realize some of the actual changes may need to happen in the joint PR in core.

  1. Let's change Role ids to just Role on the form.
    CleanShot 2023-08-28 at 11 21 39

  2. I think it should be possible to bulk-invite fewer than three people on this screen. What if there are only one or two other people on my team?

Here I try to submit a single invitation:
CleanShot 2023-08-28 at 11 24 40

And it complains about all three being empty, and it doesn't retain the one email address and role that I did submit.
CleanShot 2023-08-28 at 11 24 53

In the console I see three of this error:

Unpermitted parameter: :role_ids.
  1. As I noted in an inline comment, the test for not skipping this screen isn't being run in CI because the feature defaults to being turned off. I think we can manually set that config in the test setup, and then restore it during teardown.

require "application_system_test_case"

class InvitationListsTest < ApplicationSystemTestCase
if bulk_invitations_enabled?
Copy link
Contributor

Choose a reason for hiding this comment

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

This test isn't running because we default to this feature being turned off. I think this test should change the config setting prior to test setup to ensure that this test always run. (And it should restore the original setting afterwards.)

@gazayas
Copy link
Contributor Author

gazayas commented Aug 29, 2023

@jagthedrummer Thanks for the review! Here are some thoughts.

  1. Let's change Role ids to just Role on the form.

Done!

  1. I think it should be possible to bulk-invite fewer than three people on this screen. What if there are only one or two other people on my team?

I've been instructed to do three for now, and was told another developer on the team will work on a stimulus controller so we can adjust the amount of people we can invite for these invitations. If anything, I can just set it to one and make a note about the other developer adjusting the JS.

Also, concerning roles_ids, I was under the impression that we had to make this a single attribute when I received the instructions for the task, but now that I'm working through it I'd like to add html_options: {multiple: true} to the select element. In doing so we would leave the adding of roles up to the discretion of the developer, but it would work seamlessly with Membership creation and it also makes sense with how we currently set roles for single invitations via multiple checkboxes.

Also, will look into making the page with errors retain the values, not quite sure what the cause is right now.

  1. As I noted in an inline comment, the test for not skipping this screen isn't being run in CI because the feature defaults to being turned off. I think we can manually set that config in the test setup, and then restore it during teardown.

I went ahead and edited the tests so that they run regardless of the setting in config/initializers/bullet_train.rb.

@jagthedrummer
Copy link
Contributor

@gazayas, thanks for the info about the JS portion of this. Are we planning to wait and have that be a part of this PR? Or are we wanting to merge this and then follow up later with the JS stuff? And, if we're planning to wait, is there some way to make the controller just be forgiving about one or more of those email addresses being empty?

I think making roles a multi select makes sense given that you can assign multiple roles in other places within the app. (Related, it might be nice to have a BT config option that toggles the multiple setting for roles across the whole app. (As a different issue/PR.))

@gazayas
Copy link
Contributor Author

gazayas commented Aug 30, 2023

@jagthedrummer I made Roles multiple, and the placeholder now has Default since users technically don't have to define a role when sending an invite. I feel much better about this now because with this I don't have to fidget with role_ids, and I can use it as is.

With that being said, I'm having trouble getting the emails to reappear in the fields after the validations fail. Right now, for the invitation form for example, I'm passing a new Invitation object:

<%= form.fields_for :invitations, Invitation.new do |invitation_form| %>
  ...
<% end %>

I'm seeing though in other invocations we have of fields_for, it looks a little different:

https://github.com/bullet-train-co/bullet_train-core/blob/0755711ac7bae4cd05fff417df5445086b78fa15/bullet_train/app/views/account/invitations/_form.html.erb#L20

I'm assuming this is the issue since the controller has render :new in the create action, and I believe that the new view should retain the information since it's being called from the create action. Not quite sure how to handle this, especially considering that we will in theory be able to add/delete new nested forms with the JS we plan on adding later. Kinda lost on this part right now 😞

With that being said, I changed the invitation list to only send one invitation because I believe we will implement the JS in another PR.

Last thing: I also changed the errors so it shows one general error like Email can't be blank as opposed to Invitation email can't be blank for every single object.

@jagthedrummer
Copy link
Contributor

@gazayas, I just pulled down this branch and gave it another run and I think things are looking good for the portion that we're trying to implement in this PR.

Since we're not really considering this to be a completed feature (due to the JS portion for "add more team members") I think we should probably disable this bit from bin/configure for now. And then re-enable it when we ship the JS portion that will complete the feature.

https://github.com/bullet-train-co/bullet_train/pull/835/files#diff-1d9e0f07dcb2a76e98c85d6aa5c96b7bc60c14fd489570590950b54e0c35f9f4R177-R185

Other than than I think we can merge this once merge conflicts are resolved and tests are passing in both PRs.

@gazayas
Copy link
Contributor Author

gazayas commented Sep 14, 2023

@jagthedrummer Done!

@jagthedrummer jagthedrummer changed the title Enable bulk invitations on onboarding step [Pre-release] Enable bulk invitations on onboarding step Sep 19, 2023
@jagthedrummer jagthedrummer merged commit 8d652ac into main Sep 19, 2023
6 of 8 checks passed
@jagthedrummer jagthedrummer deleted the features/onboarding-invitations branch September 19, 2023 16:55
newstler pushed a commit that referenced this pull request Oct 9, 2023
* Prepare database for invitation lists

* Skip bulk invitation step in most system tests

* Add tests for bulk invitations

* Fixing Standard Ruby

* Add another assertion for InvitationList

* Extract invitation lists test logic to its own file

* Add another skip in invitations test

* Add comment in BT initializer for bulk invitations

* Only test bulk invitations if enabled

* Enable bulk invitations on bin/configure step

* Fixing Standard Ruby

* Edit tests to always run invitation lists system tests

* Update schema

* Remove non-existent error assertion

* Show correct error message in invitation lists test

* Try to fix invitation lists test

* Remove syntax error

* Fixing Standard Ruby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants