treewide: cleanup
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ia01590cdeed872cc8ebd16f6ca95f3cc6a6a6964
This commit is contained in:
parent
3a565689c3
commit
df1c46fa5c
16 changed files with 258 additions and 219 deletions
|
|
@ -110,8 +110,12 @@ pub fn PluginViewRenderer(props: PluginViewProps) -> Element {
|
|||
modal,
|
||||
local_state,
|
||||
};
|
||||
let page_data =
|
||||
use_plugin_data(props.client, data_sources, refresh, props.allowed_endpoints);
|
||||
let page_data = use_plugin_data(
|
||||
props.client,
|
||||
data_sources,
|
||||
refresh,
|
||||
props.allowed_endpoints,
|
||||
);
|
||||
|
||||
// Consume pending navigation requests and forward to the parent
|
||||
use_effect(move || {
|
||||
|
|
@ -151,7 +155,7 @@ pub fn PluginViewRenderer(props: PluginViewProps) -> Element {
|
|||
onclick: move |_| modal.set(None),
|
||||
"×"
|
||||
}
|
||||
{ render_element(&elem, &page_data.read(), &HashMap::new(), ctx) }
|
||||
{ render_element(&elem, &page_data.read(), &actions, ctx) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -318,44 +322,37 @@ fn PluginDataTable(props: PluginDataTableProps) -> Element {
|
|||
let row_val = row;
|
||||
rsx! {
|
||||
tr {
|
||||
for col in props.columns.clone() {
|
||||
for col in &props.columns {
|
||||
td { "{extract_cell(&row_val, &col.key)}" }
|
||||
}
|
||||
if !props.row_actions.is_empty() {
|
||||
td { class: "row-actions",
|
||||
for act in props.row_actions.clone() {
|
||||
for act in &props.row_actions {
|
||||
{
|
||||
let action = act.action.clone();
|
||||
let row_data = row_val.clone();
|
||||
let variant_class =
|
||||
button_variant_class(&act.variant);
|
||||
let page_actions = props.actions.clone();
|
||||
let success_msg: Option<String> =
|
||||
match &act.action {
|
||||
ActionRef::Special(_) => None,
|
||||
ActionRef::Name(name) => props
|
||||
.actions
|
||||
.get(name)
|
||||
.and_then(|a| {
|
||||
a.success_message.clone()
|
||||
}),
|
||||
ActionRef::Inline(a) => {
|
||||
a.success_message.clone()
|
||||
},
|
||||
};
|
||||
let error_msg: Option<String> =
|
||||
match &act.action {
|
||||
ActionRef::Special(_) => None,
|
||||
ActionRef::Name(name) => props
|
||||
.actions
|
||||
.get(name)
|
||||
.and_then(|a| {
|
||||
a.error_message.clone()
|
||||
}),
|
||||
ActionRef::Inline(a) => {
|
||||
a.error_message.clone()
|
||||
},
|
||||
};
|
||||
let (success_msg, error_msg): (
|
||||
Option<String>,
|
||||
Option<String>,
|
||||
) = match &act.action {
|
||||
ActionRef::Special(_) => (None, None),
|
||||
ActionRef::Name(name) => props
|
||||
.actions
|
||||
.get(name)
|
||||
.map_or((None, None), |a| {
|
||||
(
|
||||
a.success_message.clone(),
|
||||
a.error_message.clone(),
|
||||
)
|
||||
}),
|
||||
ActionRef::Inline(a) => (
|
||||
a.success_message.clone(),
|
||||
a.error_message.clone(),
|
||||
),
|
||||
};
|
||||
let ctx = props.ctx;
|
||||
// Pre-compute data JSON at render time to
|
||||
// avoid moving props.data into closures.
|
||||
|
|
@ -489,7 +486,8 @@ pub fn render_element(
|
|||
|| "0".to_string(),
|
||||
|p| format!("{}px {}px {}px {}px", p[0], p[1], p[2], p[3]),
|
||||
);
|
||||
let style = format!("--plugin-gap:{gap}px;--plugin-padding:{padding_css};");
|
||||
let style =
|
||||
format!("--plugin-gap:{gap}px;--plugin-padding:{padding_css};");
|
||||
rsx! {
|
||||
div {
|
||||
class: "plugin-container",
|
||||
|
|
@ -829,20 +827,18 @@ pub fn render_element(
|
|||
let variant_class = button_variant_class(variant);
|
||||
let action_ref = action.clone();
|
||||
let page_actions = actions.clone();
|
||||
let success_msg: Option<String> = match action {
|
||||
ActionRef::Special(_) => None,
|
||||
ActionRef::Name(name) => {
|
||||
actions.get(name).and_then(|a| a.success_message.clone())
|
||||
},
|
||||
ActionRef::Inline(a) => a.success_message.clone(),
|
||||
};
|
||||
let error_msg: Option<String> = match action {
|
||||
ActionRef::Special(_) => None,
|
||||
ActionRef::Name(name) => {
|
||||
actions.get(name).and_then(|a| a.error_message.clone())
|
||||
},
|
||||
ActionRef::Inline(a) => a.error_message.clone(),
|
||||
};
|
||||
let (success_msg, error_msg): (Option<String>, Option<String>) =
|
||||
match action {
|
||||
ActionRef::Special(_) => (None, None),
|
||||
ActionRef::Name(name) => {
|
||||
actions.get(name).map_or((None, None), |a| {
|
||||
(a.success_message.clone(), a.error_message.clone())
|
||||
})
|
||||
},
|
||||
ActionRef::Inline(a) => {
|
||||
(a.success_message.clone(), a.error_message.clone())
|
||||
},
|
||||
};
|
||||
let data_snapshot = build_ctx(data, &ctx.local_state.read());
|
||||
rsx! {
|
||||
button {
|
||||
|
|
@ -904,20 +900,18 @@ pub fn render_element(
|
|||
} => {
|
||||
let action_ref = submit_action.clone();
|
||||
let page_actions = actions.clone();
|
||||
let success_msg: Option<String> = match submit_action {
|
||||
ActionRef::Special(_) => None,
|
||||
ActionRef::Name(name) => {
|
||||
actions.get(name).and_then(|a| a.success_message.clone())
|
||||
},
|
||||
ActionRef::Inline(a) => a.success_message.clone(),
|
||||
};
|
||||
let error_msg: Option<String> = match submit_action {
|
||||
ActionRef::Special(_) => None,
|
||||
ActionRef::Name(name) => {
|
||||
actions.get(name).and_then(|a| a.error_message.clone())
|
||||
},
|
||||
ActionRef::Inline(a) => a.error_message.clone(),
|
||||
};
|
||||
let (success_msg, error_msg): (Option<String>, Option<String>) =
|
||||
match submit_action {
|
||||
ActionRef::Special(_) => (None, None),
|
||||
ActionRef::Name(name) => {
|
||||
actions.get(name).map_or((None, None), |a| {
|
||||
(a.success_message.clone(), a.error_message.clone())
|
||||
})
|
||||
},
|
||||
ActionRef::Inline(a) => {
|
||||
(a.success_message.clone(), a.error_message.clone())
|
||||
},
|
||||
};
|
||||
let data_snapshot = build_ctx(data, &ctx.local_state.read());
|
||||
rsx! {
|
||||
form {
|
||||
|
|
@ -1096,8 +1090,6 @@ pub fn render_element(
|
|||
} => {
|
||||
let chart_class = chart_type_class(chart_type);
|
||||
let chart_data = data.get(source_key).cloned();
|
||||
let x_label = x_axis_label.as_deref().unwrap_or("").to_string();
|
||||
let y_label = y_axis_label.as_deref().unwrap_or("").to_string();
|
||||
rsx! {
|
||||
div {
|
||||
class: "plugin-chart {chart_class}",
|
||||
|
|
@ -1111,7 +1103,7 @@ pub fn render_element(
|
|||
if let Some(x) = x_axis_label { div { class: "chart-x-label", "{x}" } }
|
||||
if let Some(y) = y_axis_label { div { class: "chart-y-label", "{y}" } }
|
||||
div { class: "chart-data-table",
|
||||
{ render_chart_data(chart_data.as_ref(), &x_label, &y_label) }
|
||||
{ render_chart_data(chart_data.as_ref(), x_axis_label.as_deref().unwrap_or(""), y_axis_label.as_deref().unwrap_or("")) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue