edc_web_components/components/
show_policy.rs1mod policy_properties;
2
3use crate::components::Identifier;
4use edc_connector_client::types::policy::{Policy, PolicyKind};
5use patternfly_yew::prelude::*;
6pub use policy_properties::PolicyProperties;
7use yew::prelude::*;
8
9#[derive(Clone, Debug, PartialEq, Properties)]
10pub struct ShowPolicyProps {
11 pub policy: Policy,
12 #[prop_or_default]
13 pub name: Option<String>,
14 #[prop_or_default]
15 pub hide_kind: bool,
16 #[prop_or_default]
17 pub hide_id: bool,
18 #[prop_or_default]
19 pub hide_name: bool,
20 #[prop_or_default]
21 pub hide_profiles: bool,
22 #[prop_or_default]
23 pub hide_extensible_properties: bool,
24}
25
26#[component]
27pub fn ShowPolicy(props: &ShowPolicyProps) -> Html {
28 let id = if !props.hide_id
29 && let Some(id) = props.policy.id()
30 {
31 html!(
32 <DescriptionGroup term="Id">
33 <Identifier id={id.to_string()} />
34 </DescriptionGroup>
35 )
36 } else {
37 html!()
38 };
39
40 let name = if !props.hide_name
41 && let Some(value) = &props.name
42 {
43 html!(<DescriptionGroup term="Name">{ value.to_string() }</DescriptionGroup>)
44 } else {
45 html!()
46 };
47
48 let kind = if props.hide_kind {
49 html!()
50 } else {
51 let kind = match props.policy.kind() {
52 PolicyKind::Set => "Set",
53 PolicyKind::Offer => "Offer",
54 PolicyKind::Agreement => "Agreement",
55 };
56
57 html!(<DescriptionGroup term="Kind">{ kind }</DescriptionGroup>)
58 };
59
60 html!(
61 <DescriptionList mode={[DescriptionListMode::Horizontal]}>
62 { id }
63 { name }
64 { kind }
65 <PolicyProperties
66 permissions={props.policy.permissions().to_vec()}
67 obligations={props.policy.obligations().to_vec()}
68 prohibitions={props.policy.prohibitions().to_vec()}
69 extensible_properties={props.policy.extensible_properties().clone()}
70 assigner={props.policy.assigner().cloned()}
71 assignee={props.policy.assignee().cloned()}
72 />
73 </DescriptionList>
74 )
75}