edc_web_components/pages/
show_policy_page.rs1use crate::components::ShowPolicy;
2use crate::contexts::use_edc_connector_context;
3use patternfly_yew::prelude::*;
4use yew::prelude::*;
5use yew::suspense::use_future_with;
6
7#[derive(Clone, Debug, PartialEq, Properties)]
8pub struct ShowPolicyPageProps {
9 #[prop_or("Policy".to_string())]
10 pub title: String,
11 #[prop_or(None)]
12 pub tag_line: Option<String>,
13 pub policy_id: String,
14}
15
16#[component]
17pub fn ShowPolicyPage(props: &ShowPolicyPageProps) -> Html {
18 let tag_line = props
19 .tag_line
20 .as_ref()
21 .map(|tag_line| html!(<p>{ tag_line }</p>))
22 .unwrap_or_default();
23
24 html!(
25 <>
26 <Title level={Level::H2} size={Size::XXXLarge}>{ &props.title }</Title>
27 { tag_line }
28 <Suspense fallback={html! {<Bullseye><Spinner /></Bullseye>}}>
29 <ShowPolicyPageInner policy_id={props.policy_id.clone()} />
30 </Suspense>
31 </>
32 )
33}
34
35#[component]
36pub fn ShowPolicyPageInner(props: &ShowPolicyPageProps) -> HtmlResult {
37 let edc_connector_client = use_edc_connector_context();
38
39 let policy = use_future_with(
40 (props.policy_id.clone(), edc_connector_client.clone()),
41 |properties| async move {
42 let (policy_id, edc_connector_client) = (*properties).clone();
43
44 if let Some(client) = edc_connector_client.get_client() {
45 client
46 .policies(edc_connector_client::EdcConnectorApiVersion::V4)
47 .get(&policy_id)
48 .await
49 .ok()
50 } else {
51 None
52 }
53 },
54 )?;
55
56 let policy = (*policy).clone();
57
58 if let Some(policy) = policy {
59 Ok(html!(
60 <ShowPolicy
61 policy={policy.policy().clone()}
62 name={policy.private_property::<String>("name").ok().flatten()}
63 />
64 ))
65 } else {
66 Ok(html!(
67 format!(
68 "Policy with id {} not found.",
69 props.policy_id
70 )
71 ))
72 }
73}