mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 04:04:55 +08:00
fix(wasm): fix wasm function to return the categories for keys with their description respectively (#3023)
This commit is contained in:
@ -254,12 +254,25 @@ pub fn add_two(n1: i64, n2: i64) -> i64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[wasm_bindgen(js_name = getDescriptionCategory)]
|
#[wasm_bindgen(js_name = getDescriptionCategory)]
|
||||||
pub fn get_description_category(key: &str) -> JsResult {
|
pub fn get_description_category() -> JsResult {
|
||||||
let key = dir::DirKeyKind::from_str(key).map_err(|_| "Invalid key received".to_string())?;
|
let keys = dir::DirKeyKind::VARIANTS
|
||||||
|
.iter()
|
||||||
|
.copied()
|
||||||
|
.filter(|s| s != &"Connector")
|
||||||
|
.collect::<Vec<&'static str>>();
|
||||||
|
let mut category: HashMap<Option<&str>, Vec<types::Details<'_>>> = HashMap::new();
|
||||||
|
for key in keys {
|
||||||
|
let dir_key =
|
||||||
|
dir::DirKeyKind::from_str(key).map_err(|_| "Invalid key received".to_string())?;
|
||||||
|
let details = types::Details {
|
||||||
|
description: dir_key.get_detailed_message(),
|
||||||
|
kind: dir_key.clone(),
|
||||||
|
};
|
||||||
|
category
|
||||||
|
.entry(dir_key.get_str("Category"))
|
||||||
|
.and_modify(|val| val.push(details.clone()))
|
||||||
|
.or_insert(vec![details]);
|
||||||
|
}
|
||||||
|
|
||||||
let result = types::Details {
|
Ok(serde_wasm_bindgen::to_value(&category)?)
|
||||||
description: key.get_detailed_message(),
|
|
||||||
category: key.get_str("Category"),
|
|
||||||
};
|
|
||||||
Ok(serde_wasm_bindgen::to_value(&result)?)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
|
use euclid::frontend::dir::DirKeyKind;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
#[derive(Serialize, Clone)]
|
#[derive(Serialize, Clone)]
|
||||||
pub struct Details<'a> {
|
pub struct Details<'a> {
|
||||||
pub description: Option<&'a str>,
|
pub description: Option<&'a str>,
|
||||||
pub category: Option<&'a str>,
|
pub kind: DirKeyKind,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user