sourcegraph
sourcegraph copied to clipboard
chore(plg): provide user Cody plan on a route level
1. Lifts the user Cody plan query to Sourcegraph GraphQL backend up to the route level.
All Cody Pro pages require the user’s Cody Pro plan to determine their behavior. Previously, we had repetitive logic to fetch this data and handle loading and error states. This PR moves the fetching of the user’s Cody plan to a higher level, simplifying the code. Now, each Cody Pro page component receives the subscription data as a prop.
2. Creates a Custom Hook for Fetching the User’s Cody Plan.
3. Refactors "/cody/subscription" page component.
- Updates the
CodySubscriptionPagecomponent to use thewithAuthenticatedUserhigher-order component. This change removes the need for an authenticated user check within the component itself, making it more consistent with other Cody Pro page components. - Removes redundant
isCodyEnabled()check.- "/cody/subscription" route is only rendered on dotcom and if the Cody feature is enabled in the license.
- The
isCodyEnabled()check consists of two fields from jscontext:-
codyEnabled: reads its value from the site config and it's obviouslytruefor dotcom -
codyEnabledForCurrentUser: returnsfalseonly if the actor is not authenticated, which is already ensured at a higher level (see 2.).
-
Test plan
- CI
- Run Sourcegraph in dotcom mode locally and compare the authenticated user related logic with sourcegraph.com