Skip to content

Commit

Permalink
Split preference name into id and name
Browse files Browse the repository at this point in the history
  • Loading branch information
Exidex committed Sep 15, 2024
1 parent ea9c795 commit 29649aa
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 101 deletions.
24 changes: 16 additions & 8 deletions dev_plugin/gauntlet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ A reasonably long plugin description that doesn't contain any usefull informatio
"""

[[preferences]]
name = 'testBool'
id = 'testBool'
name = 'Test Boolean'
type = 'bool'
default = true
description = "test bool description"
Expand All @@ -31,42 +32,49 @@ description = "test action description 2"
shortcut = { key = 'B', kind = 'main'}

[[entrypoint.preferences]]
name = 'testBool'
id = 'testBool'
name = 'Test Boolean'
type = 'bool'
default = true
description = "test bool description"

[[entrypoint.preferences]]
name = 'testEnum'
id = 'testEnum'
name = 'Test Enum'
type = 'enum'
default = 'item'
enum_values = [{ label = 'Item', value = 'item'}, { label = 'Item 2', value = 'item_2'}]
description = "test enum description"

[[entrypoint.preferences]]
name = 'testListOfStrings'
id = 'testListOfStrings'
name = 'Test List of Strings'
type = 'list_of_strings'
description = "test list of strings description"

[[entrypoint.preferences]]
name = 'testListOfNumbers'
id = 'testListOfNumbers'
name = 'Test List of Numbers'
type = 'list_of_numbers'
description = "test list of numbers description"

[[entrypoint.preferences]]
name = 'testListOfEnums'
id = 'testListOfEnums'
name = 'Test List of Enums'
type = 'list_of_enums'
description = "test list of enums description"
enum_values = [{ label = 'Item', value = 'item'}, { label = 'Item 2', value = 'item_2'}]

[[entrypoint.preferences]]
name = 'testNum'
id = 'testNum'
name = 'Test Num'
type = 'number'
default = 2
description = "test number description"

[[entrypoint.preferences]]
name = 'testStr'
id = 'testStr'
name = 'Test Str'
type = 'string'
default = 'test_value'
description = "test string description"
Expand Down
7 changes: 7 additions & 0 deletions rust/common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,31 +325,38 @@ pub enum PluginPreferenceUserData {
#[derive(Debug, Clone)]
pub enum PluginPreference {
Number {
name: String,
default: Option<f64>,
description: String,
},
String {
name: String,
default: Option<String>,
description: String,
},
Enum {
name: String,
default: Option<String>,
description: String,
enum_values: Vec<PreferenceEnumValue>,
},
Bool {
name: String,
default: Option<bool>,
description: String,
},
ListOfStrings {
name: String,
default: Option<Vec<String>>,
description: String,
},
ListOfNumbers {
name: String,
default: Option<Vec<f64>>,
description: String,
},
ListOfEnums {
name: String,
default: Option<Vec<String>>,
enum_values: Vec<PreferenceEnumValue>,
description: String,
Expand Down
4 changes: 2 additions & 2 deletions rust/common/src/rpc/backend_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,11 @@ impl BackendApi {
})
}

pub async fn set_preference_value(&mut self, plugin_id: PluginId, entrypoint_id: Option<EntrypointId>, name: String, user_data: PluginPreferenceUserData) -> Result<(), BackendApiError> {
pub async fn set_preference_value(&mut self, plugin_id: PluginId, entrypoint_id: Option<EntrypointId>, id: String, user_data: PluginPreferenceUserData) -> Result<(), BackendApiError> {
let request = RpcSetPreferenceValueRequest {
plugin_id: plugin_id.to_string(),
entrypoint_id: entrypoint_id.map(|id| id.to_string()).unwrap_or_default(),
preference_name: name,
preference_id: id,
preference_value: Some(plugin_preference_user_data_to_rpc(user_data)),
};

Expand Down
6 changes: 3 additions & 3 deletions rust/common/src/rpc/backend_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub trait BackendServer {
&self,
plugin_id: PluginId,
entrypoint_id: Option<EntrypointId>,
preference_name: String,
preference_id: String,
preference_value: PluginPreferenceUserData
) -> anyhow::Result<()>;

Expand Down Expand Up @@ -203,10 +203,10 @@ impl RpcBackend for RpcBackendServerImpl {
Some(EntrypointId::from_string(request.entrypoint_id))
};

let preference_name = request.preference_name;
let preference_id = request.preference_id;
let preference_value = request.preference_value.unwrap();

self.server.set_preference_value(plugin_id, entrypoint_id, preference_name, plugin_preference_user_data_from_rpc(preference_value))
self.server.set_preference_value(plugin_id, entrypoint_id, preference_id, plugin_preference_user_data_from_rpc(preference_value))
.await
.map_err(|err| Status::internal(format!("{:#}", err)))?;

Expand Down
46 changes: 30 additions & 16 deletions rust/common/src/rpc/grpc_convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::collections::HashMap;

use anyhow::anyhow;

use crate::model::{EntrypointId, PluginId, PluginPreference, PluginPreferenceUserData, PreferenceEnumValue, UiPropertyValue, SearchResult, SearchResultEntrypointType, UiWidget};
use crate::rpc::grpc::{rpc_ui_property_value, RpcEntrypointTypeSearchResult, RpcEnumValue, RpcPluginPreference, RpcPluginPreferenceUserData, RpcPluginPreferenceValueType, RpcSearchResult, RpcUiPropertyValue, RpcUiPropertyValueObject, RpcUiWidget, RpcUiWidgetId};
use crate::model::{EntrypointId, PluginId, PluginPreference, PluginPreferenceUserData, PreferenceEnumValue, SearchResult, SearchResultEntrypointType, UiPropertyValue, UiWidget};
use crate::rpc::grpc::rpc_ui_property_value::Value;
use crate::rpc::grpc::{RpcEntrypointTypeSearchResult, RpcEnumValue, RpcPluginPreference, RpcPluginPreferenceUserData, RpcPluginPreferenceValueType, RpcSearchResult, RpcUiPropertyValue, RpcUiPropertyValueObject, RpcUiWidget, RpcUiWidgetId};

pub(crate) fn ui_widget_to_rpc(value: UiWidget) -> RpcUiWidget {
let children = value.widget_children.into_iter()
Expand Down Expand Up @@ -276,61 +276,68 @@ pub fn plugin_preference_user_data_to_rpc(value: PluginPreferenceUserData) -> Rp

pub fn plugin_preference_to_rpc(value: PluginPreference) -> RpcPluginPreference {
match value {
PluginPreference::Number { default, description } => {
PluginPreference::Number { name, default, description } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::Number.into(),
default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::Number(value)) }),
default: default.map(|value| RpcUiPropertyValue { value: Some(Value::Number(value)) }),
name,
description,
..RpcPluginPreference::default()
}
}
PluginPreference::String { default, description } => {
PluginPreference::String { name, default, description } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::String.into(),
default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }),
default: default.map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }),
name,
description,
..RpcPluginPreference::default()
}
}
PluginPreference::Enum { default, description, enum_values } => {
PluginPreference::Enum { name, default, description, enum_values } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::Enum.into(),
default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }),
default: default.map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }),
name,
description,
enum_values: enum_values.into_iter()
.map(|value| RpcEnumValue { label: value.label, value: value.value })
.collect(),
..RpcPluginPreference::default()
}
}
PluginPreference::Bool { default, description } => {
PluginPreference::Bool { name, default, description } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::Bool.into(),
default: default.map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::Bool(value)) }),
default: default.map(|value| RpcUiPropertyValue { value: Some(Value::Bool(value)) }),
name,
description,
..RpcPluginPreference::default()
}
}
PluginPreference::ListOfStrings { default, description } => {
PluginPreference::ListOfStrings { name, default, description } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::ListOfStrings.into(),
default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }).collect()).unwrap_or(vec![]),
default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }).collect()).unwrap_or(vec![]),
name,
description,
..RpcPluginPreference::default()
}
}
PluginPreference::ListOfNumbers { default, description } => {
PluginPreference::ListOfNumbers { name, default, description } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::ListOfNumbers.into(),
default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::Number(value)) }).collect()).unwrap_or(vec![]),
default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(Value::Number(value)) }).collect()).unwrap_or(vec![]),
name,
description,
..RpcPluginPreference::default()
}
}
PluginPreference::ListOfEnums { default, enum_values, description } => {
PluginPreference::ListOfEnums { name, default, enum_values, description } => {
RpcPluginPreference {
r#type: RpcPluginPreferenceValueType::ListOfEnums.into(),
default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(rpc_ui_property_value::Value::String(value)) }).collect()).unwrap_or(vec![]),
default_list: default.map(|value| value.into_iter().map(|value| RpcUiPropertyValue { value: Some(Value::String(value)) }).collect()).unwrap_or(vec![]),
name,
description,
enum_values: enum_values.into_iter()
.map(|value| RpcEnumValue { label: value.label, value: value.value })
Expand All @@ -355,6 +362,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::Number {
default,
name: value.name,
description: value.description,
}
}
Expand All @@ -369,6 +377,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::String {
default,
name: value.name,
description: value.description,
}
}
Expand All @@ -383,6 +392,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::Enum {
default,
name: value.name,
description: value.description,
enum_values: value.enum_values.into_iter()
.map(|value| PreferenceEnumValue { label: value.label, value: value.value })
Expand All @@ -400,6 +410,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::Bool {
default,
name: value.name,
description: value.description,
}
}
Expand All @@ -423,6 +434,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::ListOfStrings {
default: default_list,
name: value.name,
description: value.description,
}
}
Expand All @@ -446,6 +458,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::ListOfNumbers {
default: default_list,
name: value.name,
description: value.description,
}
}
Expand All @@ -469,6 +482,7 @@ pub fn plugin_preference_from_rpc(value: RpcPluginPreference) -> PluginPreferenc

PluginPreference::ListOfEnums {
default: default_list,
name: value.name,
enum_values: value.enum_values.into_iter()
.map(|value| PreferenceEnumValue { label: value.label, value: value.value })
.collect(),
Expand Down
14 changes: 7 additions & 7 deletions rust/management_client/src/views/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ impl ManagementAppPluginsState {
}
ManagementAppPluginMsgIn::PluginPreferenceMsg(msg) => {
match msg {
PluginPreferencesMsg::UpdatePreferenceValue { plugin_id, entrypoint_id, name, user_data } => {
PluginPreferencesMsg::UpdatePreferenceValue { plugin_id, entrypoint_id, id, user_data } => {
self.preference_user_data
.insert((plugin_id.clone(), entrypoint_id.clone(), name.clone()), user_data.clone());
.insert((plugin_id.clone(), entrypoint_id.clone(), id.clone()), user_data.clone());

let mut backend_api = backend_api.clone();

Command::perform(
async move {
backend_api.set_preference_value(plugin_id, entrypoint_id, name, user_data.to_user_data())
backend_api.set_preference_value(plugin_id, entrypoint_id, id, user_data.to_user_data())
.await?;

Ok(())
Expand Down Expand Up @@ -228,13 +228,13 @@ impl ManagementAppPluginsState {
.map(|(plugin_id, plugin)| {
let mut result = vec![];

for (name, user_data) in &plugin.preferences_user_data {
result.push(((plugin_id.clone(), None, name.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone())))
for (id, user_data) in &plugin.preferences_user_data {
result.push(((plugin_id.clone(), None, id.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone())))
}

for (entrypoint_id, entrypoint) in &plugin.entrypoints {
for (name, user_data) in &entrypoint.preferences_user_data {
result.push(((plugin_id.clone(), Some(entrypoint_id.clone()), name.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone())))
for (id, user_data) in &entrypoint.preferences_user_data {
result.push(((plugin_id.clone(), Some(entrypoint_id.clone()), id.clone()), PluginPreferenceUserDataState::from_user_data(user_data.clone())))
}
}

Expand Down
Loading

0 comments on commit 29649aa

Please sign in to comment.