Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: hide edit prompts on the web #6815

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions vscode/webviews/components/promptList/PromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { ActionItem } from './ActionItem'
import styles from './PromptList.module.css'
import { usePromptsQuery } from './usePromptsQuery'
import { commandRowValue } from './utils'
import { commandRowValue, shouldShowAction } from './utils'

const BUILT_IN_PROMPTS_CODE: Record<string, number> = {
'document-code': 1,
Expand Down Expand Up @@ -159,19 +159,31 @@ export const PromptList: FC<PromptListProps> = props => {

const filteredActions = useCallback(
(actions: Action[]) => {
const { clientCapabilities } = useConfig()
const isEditEnabled = clientCapabilities.edit !== 'none'

if (promptFilters?.core) {
return actions.filter(action => action.actionType === 'prompt' && action.builtin)
return actions.filter(
action =>
action.actionType === 'prompt' &&
action.builtin &&
shouldShowAction(action, isEditEnabled)
)
}
const shouldExcludeBuiltinCommands =
promptFilters?.promoted || promptFilters?.owner || promptFilters?.tags
if (shouldExcludeBuiltinCommands) {
return actions.filter(action => action.actionType === 'prompt' && !action.builtin)
return actions.filter(
action =>
action.actionType === 'prompt' &&
!action.builtin &&
shouldShowAction(action, isEditEnabled)
)
}
return actions
return actions.filter(action => shouldShowAction(action, isEditEnabled))
taiyab marked this conversation as resolved.
Show resolved Hide resolved
},
[promptFilters]
)

// Don't show builtin commands to insert in the prompt editor.
const allActions = showOnlyPromptInsertableCommands
? result?.actions.filter(action => action.actionType === 'prompt' || action.mode === 'ask') ?? []
Expand Down
7 changes: 7 additions & 0 deletions vscode/webviews/components/promptList/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ import type { Action } from '@sourcegraph/cody-shared'
export function commandRowValue(row: Action): string {
return row.actionType === 'prompt' ? `prompt-${row.id}` : `command-${row.key}`
}

export const shouldShowAction = (action: Action, isEditEnabled: boolean): boolean => {
const isActionEditLike =
action.actionType === 'prompt' ? action.mode !== 'CHAT' : action.mode !== 'ask'

return isEditEnabled || !isActionEditLike
}
taiyab marked this conversation as resolved.
Show resolved Hide resolved
Loading