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

Commit dfabe64

Browse files
authored
Revert "fix(plg): Cody Pro routes conditions & add links to the user nav dropdown (#63378) (#63424)
This reverts commit 5cf81e0 (https://github.com/sourcegraph/sourcegraph/pull/63378). This PR intorduced a call to the SSC backend via proxy on the Sourcegraph backend (see `cmd/frontend/internal/ssc/ssc_proxy.go`). It appeared that proxy is not properly configured on dotcom, causing requests to fail with 503 "proxy not configured" errors. Reverting this PR until we fix the configuration. <!-- 💡 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 - CI <!-- 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. -->
1 parent e707101 commit dfabe64

File tree

10 files changed

+44
-106
lines changed

10 files changed

+44
-106
lines changed

client/web/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ ts_project(
240240
"src/cody/management/UseCodyInEditorSection.tsx",
241241
"src/cody/management/api/client.ts",
242242
"src/cody/management/api/components/CodyProApiClient.ts",
243-
"src/cody/management/api/react-query/CodyProApiProvider.tsx",
243+
"src/cody/management/api/react-query/QueryClientProvider.tsx",
244244
"src/cody/management/api/react-query/callCodyProApi.ts",
245245
"src/cody/management/api/react-query/invites.ts",
246246
"src/cody/management/api/react-query/queryKeys.ts",

client/web/src/LegacySourcegraphWebApp.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { WildcardThemeContext, type WildcardTheme } from '@sourcegraph/wildcard'
4141
import { authenticatedUser as authenticatedUserSubject, type AuthenticatedUser, authenticatedUserValue } from './auth'
4242
import { getWebGraphQLClient } from './backend/graphql'
4343
import { isBatchChangesExecutionEnabled } from './batches'
44-
import { CodyProApiProvider } from './cody/management/api/react-query/CodyProApiProvider'
4544
import { ComponentsComposer } from './components/ComponentsComposer'
4645
import { ErrorBoundary } from './components/ErrorBoundary'
4746
import { FeatureFlagsLocalOverrideAgent } from './featureFlags/FeatureFlagsProvider'
@@ -261,7 +260,6 @@ export class LegacySourcegraphWebApp extends React.Component<StaticAppConfig, Le
261260
<SearchResultsCacheProvider />,
262261
<SearchQueryStateStoreProvider useSearchQueryState={useNavbarQueryState} />,
263262
<LegacyRouteContextProvider context={legacyContext} />,
264-
<CodyProApiProvider isSourcegraphDotCom={window.context.sourcegraphDotComMode} />,
265263
/* eslint-enable react/no-children-prop, react/jsx-key */
266264
]}
267265
>

client/web/src/SourcegraphWebApp.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import type { TelemetryV2Props } from '@sourcegraph/shared/src/telemetry'
2929
import { WildcardThemeContext, type WildcardTheme } from '@sourcegraph/wildcard'
3030

3131
import { authenticatedUser as authenticatedUserSubject, type AuthenticatedUser, authenticatedUserValue } from './auth'
32-
import { CodyProApiProvider } from './cody/management/api/react-query/CodyProApiProvider'
3332
import { ComponentsComposer } from './components/ComponentsComposer'
3433
import { ErrorBoundary, RouteError } from './components/ErrorBoundary'
3534
import { FeatureFlagsLocalOverrideAgent } from './featureFlags/FeatureFlagsProvider'
@@ -284,7 +283,6 @@ export const SourcegraphWebApp: FC<SourcegraphWebAppProps> = props => {
284283
...props,
285284
}}
286285
/>,
287-
<CodyProApiProvider isSourcegraphDotCom={props.isSourcegraphDotCom} />,
288286
/* eslint-enable react/no-children-prop, react/jsx-key */
289287
]}
290288
>

client/web/src/cody/codyProRoutes.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { lazyComponent } from '@sourcegraph/shared/src/util/lazyComponent'
44

55
import { type LegacyLayoutRouteContext, LegacyRoute } from '../LegacyRouteContext'
66

7+
import { QueryClientProvider } from './management/api/react-query/QueryClientProvider'
78
import { isEmbeddedCodyProUIEnabled } from './util'
89

910
export enum CodyProRoutes {
@@ -77,5 +78,9 @@ interface CodyProPageProps extends Pick<LegacyLayoutRouteContext, 'authenticated
7778
*/
7879
const CodyProPage: React.FC<CodyProPageProps> = props => {
7980
const Component = routeComponents[props.path]
80-
return <Component authenticatedUser={props.authenticatedUser} telemetryRecorder={props.telemetryRecorder} />
81+
return (
82+
<QueryClientProvider>
83+
<Component authenticatedUser={props.authenticatedUser} telemetryRecorder={props.telemetryRecorder} />
84+
</QueryClientProvider>
85+
)
8186
}

client/web/src/cody/management/CodyManagementPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export const CodyManagementPage: React.FunctionComponent<CodyManagementPageProps
175175
)}
176176
</Text>
177177
</div>
178-
{isAdmin && (
178+
{isUserOnProTier && (
179179
<div>
180180
<ButtonLink
181181
variant="primary"

client/web/src/cody/management/api/react-query/CodyProApiProvider.tsx

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { QueryClient, QueryClientProvider as ReactQueryClientProvider } from '@tanstack/react-query'
2+
3+
// Tweak the default queries and mutations behavior.
4+
// See defaults here: https://tanstack.com/query/latest/docs/framework/react/guides/important-defaults
5+
const queryClient = new QueryClient({
6+
defaultOptions: {
7+
queries: {
8+
// If query failed, it's not likely that refetching it will succeed, so don't retry.
9+
retry: false,
10+
},
11+
mutations: {
12+
// If query failed, it's not likely that refetching it will succeed, so don't retry.
13+
retry: false,
14+
},
15+
},
16+
})
17+
18+
export const QueryClientProvider: React.FC<React.PropsWithChildren<{}>> = ({ children }) => (
19+
<ReactQueryClientProvider client={queryClient}>{children}</ReactQueryClientProvider>
20+
)

client/web/src/cody/management/subscription/manage/CodySubscriptionManagePage.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import type { LegacyLayoutRouteContext } from '../../../../LegacyRouteContext'
2020
import { CodyProRoutes } from '../../../codyProRoutes'
2121
import { PageHeaderIcon } from '../../../components/PageHeaderIcon'
2222
import { USER_CODY_PLAN } from '../../../subscription/queries'
23-
import { useCurrentSubscription, useSubscriptionSummary } from '../../api/react-query/subscriptions'
23+
import { useCurrentSubscription } from '../../api/react-query/subscriptions'
2424

2525
import { InvoiceHistory } from './InvoiceHistory'
2626
import { PaymentDetails } from './PaymentDetails'
@@ -38,7 +38,6 @@ const AuthenticatedCodySubscriptionManagePage: React.FC<Props> = ({ telemetryRec
3838
error: useCodyPlanError,
3939
data: userCodyPlanData,
4040
} = useQuery<UserCodyPlanResult, UserCodyPlanVariables>(USER_CODY_PLAN, {})
41-
const subscriptionSummaryQuery = useSubscriptionSummary()
4241

4342
useEffect(
4443
function recordViewEvent() {
@@ -47,7 +46,7 @@ const AuthenticatedCodySubscriptionManagePage: React.FC<Props> = ({ telemetryRec
4746
[telemetryRecorder]
4847
)
4948

50-
if (userCodyPlanLoading || subscriptionSummaryQuery.isLoading) {
49+
if (userCodyPlanLoading) {
5150
return <LoadingSpinner />
5251
}
5352

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

59-
if (subscriptionSummaryQuery.isError) {
60-
logger.error('Failed to fetch Cody subscription summary', subscriptionSummaryQuery.error)
61-
return null
62-
}
63-
6458
const subscriptionData = userCodyPlanData?.currentUser?.codySubscription
6559
if (!subscriptionData) {
6660
logger.error('Cody subscription data is not available.')
6761
return null
6862
}
6963

70-
if (!subscriptionSummaryQuery.data) {
71-
logger.error('Cody subscription summary is not available.')
72-
return null
73-
}
74-
7564
// This page only applies to users who have a Cody Pro subscription to manage.
7665
// Otherwise, direct them to the ./new page to sign up.
7766
if (subscriptionData.plan !== CodySubscriptionPlan.PRO) {
7867
return <Navigate to={CodyProRoutes.NewProSubscription} replace={true} />
7968
}
8069

81-
if (subscriptionSummaryQuery.data.userRole !== 'admin') {
82-
return <Navigate to={CodyProRoutes.Manage} replace={true} />
83-
}
84-
8570
return (
8671
<Page className="d-flex flex-column">
8772
<PageTitle title="Manage subscription" />

client/web/src/nav/UserNavItem.test.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { MockedTestProvider } from '@sourcegraph/shared/src/testing/apollo'
99
import { AnchorLink, RouterLink, setLinkComponent } from '@sourcegraph/wildcard'
1010
import { renderWithBrandedContext } from '@sourcegraph/wildcard/src/testing'
1111

12-
import { CodyProApiProvider } from '../cody/management/api/react-query/CodyProApiProvider'
13-
1412
import { UserNavItem, type UserNavItemProps } from './UserNavItem'
1513

1614
vi.mock('../util/license', () => ({
@@ -58,22 +56,18 @@ describe('UserNavItem', () => {
5856
emails: [],
5957
}
6058

61-
const isSourcegraphDotCom = true
62-
6359
test('simple', () => {
6460
expect(
6561
render(
6662
<MemoryRouter>
6763
<MockedTestProvider>
68-
<CodyProApiProvider isSourcegraphDotCom={isSourcegraphDotCom}>
69-
<UserNavItem
70-
showKeyboardShortcutsHelp={() => undefined}
71-
authenticatedUser={USER}
72-
isSourcegraphDotCom={true}
73-
showFeedbackModal={() => undefined}
74-
telemetryService={NOOP_TELEMETRY_SERVICE}
75-
/>
76-
</CodyProApiProvider>
64+
<UserNavItem
65+
showKeyboardShortcutsHelp={() => undefined}
66+
authenticatedUser={USER}
67+
isSourcegraphDotCom={true}
68+
showFeedbackModal={() => undefined}
69+
telemetryService={NOOP_TELEMETRY_SERVICE}
70+
/>
7771
</MockedTestProvider>
7872
</MemoryRouter>
7973
).asFragment()
@@ -83,15 +77,13 @@ describe('UserNavItem', () => {
8377
test('logout click triggers page refresh instead of performing client-side only navigation', async () => {
8478
const result = renderWithBrandedContext(
8579
<MockedTestProvider>
86-
<CodyProApiProvider isSourcegraphDotCom={isSourcegraphDotCom}>
87-
<UserNavItem
88-
showKeyboardShortcutsHelp={() => undefined}
89-
authenticatedUser={USER}
90-
isSourcegraphDotCom={isSourcegraphDotCom}
91-
showFeedbackModal={() => undefined}
92-
telemetryService={NOOP_TELEMETRY_SERVICE}
93-
/>
94-
</CodyProApiProvider>
80+
<UserNavItem
81+
showKeyboardShortcutsHelp={() => undefined}
82+
authenticatedUser={USER}
83+
isSourcegraphDotCom={true}
84+
showFeedbackModal={() => undefined}
85+
telemetryService={NOOP_TELEMETRY_SERVICE}
86+
/>
9587
</MockedTestProvider>
9688
)
9789

client/web/src/nav/UserNavItem.tsx

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import {
2626
} from '@sourcegraph/wildcard'
2727

2828
import type { AuthenticatedUser } from '../auth'
29-
import { CodyProRoutes } from '../cody/codyProRoutes'
30-
import { useSubscriptionSummary } from '../cody/management/api/react-query/subscriptions'
3129
import { enableDevSettings, isSourcegraphDev, useDeveloperSettings } from '../stores'
3230

3331
import { useNewSearchNavigation } from './new-global-navigation'
@@ -132,7 +130,6 @@ export const UserNavItem: FC<UserNavItemProps> = props => {
132130
<MenuHeader className={styles.dropdownHeader}>
133131
Signed in as <strong>@{authenticatedUser.username}</strong>
134132
</MenuHeader>
135-
{isSourcegraphDotCom && <CodyProSection />}
136133
<MenuDivider className={styles.dropdownDivider} />
137134
<MenuLink as={Link} to={authenticatedUser.settingsURL!}>
138135
Settings
@@ -244,28 +241,3 @@ export const UserNavItem: FC<UserNavItemProps> = props => {
244241
</>
245242
)
246243
}
247-
248-
const CodyProSection: React.FC = () => {
249-
const { data } = useSubscriptionSummary()
250-
251-
if (!data) {
252-
return null
253-
}
254-
255-
return (
256-
<>
257-
<MenuDivider className={styles.dropdownDivider} />
258-
<MenuHeader className={styles.dropdownHeader}>Cody PRO</MenuHeader>
259-
<MenuLink as={Link} to={CodyProRoutes.ManageTeam}>
260-
Manage team
261-
</MenuLink>
262-
263-
{/* only team admins can manage subscription */}
264-
{data.userRole === 'admin' && (
265-
<MenuLink as={Link} to={CodyProRoutes.SubscriptionManage}>
266-
Manage subscription
267-
</MenuLink>
268-
)}
269-
</>
270-
)
271-
}

0 commit comments

Comments
 (0)