Skip to content

Commit

Permalink
Fix last used prompts ordering (sourcegraph#5848)
Browse files Browse the repository at this point in the history
Fixes
https://linear.app/sourcegraph/issue/SRCH-1131/make-prompts-dropdown-menu-a-recently-used-list

This PR changes how smart recently used prompt ordering works.
Previously, we counted the number of times a user clicked on prompts and
used this aggregated count value to sort the list of prompts.

Now we just set the timestamp to the used prompt and sort it by this, so
it's truly the most recently used prompt (always will be on top of the
list)

## Test plan
- Check that in the prompt list you can see the right order of prompts
  • Loading branch information
vovakulikov authored and PriNova committed Oct 11, 2024
1 parent 1334cb7 commit d04e083
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion vscode/webviews/components/promptList/PromptList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const PromptList: FC<PromptListProps> = props => {

const endpointURL = new URL(useConfig().authStatus.endpoint)
const telemetryRecorder = useTelemetryRecorder()
const [lastUsedActions = {}] = useLocalStorage<Record<string, number>>('last-used-actions', {})
const [lastUsedActions = {}] = useLocalStorage<Record<string, number>>('last-used-actions-v2', {})

const telemetryPublicMetadata: Record<string, number> = {
[`in${telemetryLocation}`]: 1,
Expand Down
5 changes: 2 additions & 3 deletions vscode/webviews/prompts/PromptsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ export const PromptsTab: React.FC<{
export function useActionSelect() {
const dispatchClientAction = useClientActionDispatcher()
const [lastUsedActions = {}, persistValue] = useLocalStorage<Record<string, number>>(
'last-used-actions',
'last-used-actions-v2',
{}
)

return (action: Action, setView: (view: View) => void) => {
try {
const actionKey = action.actionType === 'prompt' ? action.id : action.key
const lastUsedActionCount = lastUsedActions[actionKey] ?? 0
persistValue({ ...lastUsedActions, [actionKey]: lastUsedActionCount + 1 })
persistValue({ ...lastUsedActions, [actionKey]: Date.now() })
} catch {
console.error('Failed to persist last used action count')
}
Expand Down

0 comments on commit d04e083

Please sign in to comment.