Skip to content

Commit

Permalink
Allow to force usage of pre-defined endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
pkukielka committed Jan 9, 2025
1 parent 3f908ae commit cb8addf
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 536 deletions.
1 change: 1 addition & 0 deletions vscode/src/chat/chat-view/ChatController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ export class ChatController implements vscode.Disposable, vscode.WebviewViewProv
webviewType,
multipleWebviewsEnabled: !sidebarViewOnly,
internalDebugContext: configuration.internalDebugContext,
allowEndpointChange: configuration.overrideServerEndpoint === undefined,
}
}

Expand Down
1 change: 1 addition & 0 deletions vscode/src/chat/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export interface ConfigurationSubsetForWebview
// Whether support running multiple webviews (e.g. sidebar w/ multiple editor panels).
multipleWebviewsEnabled?: boolean | undefined | null
endpointHistory?: string[] | undefined | null
allowEndpointChange: boolean
}

/**
Expand Down
1 change: 1 addition & 0 deletions vscode/webviews/App.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const dummyVSCodeAPI: VSCodeWrapper = {
experimentalNoodle: false,
smartApply: false,
hasEditCapability: false,
allowEndpointChange: true,
},
clientCapabilities: CLIENT_CAPABILITIES_FIXTURE,
authStatus: {
Expand Down
1 change: 1 addition & 0 deletions vscode/webviews/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const App: React.FunctionComponent<{ vscodeAPI: VSCodeWrapper }> = ({ vsc
codyIDE={config.clientCapabilities.agentIDE}
endpoints={config.config.endpointHistory ?? []}
authStatus={config.authStatus}
allowEndpointChange={config.config.allowEndpointChange}
/>
</div>
) : (
Expand Down
31 changes: 19 additions & 12 deletions vscode/webviews/AuthPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface LoginProps {
codyIDE: CodyIDE
endpoints: string[]
authStatus: AuthStatus
allowEndpointChange: boolean
}

interface SignInButtonProps {
Expand All @@ -38,9 +39,10 @@ export const AuthPage: React.FunctionComponent<React.PropsWithoutRef<LoginProps>
uiKindIsWeb,
vscodeAPI,
authStatus,
allowEndpointChange,
}) => {
const telemetryRecorder = useTelemetryRecorder()
const [isEnterpriseSignin, setIsEnterpriseSignin] = useState(false)
const [isEnterpriseSignin, setIsEnterpriseSignin] = useState(!allowEndpointChange)

// Extracted common button props and styles
const commonButtonProps = {
Expand Down Expand Up @@ -127,25 +129,28 @@ export const AuthPage: React.FunctionComponent<React.PropsWithoutRef<LoginProps>
() => (
<section className="tw-bg-sidebar-background tw-text-sidebar-foreground tw-w-full tw-max-w-md">
<div className="tw-font-semibold tw-text-md tw-my-4 tw-text-muted-foreground">
<Button
onClick={() => setIsEnterpriseSignin(false)}
className="tw-flex tw-justify-between"
variant="ghost"
title="Back to sign-in options list"
>
<ArrowLeftIcon className="tw-mr-3" size={16} />
Back
</Button>
{allowEndpointChange && (
<Button
onClick={() => setIsEnterpriseSignin(false)}
className="tw-flex tw-justify-between"
variant="ghost"
title="Back to sign-in options list"
>
<ArrowLeftIcon className="tw-mr-3" size={16} />
Back
</Button>
)}
<ClientSignInForm
authStatus={authStatus}
vscodeAPI={vscodeAPI}
className="tw-mt-8"
telemetryRecorder={telemetryRecorder}
allowEndpointChange={allowEndpointChange}
/>
</div>
</section>
),
[authStatus, vscodeAPI, telemetryRecorder]
[authStatus, vscodeAPI, telemetryRecorder, allowEndpointChange]
)

return (
Expand Down Expand Up @@ -265,6 +270,7 @@ const WebLogin: React.FunctionComponent<
interface ClientSignInFormProps {
vscodeAPI: VSCodeWrapper
telemetryRecorder: TelemetryRecorder
allowEndpointChange: boolean
authStatus?: AuthStatus
className?: string
}
Expand All @@ -273,7 +279,7 @@ interface ClientSignInFormProps {
* The form allows users to input their Sourcegraph instance URL and access token manually.
*/
const ClientSignInForm: React.FC<ClientSignInFormProps> = memo(
({ className, authStatus, vscodeAPI, telemetryRecorder }) => {
({ className, authStatus, vscodeAPI, telemetryRecorder, allowEndpointChange }) => {
// Combine related state into a single object to reduce re-renders
const [formState, setFormState] = useState({
showAccessTokenField: false,
Expand Down Expand Up @@ -354,6 +360,7 @@ const ClientSignInForm: React.FC<ClientSignInFormProps> = memo(
className="tw-w-full tw-my-2 !tw-p-4"
required
onChange={handleInputChange}
disabled={!allowEndpointChange}
/>
<FormMessage match="typeMismatch">Invalid URL.</FormMessage>
<FormMessage match="valueMissing">URL is required.</FormMessage>
Expand Down
11 changes: 1 addition & 10 deletions vscode/webviews/CodyPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useClientActionDispatcher } from './client/clientState'
import { Notices } from './components/Notices'
import { StateDebugOverlay } from './components/StateDebugOverlay'
import { TabContainer, TabRoot } from './components/shadcn/ui/tabs'
import { AccountTab, HistoryTab, PromptsTab, SettingsTab, TabsBar, View } from './tabs'
import { HistoryTab, PromptsTab, SettingsTab, TabsBar, View } from './tabs'
import type { VSCodeWrapper } from './utils/VSCodeApi'
import { useUserAccountInfo } from './utils/useConfig'
import { useFeatureFlag } from './utils/useFeatureFlags'
Expand Down Expand Up @@ -155,15 +155,6 @@ export const CodyPanel: FunctionComponent<CodyPanelProps> = ({
isPromptsV2Enabled={isPromptsV2Enabled}
/>
)}
{view === View.Account && (
<AccountTab
config={config}
clientCapabilities={clientCapabilities}
authStatus={authStatus}
isDotComUser={isDotComUser}
userProductSubscription={userProductSubscription}
/>
)}
{view === View.Settings && <SettingsTab />}
</TabContainer>
<StateDebugOverlay />
Expand Down
249 changes: 0 additions & 249 deletions vscode/webviews/components/AccountSwitcher.tsx

This file was deleted.

Loading

0 comments on commit cb8addf

Please sign in to comment.