edc_web_components/pages/
show_contract_negotiation.rs1use crate::components::ContractNegotiationStatus;
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 ShowContractNegotiationPageProps {
9 pub contract_negotiation_id: String,
10 #[prop_or_default]
11 pub on_contract_agreement_click: Callback<String>,
12}
13
14#[component]
15pub fn ShowContractNegotiationPage(props: &ShowContractNegotiationPageProps) -> Html {
16 html!(
17 <>
18 <Title level={Level::H2} size={Size::XXXLarge}>{ "Contract Negotiation" }</Title>
19 <Suspense fallback="Loading ...">
20 <ShowContractNegotiationPageInner
21 contract_negotiation_id={props.contract_negotiation_id.clone()}
22 on_contract_agreement_click={props.on_contract_agreement_click.clone()}
23 />
24 </Suspense>
25 </>
26 )
27}
28
29#[component]
30pub fn ShowContractNegotiationPageInner(props: &ShowContractNegotiationPageProps) -> HtmlResult {
31 let edc_connector_client = use_edc_connector_context();
32
33 let refresh = use_state(|| 0usize);
34
35 let contract_negotiation = use_future_with(
36 (
37 props.contract_negotiation_id.clone(),
38 edc_connector_client.clone(),
39 refresh.clone(),
40 ),
41 |properties| async move {
42 let (contract_negotiation_id, edc_connector_client, _) = (*properties).clone();
43
44 if let Some(client) = edc_connector_client.get_client() {
45 client
46 .contract_negotiations(edc_connector_client::EdcConnectorApiVersion::V4)
47 .get(&contract_negotiation_id)
48 .await
49 .ok()
50 } else {
51 None
52 }
53 },
54 )?;
55
56 let on_finalized = use_callback(refresh.setter(), |_, refresh_setter| {
57 refresh_setter.set(1);
58 });
59
60 let contract_negotiation = (*contract_negotiation).clone();
61
62 if let Some(contract_negotiation) = contract_negotiation {
63 let contract_agreement =
64 if let Some(contract_agreement_id) = contract_negotiation.contract_agreement_id() {
65 let onclick = {
66 let contract_agreement_id = contract_agreement_id.clone();
67
68 props
69 .on_contract_agreement_click
70 .reform(move |_| contract_agreement_id.clone())
71 };
72
73 html!(
74 <Button variant={ButtonVariant::InlineLink} {onclick}>{ contract_agreement_id }</Button>
75 )
76 } else {
77 html!()
78 };
79
80 Ok(html!(
81 <Stack gutter=true>
82 <StackItem>
83 <DescriptionList mode={[DescriptionListMode::Horizontal]}>
84 <DescriptionGroup term="Id">{ contract_negotiation.id() }</DescriptionGroup>
85 <DescriptionGroup term="Contract Agreement Id">{ contract_agreement }</DescriptionGroup>
86 <DescriptionGroup term="Counter Party ID">
87 { contract_negotiation.counter_party_id().clone().unwrap_or_default() }
88 </DescriptionGroup>
89 </DescriptionList>
90 </StackItem>
91 <StackItem>
92 <ContractNegotiationStatus
93 contract_negotiation_id={props.contract_negotiation_id.clone()}
94 {on_finalized}
95 />
96 </StackItem>
97 </Stack>
98 ))
99 } else {
100 Ok(html!(
101 format!(
102 "Contract Negotiation with id {} not found.",
103 props.contract_negotiation_id
104 )
105 ))
106 }
107}