From 2494e78e5324e3844918ba9f0dcdf783552a2e01 Mon Sep 17 00:00:00 2001 From: Taiyab Raja Date: Mon, 27 Jan 2025 12:37:40 +0000 Subject: [PATCH 1/2] Hide edit prompts on the web --- .../components/promptList/PromptList.tsx | 22 ++++++++++++++----- .../webviews/components/promptList/utils.ts | 7 ++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/vscode/webviews/components/promptList/PromptList.tsx b/vscode/webviews/components/promptList/PromptList.tsx index 5ffe72508320..65da4d3f50c1 100644 --- a/vscode/webviews/components/promptList/PromptList.tsx +++ b/vscode/webviews/components/promptList/PromptList.tsx @@ -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 = { 'document-code': 1, @@ -159,19 +159,31 @@ export const PromptList: FC = 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)) }, [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') ?? [] diff --git a/vscode/webviews/components/promptList/utils.ts b/vscode/webviews/components/promptList/utils.ts index 683b9e319fda..cb24cab1e044 100644 --- a/vscode/webviews/components/promptList/utils.ts +++ b/vscode/webviews/components/promptList/utils.ts @@ -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 +} From 7e910c751246d092af1227e9a6fc87bc91788e7c Mon Sep 17 00:00:00 2001 From: Taiyab Raja Date: Mon, 27 Jan 2025 13:53:45 +0000 Subject: [PATCH 2/2] Tidy ups --- .../components/promptList/PromptList.tsx | 36 ++++++++++--------- .../webviews/components/promptList/utils.ts | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/vscode/webviews/components/promptList/PromptList.tsx b/vscode/webviews/components/promptList/PromptList.tsx index 65da4d3f50c1..7b97ff2936dd 100644 --- a/vscode/webviews/components/promptList/PromptList.tsx +++ b/vscode/webviews/components/promptList/PromptList.tsx @@ -156,35 +156,37 @@ export const PromptList: FC = props => { error, ] ) - const filteredActions = useCallback( (actions: Action[]) => { const { clientCapabilities } = useConfig() const isEditEnabled = clientCapabilities.edit !== 'none' + function isEditActionLike(action: Action): boolean { + return action.actionType === 'prompt' ? action.mode !== 'CHAT' : action.mode !== 'ask' + } + + // First pass: filter out edit-requiring actions if edit is disabled + const filteredActions = isEditEnabled + ? actions + : actions.filter(action => !isEditActionLike(action)) + + // Second pass: apply prompt filters based on configuration if (promptFilters?.core) { - return actions.filter( - action => - action.actionType === 'prompt' && - action.builtin && - shouldShowAction(action, isEditEnabled) - ) + return filteredActions.filter(action => action.actionType === 'prompt' && action.builtin) } - const shouldExcludeBuiltinCommands = + + const hasCustomFilters = promptFilters?.promoted || promptFilters?.owner || promptFilters?.tags - if (shouldExcludeBuiltinCommands) { - return actions.filter( - action => - action.actionType === 'prompt' && - !action.builtin && - shouldShowAction(action, isEditEnabled) + if (hasCustomFilters) { + return filteredActions.filter( + action => action.actionType === 'prompt' && !action.builtin ) } - return actions.filter(action => shouldShowAction(action, isEditEnabled)) + + return filteredActions }, [promptFilters] - ) - // Don't show builtin commands to insert in the prompt editor. + ) // Don't show builtin commands to insert in the prompt editor. const allActions = showOnlyPromptInsertableCommands ? result?.actions.filter(action => action.actionType === 'prompt' || action.mode === 'ask') ?? [] : result?.actions ?? [] diff --git a/vscode/webviews/components/promptList/utils.ts b/vscode/webviews/components/promptList/utils.ts index cb24cab1e044..1f9995e74cf9 100644 --- a/vscode/webviews/components/promptList/utils.ts +++ b/vscode/webviews/components/promptList/utils.ts @@ -4,7 +4,7 @@ export function commandRowValue(row: Action): string { return row.actionType === 'prompt' ? `prompt-${row.id}` : `command-${row.key}` } -export const shouldShowAction = (action: Action, isEditEnabled: boolean): boolean => { +export function shouldShowAction(action: Action, isEditEnabled: boolean): boolean { const isActionEditLike = action.actionType === 'prompt' ? action.mode !== 'CHAT' : action.mode !== 'ask'