-
Notifications
You must be signed in to change notification settings - Fork 351
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
import { ActionItem } from './ActionItem' | ||
import styles from './PromptList.module.css' | ||
import { usePromptsQuery } from './usePromptsQuery' | ||
import { commandRowValue } from './utils' | ||
import { commandRowValue, shouldShowAction } from './utils' | ||
Check failure on line 21 in vscode/webviews/components/promptList/PromptList.tsx
|
||
|
||
const BUILT_IN_PROMPTS_CODE: Record<string, number> = { | ||
'document-code': 1, | ||
|
@@ -156,23 +156,37 @@ | |
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)) | ||
Comment on lines
+169
to
+171
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really would suggest to implement this as
Otherwise we have two variables in scope that represent actions ( Of course we can also build just a single filter condition to avoid this, but that seems more tricky. |
||
|
||
// Second pass: apply prompt filters based on configuration | ||
if (promptFilters?.core) { | ||
return actions.filter(action => action.actionType === 'prompt' && action.builtin) | ||
return filteredActions.filter(action => action.actionType === 'prompt' && action.builtin) | ||
} | ||
const shouldExcludeBuiltinCommands = | ||
|
||
const hasCustomFilters = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The naming seems to imply that |
||
promptFilters?.promoted || promptFilters?.owner || promptFilters?.tags | ||
if (shouldExcludeBuiltinCommands) { | ||
return actions.filter(action => action.actionType === 'prompt' && !action.builtin) | ||
if (hasCustomFilters) { | ||
return filteredActions.filter( | ||
action => action.actionType === 'prompt' && !action.builtin | ||
) | ||
} | ||
return actions | ||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep the empty line and the comment above the following line. |
||
const allActions = showOnlyPromptInsertableCommands | ||
? result?.actions.filter(action => action.actionType === 'prompt' || action.mode === 'ask') ?? [] | ||
: result?.actions ?? [] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function should either be defined outside the component or it should replace
shouldShowAction
which you don't need anymore.