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
Copy dev profile #337
Copy dev profile #337
Conversation
|
@joemasilotti This will append many flash messages if you click many times, do you like the behavior? |
|
Hmm. I'm wondering if changing the copy icon to a check when clicking is a better approach. We could even clear it after a few seconds. Tailwind UI does this and it works quite well. |
|
That will make it simpler, do you have an example from the tailwind UI? |
|
If you set a title in the SVG you can query for it with a CSS selector. There's an example somewhere in the codebase. As for copy and clipboard, I'm not 100% sure. Might have to get creative if there isn't something built in to capybara. |
| <%= inline_svg_tag "icons/solid/document-duplicate.svg", class: "h-6 w-5", data: {clipboard_target: "toggleable"} %> | ||
| <%= inline_svg_tag "icons/solid/check.svg", class: "h-6 w-5 text-green-500 hidden", data: {clipboard_target: "toggleable"} %> |
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.
I'd love to get rid of the mismatched height/width calls, if possible. Because I'd be inclined to change them both to *-5 but that would break the layout!
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.
What about getting rid with w-5 and remain with height?
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.
I think the question is more "Why does `w-5 h-5 not work here" when it works everywhere else. Are we missing a flex tag or something?
| static targets = ["toggleable"]; | ||
|
|
||
| copy({ target: { value } }) { | ||
| navigator.clipboard.writeText(value); |
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.
It seems like this is copying plain text and not text/html. This SO question has a few answers that could help. The accepted on, even though it is a lot of code, does indeed work for me. You can test by pasting the copied code into an email client.
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.
I don't know how trello works but if you paste a link https://railsdevs.com/developers/35
It's able to transform to

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.
That's only the link though. Trello is fetching the title by crawling the page and populating it from <title>.
We want full HTML to be copied, so the text with an embedded link. Not only a link by itself.
| @@ -8,4 +8,11 @@ | |||
| <%= inline_svg_tag "icons/solid/briefcase.svg", class: "-ml-1 mr-3 h-5 w-5" %> | |||
| <%= t("developers.show.hire") %> | |||
| <% end %> | |||
|
|
|||
| <% if admin? %> | |||
| <button data-controller="clipboard" data-action="click->clipboard#copy click->clipboard#toggle" value="<a href='<%= developer_url(@developer) %>'><%= @developer.hero %></a>" type="button" class="shrink-0 mt-4 md:mt-0 inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-base font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"> | |||
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.
Is shoving this in the value the best approach? I wonder if it would be better to move this to a hidden element inside the controller with a target. But read my comment below on text/html first because that might help guide you a bit.
|
Hey @gathuku, do you still have the appetite to get this across the finish line? I made a lot of comments in the PR review. If not, let me know and I can take over. |
|
Sure, Am willing to look at it, i might want your help on testing. |
|
Sure thing! Let me know when you want to hand it off and I will take it from there. |
|
Tried something like this with no success test "should show copy icon to admin user" do
user = users(:admin)
render_inline DeveloperPrimaryActionComponent.new(user:, developer: @developer)
assert_selector "svg[title='document duplicate']"
end |
| @@ -0,0 +1,4 @@ | |||
| <svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor"> | |||
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.
@gathuku, you have to add the title attribute here for the query to work.
|
Hey @gathuku, are you still working on this? I use a workaround every day that could be sped up a ton by this PR being merged so I'd love to see it get deployed soon. Let me know if you'd rather pass it off and I can take it from here! |
It's okay @joemasilotti . Please pick it, i will follow how you implement this. |




Pull request checklist
bin/checkTODO
Replace flash if exists
Show for admin only
closes Button to copy hero/URL of developer profile #326
Credit to thoughtbot