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 pub policy_id: String,
10}
11
12#[component]
13pub fn ShowPolicyPage(props: &ShowPolicyPageProps) -> Html {
14 html!(
15 <>
16 <Title level={Level::H2} size={Size::XXXLarge}>{ "Policy" }</Title>
17 <Suspense fallback="Loading ...">
18 <ShowPolicyPageInner policy_id={props.policy_id.clone()} />
19 </Suspense>
20 </>
21 )
22}
23
24#[component]
25pub fn ShowPolicyPageInner(props: &ShowPolicyPageProps) -> HtmlResult {
26 let edc_connector_client = use_edc_connector_context();
27
28 let policy = use_future_with(
29 (props.policy_id.clone(), edc_connector_client.clone()),
30 |properties| async move {
31 let (policy_id, edc_connector_client) = (*properties).clone();
32
33 if let Some(client) = edc_connector_client.get_client() {
34 client
35 .policies(edc_connector_client::EdcConnectorApiVersion::V4)
36 .get(&policy_id)
37 .await
38 .ok()
39 } else {
40 None
41 }
42 },
43 )?;
44
45 let policy = (*policy).clone();
46
47 if let Some(policy) = policy {
48 Ok(html!(
49 <ShowPolicy
50 policy={policy.policy().clone()}
51 name={policy.private_property::<String>("name").ok().flatten()}
52 />
53 ))
54 } else {
55 Ok(html!(
56 format!(
57 "Policy with id {} not found.",
58 props.policy_id
59 )
60 ))
61 }
62}