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