Skip to content

Commit

Permalink
Fix edit intent setting for jetbrains backport (#6397)
Browse files Browse the repository at this point in the history
<img width="1281" alt="image"
src="https://github.com/user-attachments/assets/0004e085-2421-4073-9957-e22f75bd2183"
/>

This PR has these fixes for jetbrains
## Test plan

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->

## Changelog

<!-- OPTIONAL; info at
https://www.notion.so/sourcegraph/Writing-a-changelog-entry-dd997f411d524caabf0d8d38a24a878c
-->

Co-authored-by: Naman Kumar <[email protected]>
  • Loading branch information
arafatkatze and thenamankumar authored Dec 17, 2024
1 parent 21bbf7b commit 1c14645
Showing 1 changed file with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ChatMessage } from '@sourcegraph/cody-shared'
import { CodyIDE, FeatureFlag } from '@sourcegraph/cody-shared'
import { CodyIDE } from '@sourcegraph/cody-shared'
import clsx from 'clsx'
import { BadgeCheck, Pencil, Search } from 'lucide-react'
import type { FC } from 'react'
Expand All @@ -11,7 +11,6 @@ import { ToolbarPopoverItem } from '../../../../../../components/shadcn/ui/toolb
import { Tooltip, TooltipContent, TooltipTrigger } from '../../../../../../components/shadcn/ui/tooltip'
import { useConfig } from '../../../../../../utils/useConfig'
import { useExperimentalOneBox } from '../../../../../../utils/useExperimentalOneBox'
import { useFeatureFlag } from '../../../../../../utils/useFeatureFlags'
import { CodyIcon } from '../../../../../components/CodyIcon'

export type SubmitButtonState = 'submittable' | 'emptyEditorValue' | 'waitingResponseComplete'
Expand All @@ -20,9 +19,10 @@ interface IntentOption {
title: string
icon: React.FC<{ className?: string }>
intent: ChatMessage['intent']
hidden?: boolean
}

function getIntentOptions(ide: CodyIDE, showEditIntent?: boolean): IntentOption[] {
function getIntentOptions(ide: CodyIDE): IntentOption[] {
const standardOneBoxIntents: IntentOption[] = [
{
title: 'Best for question',
Expand All @@ -41,7 +41,7 @@ function getIntentOptions(ide: CodyIDE, showEditIntent?: boolean): IntentOption[
},
]

if (ide === CodyIDE.Web || !showEditIntent) {
if (ide === CodyIDE.Web) {
return standardOneBoxIntents
}

Expand All @@ -51,6 +51,7 @@ function getIntentOptions(ide: CodyIDE, showEditIntent?: boolean): IntentOption[
title: 'Edit Code',
icon: Pencil,
intent: 'edit',
hidden: true,
},
]
}
Expand All @@ -68,12 +69,7 @@ export const SubmitButton: FC<{
clientCapabilities: { agentIDE },
} = useConfig()

const showEditCodeIntent = useFeatureFlag(FeatureFlag.CodyExperimentalShowEditCodeIntent)

const intentOptions = useMemo(
() => getIntentOptions(agentIDE, showEditCodeIntent),
[agentIDE, showEditCodeIntent]
)
const intentOptions = useMemo(() => getIntentOptions(agentIDE), [agentIDE])

if (state === 'waitingResponseComplete') {
return (
Expand Down Expand Up @@ -104,7 +100,7 @@ export const SubmitButton: FC<{

return (
<div className="tw-flex tw-items-center">
{experimentalOneBoxEnabled && selectedIntent && (
{experimentalOneBoxEnabled && selectedIntent && !selectedIntent.hidden && (
<selectedIntent.icon className="tw-size-8 tw-mr-2" />
)}
<Tooltip>
Expand Down Expand Up @@ -146,21 +142,25 @@ export const SubmitButton: FC<{
popoverContent={close => (
<Command>
<CommandList className="tw-p-2">
{intentOptions.map(option => (
<CommandItem
key={option.intent ?? option.title}
onSelect={() => {
onSelectIntent?.(option.intent)
close()
}}
className="tw-flex tw-text-left tw-justify-between tw-rounded-sm"
>
<div className="tw-flex tw-items-center tw-gap-2">
<option.icon className="tw-size-8" />
{option.title}
</div>
</CommandItem>
))}
{intentOptions.map(
option =>
// biome-ignore lint/correctness/useJsxKeyInIterable: no key required for false
!option.hidden && (
<CommandItem
key={option.intent ?? option.title}
onSelect={() => {
onSelectIntent?.(option.intent)
close()
}}
className="tw-flex tw-text-left tw-justify-between tw-rounded-sm"
>
<div className="tw-flex tw-items-center tw-gap-2">
<option.icon className="tw-size-8" />
{option.title}
</div>
</CommandItem>
)
)}
</CommandList>
</Command>
)}
Expand Down

0 comments on commit 1c14645

Please sign in to comment.