Skip to content

Commit

Permalink
Order prompts by default (#12268)
Browse files Browse the repository at this point in the history
Prompts in the prompt library will be in A->Z order by default.

Release Notes:

- N/A
  • Loading branch information
iamnbutler authored May 25, 2024
1 parent f7a8696 commit d5fe2c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions crates/assistant/src/prompts/prompt_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ use super::prompt::StaticPrompt;
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct PromptId(pub Uuid);

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum SortOrder {
Alphabetical,
}

#[allow(unused)]
impl PromptId {
pub fn new() -> Self {
Expand Down Expand Up @@ -60,6 +65,22 @@ impl PromptLibrary {
.collect()
}

pub fn sorted_prompts(&self, sort_order: SortOrder) -> Vec<(PromptId, StaticPrompt)> {
let state = self.state.read();

let mut prompts = state
.prompts
.iter()
.map(|(id, prompt)| (*id, prompt.clone()))
.collect::<Vec<_>>();

match sort_order {
SortOrder::Alphabetical => prompts.sort_by(|(_, a), (_, b)| a.title().cmp(&b.title())),
};

prompts
}

pub fn first_prompt_id(&self) -> Option<PromptId> {
let state = self.state.read();
state.prompts.keys().next().cloned()
Expand Down
4 changes: 2 additions & 2 deletions crates/assistant/src/prompts/prompt_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ui::{prelude::*, IconButtonShape, ListItem, ListItemSpacing};
use util::{ResultExt, TryFutureExt};
use workspace::ModalView;

use super::prompt_library::{PromptId, PromptLibrary};
use super::prompt_library::{PromptId, PromptLibrary, SortOrder};
use crate::prompts::prompt::StaticPrompt;

pub struct PromptManager {
Expand Down Expand Up @@ -264,7 +264,7 @@ impl PickerDelegate for PromptManagerDelegate {
let prompt_library = self.prompt_library.clone();
cx.spawn(|picker, mut cx| async move {
async {
let prompts = prompt_library.prompts();
let prompts = prompt_library.sorted_prompts(SortOrder::Alphabetical);
let matching_prompts = prompts
.into_iter()
.filter(|(_, prompt)| {
Expand Down

0 comments on commit d5fe2c8

Please sign in to comment.