edc_web_components/pages/
contract_negotiation_page.rs1use crate::components::ListContractNegotiations;
2use crate::contexts::use_edc_connector_context;
3use crate::models::ContractNegotiationItem;
4use edc_connector_client::EdcConnectorApiVersion;
5use edc_connector_client::types::query::Query;
6use patternfly_yew::prelude::*;
7use yew::prelude::*;
8use yew::suspense::use_future_with;
9
10#[component]
11pub fn ContractNegotiationPage() -> Html {
12 let refresh = use_state(|| 0usize);
13 let offset = use_state(|| 0usize);
14 let limit = use_state(|| 10usize);
15
16 let onoffset = use_callback(
17 (refresh.clone(), offset.setter()),
18 |offset, (refresh, offset_setter)| {
19 offset_setter.set(offset);
20 refresh.set(**refresh + 1);
21 },
22 );
23
24 let onlimit = use_callback(
25 (refresh.clone(), limit.setter()),
26 |limit, (refresh, limit_setter)| {
27 limit_setter.set(limit);
28 refresh.set(**refresh + 1);
29 },
30 );
31
32 html!(
33 <Stack gutter=true>
34 <StackItem>
35 <Split gutter=true>
36 <SplitItem fill=true>
37 <Title level={Level::H3} size={Size::XXLarge}>{ "List Contract Negotiations" }</Title>
38 </SplitItem>
39 </Split>
40 </StackItem>
41 <StackItem>
42 <Suspense>
43 <ContractNegotiationPageInner
44 offset={*offset}
45 limit={*limit}
46 {onoffset}
47 {onlimit}
48 force_refresh={*refresh}
49 />
50 </Suspense>
51 </StackItem>
52 </Stack>
53 )
54}
55
56#[derive(Clone, Debug, PartialEq, Properties)]
57pub struct ContractNegotiationPageInnerProps {
58 pub offset: usize,
59 pub limit: usize,
60 pub onoffset: Callback<usize>,
61 pub onlimit: Callback<usize>,
62 pub force_refresh: usize,
63}
64
65#[component]
66pub fn ContractNegotiationPageInner(props: &ContractNegotiationPageInnerProps) -> HtmlResult {
67 let edc_connector_context = use_edc_connector_context();
68
69 let contract_negotiation_items = use_future_with(
70 (
71 edc_connector_context,
72 props.limit,
73 props.offset,
74 props.force_refresh,
75 ),
76 |parameters| async move {
77 let (edc_connector_context, limit, offset, _) = (*parameters).clone();
78
79 let query = Query::builder()
80 .limit(limit as u32)
81 .offset(offset as u32)
82 .build();
83
84 if let Some(client) = edc_connector_context.get_client() {
85 client
86 .contract_negotiations(EdcConnectorApiVersion::V4)
87 .query(query)
88 .await
89 .unwrap_or_default()
90 .into_iter()
91 .map(ContractNegotiationItem::from)
92 .collect()
93 } else {
94 vec![]
95 }
96 },
97 )?;
98
99 let contract_negotiation_items = (*contract_negotiation_items).clone();
100
101 Ok(html!(
102 <ListContractNegotiations
103 contract_negotiation_items={contract_negotiation_items}
104 offset={props.offset}
105 limit={props.limit}
106 onoffset={props.onoffset.clone()}
107 onlimit={props.onlimit.clone()}
108 />
109 ))
110}