Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Add 'Take Sourcegraph to your [code host]' popover #14256

Merged
merged 43 commits into from
Oct 8, 2020
Merged

Conversation

tjkandala
Copy link
Contributor

@tjkandala tjkandala commented Sep 28, 2020

Closes #14199. Part of RFC 221

  • - Convert GoToCodeHostAction to function component
  • - Implement popup popover
  • - Remove chrome extension toast
  • - Implement focus trapping for modal
  • - Implement hover tracking (5 hovers seen by user before displaying popup)
  • - Storybook
  • - Integration testing
  • - Improve CSS
    • - SVG sizing
    • - Popover arrow

Interaction

Popover fade in on click
Keyboard navigation, "Remind me later"

Popover visuals

Screenshot from 2020-09-30 19-02-49

@AlicjaSuska The "arrow" is a square rotated 45 degrees and 50% hidden by the popover. This approach is good for responsive popovers since it's mostly the same styles for each direction, but it doesn't align 100% with the design. I'll revisit the arrow after finishing the remaining issues.

@tjkandala tjkandala requested review from AlicjaSuska and a team September 28, 2020 22:26
@tjkandala tjkandala added RFC-221 Browser extension - improve discoverability and awerness webapp labels Sep 28, 2020
@sqs
Copy link
Member

sqs commented Sep 28, 2020

In https://github.com/sourcegraph/sourcegraph/pull/14261 I made it so it shows the toast on your 3rd day of activity, not your 1st. Not sure how you're doing it here, but you should make it so this doesn't show up immediately the very first time they load Sourcegraph.

@tjkandala
Copy link
Contributor Author

We're removing the toast as part of RFC 221 in favor of inline alerts after the user has seen 2 hovers.

That's a good idea though; cc @sourcegraph/web @AlicjaSuska Should we check daysActiveCount for this popup?

@AlicjaSuska
Copy link
Contributor

This popup is displayed after clicking on 'view on GitHub'. I think it doesn't make sense to add the day count as criteria here. I think it makes sense to show this information even if someone clicks 'view on [code host]' for the first time.

@felixfbecker
Copy link
Contributor

@AlicjaSuska maybe we can include the criterium "Has seen at least 2 hovers" too with the same reasoning as for the alert?

Copy link
Contributor

@felixfbecker felixfbecker left a comment

Choose a reason for hiding this comment

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

issue: How are we going to test this and prevent regressions? Having a story for the modal sounds like a good idea, and maybe an integration test for the behavior?

web/src/auth/icons.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/GoToCodeHostAction.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/GoToCodeHostAction.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/GoToCodeHostAction.tsx Outdated Show resolved Hide resolved
@AlicjaSuska
Copy link
Contributor

@felixfbecker let's add the '2 hovers' criteria, you're right.

@tjkandala
Copy link
Contributor Author

If the user clicks "Install the Sourcegraph browser extension" from the alert, but doesn't install the extension, should we disable the popover for the 'View on code host button'? They're both dependent on the user seeing 5 hovers now, so it might be annoying to see the popover after already looking to, but not installing, the extension.

@tjkandala tjkandala changed the title Add 'Take Sourcegraph to your [code host]' popup Add 'Take Sourcegraph to your [code host]' popover Oct 1, 2020
@AlicjaSuska
Copy link
Contributor

@tjkandala

  • I've changed the pointer to 12px square rotated 45 degrees - as you've suggested See the design
  • I've updated the designs in Figma. Please, pay attention to dark mode - I've changed the background color slightly
  • about your comment: 'If the user clicks "Install the Sourcegraph browser extension" from the alert, but doesn't install the extension, should we disable the popover for the 'View on code host button'? - I see the value in showing the popover in the context of clicking on 'view on [code host] even if user already visited the extension page but didn't install. It can serve as reminder / seeing the potential benefit in context. I think they shouldn't be dependent. Both should be dismissed only explicitly by the user (by X for alert or 'no, thanks' for the popover) or by installing the extension.

}

/**
* A component that is displayed in the same way, regardless of whether it's a link (with a
* destination URL) or a button (with a click handler).
*
* It is keyboard accessible: unlike <Link> or <a>, pressing the enter key triggers it. Unlike
* <button>, it shows a focus ring.
* It is keyboard accessible: unlike `<Link>` or `<a>`, pressing the enter key triggers it.
Copy link
Contributor

@felixfbecker felixfbecker Oct 2, 2020

Choose a reason for hiding this comment

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

thought: I'm starting to question the validity of the entire LinkOrButton/ButtonLink component. This comment stated that <button>s don't show a focus ring, which is false - the buttons in our app all have focus rings. But now I just verified that hitting enter when a link is focused also triggers navigation and click handlers in Chrome, so that statement seems to be false too, leaving no reason to use this component.
The only case where it would not do anything is if the link only had onClick, but in that case it should not be a link, it should be a <button>. It seems like for our use cases we should always use <button> or <a>/<Link> directly and avoid this component, potentially remove it.
cc @sourcegraph/frontend-engineers

web/src/components/PopoverContainer.scss Outdated Show resolved Hide resolved
web/src/components/useModality.ts Outdated Show resolved Hide resolved
web/src/integration/blob-viewer.test.ts Outdated Show resolved Hide resolved
web/src/repo/RepoContainer.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/GoToCodeHostAction.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/InstallExtensionPopover.story.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/InstallExtensionPopover.tsx Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 2, 2020

Codecov Report

Merging #14256 into main will decrease coverage by 5.73%.
The diff coverage is 20.22%.

@@            Coverage Diff             @@
##             main   #14256      +/-   ##
==========================================
- Coverage   52.70%   46.97%   -5.74%     
==========================================
  Files        1030     1550     +520     
  Lines       65273    78991   +13718     
  Branches     2427     6897    +4470     
==========================================
+ Hits        34402    37105    +2703     
- Misses      27194    38166   +10972     
- Partials     3677     3720      +43     
Flag Coverage Δ
#go 52.43% <ø> (-0.01%) ⬇️
#integration 100.00% <ø> (ø)
#storybook 100.00% <ø> (ø)
#typescript 33.60% <20.22%> (-20.71%) ⬇️
#unit 33.60% <20.22%> (-20.71%) ⬇️
Impacted Files Coverage Δ
client/shared/src/actions/ActionItem.tsx 80.85% <ø> (ø)
client/web/src/Layout.tsx 0.00% <0.00%> (ø)
client/web/src/auth/icons.tsx 50.00% <0.00%> (ø)
client/web/src/components/useModality.ts 0.00% <0.00%> (ø)
client/web/src/nav/GlobalNavbar.tsx 60.52% <ø> (ø)
client/web/src/nav/NavLinks.tsx 82.75% <ø> (ø)
client/web/src/repo/RepoContainer.tsx 0.00% <0.00%> (ø)
client/web/src/repo/RepoHeader.tsx 0.00% <0.00%> (ø)
client/web/src/repo/RepoRevisionContainer.tsx 0.00% <ø> (ø)
...lient/web/src/repo/actions/GoToPermalinkAction.tsx 0.00% <ø> (ø)
... and 540 more

@tjkandala
Copy link
Contributor Author

tjkandala commented Oct 4, 2020

Update: Replaced all (2) modals in the web app with @reach/dialog, replaced custom popover with reactstrap's popover and @reach/popover (to compare), and removed useModality hook.

Reactstrap popover

Keyboard navigation

Fade in and visuals are same as in original post.

Reach popover

Keyboard navigation

No fade in.

Popover visuals

Screenshot from 2020-10-03 23-46-01

Summary

Reactstrap's popover is easier to visually customize, but I don't think it's meant to be used with interactive elements. Reach adheres to the ARIA spec, but is hard to position when compared to Popper's modifiers system (Popper does the heavy lifting for both reactstrap's popover and the original custom popover).

I'll spend a little more time trying to get Reach's popover to align with the design. If that doesn't work out, I propose that we use reactstrap's popper combined with the focus-trap library (or react-focus-lock, which was added to the web app by @reach/dialog) to essentially recreate the original implementation, but with more robust and mature 3rd-party building blocks.

Edit: Went with reactstrap + react-focus-lock, the popover works like the original implementation now.

@felixfbecker
Copy link
Contributor

@tjkandala looks like you did good research on the best solution for popovers! If we're using Reactstrap now, does that mean we also need to add an import to the Bootstrap styles and they should "just work"? (I see that we still have custom CSS for the popover despite using Reactstrap, and that the arrow still doesn't work)

@tjkandala
Copy link
Contributor Author

@tjkandala looks like you did good research on the best solution for popovers! If we're using Reactstrap now, does that mean we also need to add an import to the Bootstrap styles and they should "just work"? (I see that we still have custom CSS for the popover despite using Reactstrap, and that the arrow still doesn't work)

Replaced custom CSS with Bootstrap styles, which fixed the arrow. Weirdly, importing Bootstrap styles changed the way that the offset works.

No offset

Screenshot from 2020-10-05 18-56-35

Offset "0, -4" (Same as original post)

Screenshot from 2020-10-05 18-43-11

Copy link
Contributor

@AlicjaSuska AlicjaSuska left a comment

Choose a reason for hiding this comment

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

Thank you for this work @tjkandala I finally could test it after your help 🎉

Improvements that are needed:

  • popup should appear for users who have 3 hovers, not 5 (as it is now)
  • pointer styles are not aligned with the design. If it's a very difficult fix we can also remove the pointer entirely to speed things up.
  • in dark mode, there are light points in the corners of the popover. I'm not sure what are those.

Screenshot 2020-10-06 at 18 40 36

- if we move forward with the pointer, it should be closer to the icon, 4 px above the divider (now it touches the divider) Design screenshot:

Screenshot 2020-10-06 at 18 46 07

- after clicking on 'install the extension', Docs should open in the **new tab** (not in the same tab as currently)

@tjkandala
Copy link
Contributor Author

tjkandala commented Oct 6, 2020

Screenshot from 2020-10-06 15-20-47

update: @AlicjaSuska. Links also open in new tabs when the user originally middle clicked 'Go to [code host]', and docs always open in new tab.

package.json Show resolved Hide resolved
web/src/extensions/ExtensionPermissionModal.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/InstallExtensionPopover.tsx Outdated Show resolved Hide resolved
web/src/repo/actions/InstallExtensionPopover.tsx Outdated Show resolved Hide resolved
web/src/SourcegraphWebApp.scss Outdated Show resolved Hide resolved
web/src/components/Dialog.scss Outdated Show resolved Hide resolved
web/src/integration/blob-viewer.test.ts Outdated Show resolved Hide resolved
web/src/repo/RepoContainer.tsx Outdated Show resolved Hide resolved
}

& .arrow::after {
border-bottom-color: var(--body-bg) !important;
Copy link
Contributor

Choose a reason for hiding this comment

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

question: shouldn't this be set in global-styles for all popovers? Or perhaps there is just a Bootstrap Sass var we can set for this? Usually we need to set some Sass variables for every Bootstrap component when start using it to make it theme-aware, and this PR is the first one to use popover, so that's likely

Copy link
Contributor Author

@tjkandala tjkandala Oct 6, 2020

Choose a reason for hiding this comment

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

Implemented this change. However, I found out that other popovers in our application broke once we imported Bootstrap's popover styles, probably since they were built without Bootstrap (css) in mind. I set $popover-max-width to auto. Do you think this is the right change?

Copy link
Contributor

Choose a reason for hiding this comment

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

We obviously can't break other popovers, so if that change fixes it, that sounds right. I wasn't aware we actually used the class elsewhere given we had not imported it. I also just found these styles:

https://github.com/sourcegraph/sourcegraph/blob/9308b5e932036efde80e6a7b926383130e8aeb98/web/src/SourcegraphWebApp.scss#L233-L239

They can probably be removed, and that comment looks like it doesn't apply if we set the variables correctly. The arrow also seems to be an element you have to explicitly render in the DOM, so that can just be omitted if we don't want it for certain popovers (like the rev switcher).

@felixfbecker
Copy link
Contributor

popup should appear for users who have 3 hovers, not 5 (as it is now)

@AlicjaSuska this was something we discussed when we hacked on this, 3 felt very low. Do you feel strongly about 3?

@tjkandala tjkandala merged commit a3f7e43 into main Oct 8, 2020
@tjkandala tjkandala deleted the tj/code-host-popup branch October 8, 2020 23:47
efritz pushed a commit that referenced this pull request Oct 9, 2020
Display an alert on first render of a repo page after the user has seen 3 hovers. Add a popover when the user first clicks on 'View on [code host]'.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
RFC-221 Browser extension - improve discoverability and awerness webapp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add 'Take SG to your [code host]' popup after clicking 'open on [code host]
6 participants