Skip to content

Commit

Permalink
Add generator entrypoint name in addition to plugin name to main view…
Browse files Browse the repository at this point in the history
… search results
  • Loading branch information
Exidex committed Jan 6, 2025
1 parent a5d69e8 commit 6b0e3fa
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rust/client/src/ui/search_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ pub fn search_list<'a>(
.width(Length::Fill)
.into();

let sub_text: Element<_> = text(&search_result.plugin_name)
let sub_text = match &search_result.entrypoint_generator_name {
None => &search_result.plugin_name,
Some(entrypoint_generator_name) => &format!("{} - {}", entrypoint_generator_name, &search_result.plugin_name)
};

let sub_text: Element<_> = text(sub_text.clone())
.shaping(Shaping::Advanced)
.themed(TextStyle::MainListItemSubtext);

let sub_text: Element<_> = container(sub_text)
.themed(ContainerStyle::MainListItemSubText); // FIXME find a way to set padding based on whether the scroll bar is visible
.themed(ContainerStyle::MainListItemSubText); // FIXME find a way to set padding based on whether the scroll bar is visible

let mut button_content = vec![];

Expand Down
1 change: 1 addition & 0 deletions rust/common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ pub struct SearchResult {
pub plugin_name: String,
pub entrypoint_id: EntrypointId,
pub entrypoint_name: String,
pub entrypoint_generator_name: Option<String>,
pub entrypoint_icon: Option<String>,
pub entrypoint_type: SearchResultEntrypointType,
pub entrypoint_actions: Vec<SearchResultEntrypointAction>,
Expand Down
12 changes: 12 additions & 0 deletions rust/server/src/plugins/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,11 @@ impl BackendForPluginRuntimeApi for BackendForPluginRuntimeApiImpl {
shortcuts.insert(id.clone(), entrypoint_shortcuts);
}

let generator_names: HashMap<_, _> = entrypoints.iter()
.filter(|entrypoint| matches!(db_entrypoint_from_str(&entrypoint.entrypoint_type), DbPluginEntrypointType::EntrypointGenerator))
.map(|entrypoint| (entrypoint.id.clone(), entrypoint.name.clone()))
.collect();

let mut generated_search_items = generated_commands.into_iter()
.map(|item| {
let entrypoint_icon_path = match item.entrypoint_icon {
Expand Down Expand Up @@ -767,6 +772,10 @@ impl BackendForPluginRuntimeApi for BackendForPluginRuntimeApiImpl {
})
.collect();

let entrypoint_generator_name = generator_names
.get(&item.generator_entrypoint_id)
.map(|name| name.to_string());

Ok(SearchIndexItem {
entrypoint_type: SearchResultEntrypointType::Generated,
entrypoint_id: EntrypointId::from_string(item.entrypoint_id),
Expand All @@ -775,6 +784,7 @@ impl BackendForPluginRuntimeApi for BackendForPluginRuntimeApiImpl {
entrypoint_frecency,
entrypoint_actions,
entrypoint_accessories,
entrypoint_generator_name,
})
})
.collect::<anyhow::Result<Vec<_>>>()?;
Expand Down Expand Up @@ -817,6 +827,7 @@ impl BackendForPluginRuntimeApi for BackendForPluginRuntimeApiImpl {
Ok(Some(SearchIndexItem {
entrypoint_type: SearchResultEntrypointType::Command,
entrypoint_name: entrypoint.name,
entrypoint_generator_name: None,
entrypoint_id,
entrypoint_icon_path,
entrypoint_frecency,
Expand All @@ -828,6 +839,7 @@ impl BackendForPluginRuntimeApi for BackendForPluginRuntimeApiImpl {
Ok(Some(SearchIndexItem {
entrypoint_type: SearchResultEntrypointType::View,
entrypoint_name: entrypoint.name,
entrypoint_generator_name: None,
entrypoint_id,
entrypoint_icon_path,
entrypoint_frecency,
Expand Down
4 changes: 4 additions & 0 deletions rust/server/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct SearchIndex {
}

struct EntrypointData {
entrypoint_generator_name: Option<String>,
entrypoint_type: SearchResultEntrypointType,
icon_path: Option<String>,
frecency: f64,
Expand All @@ -47,6 +48,7 @@ enum EntrypointActionType {
pub struct SearchIndexItem {
pub entrypoint_type: SearchResultEntrypointType,
pub entrypoint_name: String,
pub entrypoint_generator_name: Option<String>,
pub entrypoint_id: EntrypointId,
pub entrypoint_icon_path: Option<String>,
pub entrypoint_frecency: f64,
Expand Down Expand Up @@ -163,6 +165,7 @@ impl SearchIndex {
.collect();

let data = EntrypointData {
entrypoint_generator_name: item.entrypoint_generator_name,
entrypoint_type: item.entrypoint_type,
icon_path: item.entrypoint_icon_path,
frecency: item.entrypoint_frecency,
Expand Down Expand Up @@ -288,6 +291,7 @@ impl SearchIndex {
let result_item = SearchResult {
entrypoint_type: entrypoint_data.entrypoint_type.clone(),
entrypoint_name,
entrypoint_generator_name: entrypoint_data.entrypoint_generator_name.clone(),
entrypoint_id,
entrypoint_icon: entrypoint_data.icon_path.clone(),
plugin_name,
Expand Down

0 comments on commit 6b0e3fa

Please sign in to comment.