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

fix(plg): add links to the user nav dropdown #63462

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

taras-yemets
Copy link
Contributor

@taras-yemets taras-yemets commented Jun 25, 2024

Closes https://github.com/sourcegraph/sourcegraph/issues/63264
Re-implements reverted https://github.com/sourcegraph/sourcegraph/pull/63378

  1. Adds Cody Pro section (available for the team admins only) to the user nav dropdown on dotcom:
    • if dotcom.codyProConfig.useEmebeddedUI site config param is set to true, team admins will have links to "cody/subscription/manage" and "cody/team/manage" pages
    • if dotcom.codyProConfig.useEmebeddedUI site config param is not set or set to false, team admins will have only link only to the manage subscription page on accounts.sourcegraph.com (https://accounts.sourcegraph.com/cody/subscription).
  2. Makes subscription management page only available for team admins. If team members try to navigate this page by changing the URL, they will be redirected to the "/cody/manage" page.
  3. Lifts QueryClientProvider (wrapper around react-query ClientProvider higher in the component tree so that Cody Pro API query and mutations can be used not only on the Cody Pro routes.

Design

useEmbeddedUI Role Plan Screenshot
true member Pro Screenshot 2024-06-25 at 15 15 20
true admin Pro Screenshot 2024-06-25 at 15 17 26
true n/a Free Screenshot 2024-06-25 at 15 26 37
false member Pro Screenshot 2024-06-25 at 15 21 36
false admin Pro Screenshot 2024-06-25 at 15 20 11
false n/a Free Screenshot 2024-06-25 at 15 28 20

Test plan

Test plan

  • Tested manually (screenshots attached):
    • Run Sourcegraph instance in dotcom mode
    • Tweak dotcom.codyProConfig.useEmbeddedUI site config param, log in with users with different team roles (member/admin) and check results with the table above.
  • Added unit tests

…down (#63378)

Closes https://github.com/sourcegraph/sourcegraph/issues/63264

1. Adds Cody Pro section to the user nav dropdown on dotcom:
- team admins have links to "cody/subscription/manage" and
"cody/team/manage" pages
   - team members have only link only to the "cody/team/manage" page
2. Makes subscription management page only available for team admins. If
team members try to navigate this page by changing the URL, they will be
redirected to the "/cody/manage" page.
- Makes "Manage subscription" link on the "/cody/manage" available only
for the team admins (previously - any Pro user)
3. Lifts `QueryClientProvider` (wrapper around react-query
`ClientProvider` higher in the component tree so that Cody Pro API query
and mutations can be used not only on the Cody Pro routes.


[Design](https://www.figma.com/design/FMSdn1oKccJRHQPgf7053o/Cody-PLG-GA?node-id=5351-19126&t=LfNQR7vUCJhlNvyT-4)

| Role | Screenshot |
|--|--|
|Admin|<img width="1605" alt="Screenshot 2024-06-20 at 12 57 13"
src="https://github.com/sourcegraph/sourcegraph/assets/25318659/e7b995fd-4322-4f7f-86bb-c7027cacd644"><img
width="1605" alt="Screenshot 2024-06-20 at 13 10 28"
src="https://github.com/sourcegraph/sourcegraph/assets/25318659/84be111c-76e2-4b14-9b73-ebdd5f8cbb9a">|
|Member|<img width="1605" alt="Screenshot 2024-06-20 at 12 56 50"
src="https://github.com/sourcegraph/sourcegraph/assets/25318659/aefd8b3b-29fe-4957-87ee-b493eb489922"><img
width="1605" alt="Screenshot 2024-06-20 at 13 09 51"
src="https://github.com/sourcegraph/sourcegraph/assets/25318659/8209e7a0-4deb-4681-9f6b-3cfde8110842">|




<!-- 💡 To write a useful PR description, make sure that your description
covers:
- WHAT this PR is changing:
    - How was it PREVIOUSLY.
    - How it will be from NOW on.
- WHY this PR is needed.
- CONTEXT, i.e. to which initiative, project or RFC it belongs.

The structure of the description doesn't matter as much as covering
these points, so use
your best judgement based on your context.
Learn how to write good pull request description:
https://www.notion.so/sourcegraph/Write-a-good-pull-request-description-610a7fd3e613496eb76f450db5a49b6e?pvs=4
-->


## Test plan
- Start Sourcegraph instance in dotcom mode
  - sign in as a Cody Pro team admin 
- ensure that "Manage subscription" and "Manage team" links are present
in the user nav dropdown
    - ensure "/cody/manage" page has "Manage subscription" link
  - sign in as a Cody Pro team member (not admin)
    - ensure "Manage team" link is present in the user nav dropdown
    - navigate to "/cody/subscription/manage/ page by changing the URL
    - ensure you've been redirected to the "/cody/manage" page
    - ensure "/cody/manage" page doesn't have "Manage subscription" link
- start Sourcegraph in the enterprise mode
  - ensure the mentioned links are not rendered
<!-- All pull requests REQUIRE a test plan:
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles
-->


## Changelog

<!--
1. Ensure your pull request title is formatted as: $type($domain): $what
2. Add bullet list items for each additional detail you want to cover
(see example below)
3. You can edit this after the pull request was merged, as long as
release shipping it hasn't been promoted to the public.
4. For more information, please see this how-to
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c?

Audience: TS/CSE > Customers > Teammates (in that order).

Cheat sheet: $type = chore|fix|feat $domain:
source|search|ci|release|plg|cody|local|...
-->

<!--
Example:

Title: fix(search): parse quotes with the appropriate context
Changelog section:

## Changelog

- When a quote is used with regexp pattern type, then ...
- Refactored underlying code.
-->
@cla-bot cla-bot bot added the cla-signed label Jun 25, 2024
@taras-yemets taras-yemets changed the title Ty/add-cody-pro-links-to-user-nav fix(plg): add links to the user nav dropdown Jun 25, 2024
@taras-yemets taras-yemets requested a review from a team June 25, 2024 12:35
@taras-yemets taras-yemets marked this pull request as ready for review June 25, 2024 12:35
Copy link
Contributor

@chrsmith chrsmith left a comment

Choose a reason for hiding this comment

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

Some minor suggestions, but overall this LGTM!

@@ -55,18 +56,32 @@ const AuthenticatedCodySubscriptionManagePage: React.FC<Props> = ({ telemetryRec
return null
}

if (subscriptionSummaryQuery.isError) {
logger.error('Failed to fetch Cody subscription summary', subscriptionSummaryQuery.error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is just logging an error and returning null the right call here? Or should we have something like return <GenericErrorPage message="{...}"></GenericErrorPage>?

It just seems like this could lead to a situation where the user has a blank page or some awkward looking UI, which is a little worse than having a clear "error" state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrsmith, WDYT about throwing an error that is propagated to the closest ErrorBoundary and results in a page looking like this?

Screenshot 2024-06-26 at 12 26 22

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
logger.error('Failed to fetch Cody subscription summary', subscriptionSummaryQuery.error)
throw new Error('Failed to fetch Cody subscription summary.')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's fine, then we may want to handle the other failed API calls inside components in a similar way (search).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cc: @rrhyne

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that error message is fine for now but it would be better to update the text to be more end user friendly by removing “your site admin” and linking “Sourcegraph support” to the proper channel on discord, or the best place to resolve the error.

Copy link
Contributor

Choose a reason for hiding this comment

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

This SGTM. The "fall back to the default error handler" seems super reasonable. And I also like Rob's suggestions. (Which I'm guessing would just be within the <GenericErrorHandlerDodad> use slightly different wording if in dotcom mode.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replacing logger.error calls with error propagation to the nearest error boundary might not be sufficient.
For instance, a 404 error for the subscription summary should redirect the user to the "/cody/manage" page and possibly provide UI feedback indicating they tried to access the page they are not allowed to because of their team status or role on the team.
Additionally, I think we need a consistent approach to handling API call failures across the entire PLG flow. To address this comprehensively, I’ve created a dedicated issue, and I suggest we handle it in a separate PR.
WDYT, @chrsmith?

@taras-yemets taras-yemets force-pushed the ty/add-cody-pro-links-to-user-nav branch from 2211865 to f1ad572 Compare June 26, 2024 08:05
@taras-yemets
Copy link
Contributor Author

Cody dashboard link has been added in https://github.com/sourcegraph/sourcegraph/pull/63514. @rrhyne, do you think we need to revisit the Cody PRO section in the user nav drodown inroduced in the current PR (e.g., have a dedicated Cody section)?

@rrhyne
Copy link
Contributor

rrhyne commented Jul 1, 2024

Cody dashboard link has been added in #63514. @rrhyne, do you think we need to revisit the Cody PRO section in the user nav drodown inroduced in the current PR (e.g., have a dedicated Cody section)?

Sorry, I thought I had replied to this elsewhere but did not. Yeah, I do. This is an odd location for the dash and we should pull it all together into a single section so users get used to seeing it in one place throughout the life cycle of Free -> Pro -> Teams.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Put "Manage subscription" and "Manage team" links to the submenu on the right
3 participants