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

PLG: extract Cody Pro routes to a separate file#63003

Merged
taras-yemets merged 11 commits into
mainfrom
ty/cody-pro-routes
Jun 3, 2024
Merged

PLG: extract Cody Pro routes to a separate file#63003
taras-yemets merged 11 commits into
mainfrom
ty/cody-pro-routes

Conversation

@taras-yemets

@taras-yemets taras-yemets commented May 31, 2024

Copy link
Copy Markdown
Contributor
  1. Ensures Cody Pro routes are available only on dotcom.

Cody Manage and Cody Subscription routes previously lacked isSourcegraphDotCom checks, resulting in the error “this feature is only available on sourcegraph.com” when accessed on the enterprise version. This update adds the necessary checks to restrict these routes to Sourcegraph.com.

Screenshot Screenshot 2024-05-31 at 17 35 32
  1. Moves Cody Pro routes definition to a separate file.

To reduce clutter in the web app routes file, Cody Pro-specific implementation details (such as the isEmbeddedCodyProUIEnabled experimental thingy) have been moved to a separate file. This keeps the logic cleaner and more organized.

  1. Creates CodyProPage component that wraps every Cody Pro page.

A new CodyProPage component has been created to wrap all Cody Pro pages. This shared wrapper will be useful for performing actions on every Cody Pro page (e.g., logging page views) and for wrapping pages with specific providers (e.g., ReactQuery provider for SSC backend access, as seen in https://github.com/sourcegraph/sourcegraph/pull/62939).

Test plan

  • CI
  • Tested manually: migrated routes load corresponding pages

@cla-bot cla-bot Bot added the cla-signed label May 31, 2024
@taras-yemets taras-yemets marked this pull request as ready for review May 31, 2024 15:07
@taras-yemets taras-yemets requested a review from a team May 31, 2024 15:07
Comment thread client/web/src/cody/codyProRoutes.tsx Outdated
/>
)}
condition={({ isSourcegraphDotCom, licenseFeatures }) =>
isSourcegraphDotCom && licenseFeatures.isCodyEnabled

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

However, Cody Pro routes are available only on dotcom, and Cody should always be enabled there. I’m leaving the license check in place “just in case” since I couldn’t find a hardcoded true for the Cody feature when in dotcom mode in our backend code.

@chrsmith chrsmith left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All of this looks right, and does take a step towards a better overall architecture. (🙌 👏)

But I think we need to double check that users can still use /cody/manage (like they do today), and serve a 404 error on sourcegraph.com for our newer pages (at least until we set certain site config or user flags.)

Also, if possible, I think it would be cleaner to just have any "Cody Pro" pages serve a 404 if you aren't running on dotcom mode. Since "error: this page is only available on sourcegraph.com" seems less pleasant than just a generic 404. (Since the end result is the same: that page doesn't exist [for Enterprise users].)

Comment thread client/web/src/cody/CodyProPage.tsx Outdated
Comment on lines +29 to +31
/**
* Renders the appropriate Cody Pro page component for the given route path.
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think I've ever seen a /** */ style comment in the code base yet. So would you mind doing a quick sanity check too see how common this is? If we already have enough usages that either would be considered common, then we can leave this as-is.

But if most doc comments like this are using single-line (//) comments, we should try to be consistent with the larger codebase.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think I've ever seen a /** */ style comment in the code base yet. So would you mind doing a quick sanity check too see how common this is? If we already have enough usages that either would be considered common, then we can leave this as-is.

4640 uses in the monorepo only.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @vdavid , perhaps a better question I should have asked is: do we have an "official" style guide for various languages at Sourcegraph? Even if it is just "do whatever the {Microsoft, Google} style guide for {language} says"?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We don't have much docs guidance for these things, what we have is linter rules. Apparently none for this one, probably it was so low value that no one has uniformized it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I used the JSDoc /** comment because it's shown in the hover tooltips, as opposed to the /* and // comments.

Screenshot 2024-06-03 at 10 01 14

Comment thread client/web/src/cody/CodyProPage.tsx Outdated
Comment thread client/web/src/cody/codyProRoutes.tsx

@vdavid vdavid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I like it. Please either wait for @chrsmith's response for how comfortable he is with publishing these pages, or ask Security. That's the only thing, otherwise this is great! Thanks! 🙂

@taras-yemets

Copy link
Copy Markdown
Contributor Author

@chrsmith, @vdavid, thanks for your reviews!

https://github.com/sourcegraph/sourcegraph/blob/0189c78bf46a698bcc85a589dd4a35bc2d1e71c2/client/web/src/cody/codyProRoutes.tsx#L23-L34

This PR doesn't make changes to the conditional routes rendering depending on the isEmbeddedCodyProUIEnabled experimental thingy (https://github.com/sourcegraph/sourcegraph/pull/63003#discussion_r1623881578).

@taras-yemets taras-yemets enabled auto-merge (squash) June 3, 2024 12:40
@taras-yemets taras-yemets merged commit 88d71af into main Jun 3, 2024
@taras-yemets taras-yemets deleted the ty/cody-pro-routes branch June 3, 2024 12:42
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.

3 participants