Skip to content

Add dev env user switcher#22016

Closed
mrmir wants to merge 2 commits intodevfrom
tooling/dev-mode-user-switcher
Closed

Add dev env user switcher#22016
mrmir wants to merge 2 commits intodevfrom
tooling/dev-mode-user-switcher

Conversation

@mrmir
Copy link
Contributor

@mrmir mrmir commented Feb 17, 2026

This PR adds a new development environment only dev_tools module. The intention is that this can be used to store anything that is useful for devs, but shouldn't ever be accessible on prod/shouldn't add to the main code base

For starters, I added the user switcher since that is something I wanted a few times. Perhaps the custom dev only icons/banner/styles that we currently have can also go in here

⚠️ Naturally, the code isn't prod ready and is mostly at a "this works well enough" stage for the actual component, since it was done rather quickly and with a lot of Claude assistance, but the module creation/structure should still be looked at properly

TODO

  • Move it to a separate gem so that it becomes opt-in via Gemfile.local
  • Markus can create a repo under opf

Copy link
Contributor

@toy toy left a comment

Choose a reason for hiding this comment

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

I like it a lot, thank you!
As you already told that you are going to move it to a new dev module, I just added few comments, but didn't review completely

@mrmir mrmir requested a review from toy February 27, 2026 17:15
@mrmir mrmir marked this pull request as ready for review February 27, 2026 17:16
@mrmir
Copy link
Contributor Author

mrmir commented Feb 27, 2026

@toy thanks for the early feedback. After moving it to a module, a lot of your comments are no longer valid, so maybe you can do another review when you have a bit

@mrmir
Copy link
Contributor Author

mrmir commented Feb 27, 2026

@klaustopher @cbliard @HDinger do you have any thoughts on this?

Copy link
Contributor

@toy toy left a comment

Choose a reason for hiding this comment

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

Already works great! (after fixing gemfile group) Otherwise a bunch of small improvement suggestions

end

group :development do
gem 'openproject-dev_tools', path: 'modules/dev_tools'
Copy link
Contributor

Choose a reason for hiding this comment

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

As it is internal only gem, Maybe better to specify require: "open_project/dev_tools" to not create the modules/dev_tools/lib/openproject-dev_tools.rb file?

s.license = "GPL-3.0"

s.files = Dir["{app,config,lib}/**/*"]
s.metadata["rubygems_mfa_required"] = "true"
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternative is to disable the rubocop rule # rubocop:disable Gemspec/RequireMFA for the gemspec block

Comment on lines +61 to +64
module OpenProject
module DevTools
end
end
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to create empty modules, as they will be created already in required file

gem 'ladle'
end

group :development do
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding it to development group instead of opf_plugins seem to load it too early (fails to find OpenProject::Plugins) and will not be found as a plugin, maybe better to stop loading in non dev environment in the Engine?

@@ -0,0 +1,9 @@
en:
dev_tools:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at few other plugins, we seem to use plugin_openproject_XXX namespace, so plugin_openproject_dev_tools

Copy link
Contributor

Choose a reason for hiding this comment

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

I am pretty sure that we don't do this consistently. E.g. storages is not plugin_storages.

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw that it was inconsistent, but longer namespace reduces the chance of conflict

Primer::Alpha::ActionMenu.new(
classes: "op-app-menu--item",
menu_id: "op-dev-user-switcher-menu",
anchor_align: :end
Copy link
Contributor

Choose a reason for hiding this comment

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

anchor_align doesn't seem to be needed, all items are aligned to the end on container level

button.with_leading_visual_icon(icon: :"person-add")
button.with_tooltip(text: I18n.t("dev_tools.user_switcher.tooltip"))

current_user_name
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to leave only the icon, for the item not to change size, and current user can be partially identified by the login icon

Comment on lines +48 to +49
menu.with_group do |group|
group.with_heading(title: I18n.t("dev_tools.user_switcher.active_users"))
Copy link
Contributor

Choose a reason for hiding this comment

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

As there is only one group, I think it is not needed and items can be added directly on the menu level

group.with_item(
href: dev_tools_switch_user_path(user_id: user.id),
label: user.name,
content_arguments: { data: { "turbo-method": "post" } }
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding select_variant: :single to Primer::Alpha::ActionMenu.new options and following allow showing current user in the list

Suggested change
content_arguments: { data: { "turbo-method": "post" } }
content_arguments: { data: { "turbo-method": "post" } },
active: user == User.current

<%=
render(
Primer::Alpha::ActionMenu.new(
classes: "op-app-menu--item",
Copy link
Contributor

Choose a reason for hiding this comment

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

If it is possible to somehow add order: 1 style, this item will be rendered at the end of the flex box

@HDinger
Copy link
Contributor

HDinger commented Mar 2, 2026

I see some dangers was that approach. People tend to copy things that they find and code, so adding half working components for the sake of development as usually risky.. Also I don't know how much sense it makes to invest time into frontend components for things that are never intended to be in the visible. I like the encapsulation in the module however I fear, this will be taken as reference although it shouldn't.

What is the use case behind the user switcher component? Maybe it makes sense to discuss that in person (perhaps in the dev open door)..

@mrmir
Copy link
Contributor Author

mrmir commented Mar 2, 2026

I see some dangers was that approach. People tend to copy things that they find and code, so adding half working components for the sake of development as usually risky.. Also I don't know how much sense it makes to invest time into frontend components for things that are never intended to be in the visible. I like the encapsulation in the module however I fear, this will be taken as reference although it shouldn't.

What is the use case behind the user switcher component? Maybe it makes sense to discuss that in person (perhaps in the dev open door)..

I think that's a fair point, thanks. The frontend being put together a bit haphazardly/without actual designs is to save time ofc, but it is true that these will then be visible to any dev searching for references in the codebase to copy. I'll add it to Wednesday's dev open door to get some more opinions 👍🏽

@mrmir
Copy link
Contributor Author

mrmir commented Mar 4, 2026

Closing in favour of opf/openproject-dev_tools#2. Still need to take into account the feedback mentioned here - will do so there

@mrmir mrmir closed this Mar 4, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants