edc_web_ui/pages/
contract_negotiation_page.rs1use crate::components::{CreateContractNegotiation, ListContractNegotiations};
2use crate::contexts::use_edc_connector_context;
3use crate::models::ContractNegotiationItem;
4use edc_connector_client::types::query::Query;
5use patternfly_yew::prelude::*;
6use yew::prelude::*;
7use yew::suspense::use_future_with;
8
9#[component]
10pub fn ContractNegotiationPage() -> Html {
11 let refresh = use_state(|| 0usize);
12 let backdropper = use_backdrop();
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 let on_create = use_callback(
33 (backdropper.clone(), refresh.clone()),
34 |_, (backdropper, refresh)| {
35 if let Some(backdropper) = backdropper {
36 backdropper.close();
37 }
38
39 refresh.set(**refresh + 1);
40 },
41 );
42
43 let onclick = use_callback((backdropper, on_create), |_, (backdropper, on_create)| {
44 if let Some(backdropper) = backdropper {
45 backdropper.open(html!(
46 <Bullseye>
47 <Modal variant={ModalVariant::Medium} title="Create an Contract Negotiation">
48 <CreateContractNegotiation {on_create} />
49 </Modal>
50 </Bullseye>
51 ))
52 }
53 });
54
55 html!(
56 <Stack gutter=true>
57 <StackItem>
58 <Split gutter=true>
59 <SplitItem fill=true>
60 <Title level={Level::H3} size={Size::XXLarge}>{ "List Contract Negotiations" }</Title>
61 </SplitItem>
62 <SplitItem>
63 <Button icon={Icon::Plus} {onclick} variant={ButtonVariant::Primary}>{ "Add" }</Button>
64 </SplitItem>
65 </Split>
66 </StackItem>
67 <StackItem>
68 <Card>
69 <CardBody>
70 <Suspense>
71 <ContractNegotiationPageInner
72 offset={*offset}
73 limit={*limit}
74 {onoffset}
75 {onlimit}
76 force_refresh={*refresh}
77 />
78 </Suspense>
79 </CardBody>
80 </Card>
81 </StackItem>
82 </Stack>
83 )
84}
85
86#[derive(Clone, Debug, PartialEq, Properties)]
87pub struct ContractNegotiationPageInnerProps {
88 pub offset: usize,
89 pub limit: usize,
90 pub onoffset: Callback<usize>,
91 pub onlimit: Callback<usize>,
92 pub force_refresh: usize,
93}
94
95#[component]
96pub fn ContractNegotiationPageInner(props: &ContractNegotiationPageInnerProps) -> HtmlResult {
97 let edc_connector_context = use_edc_connector_context();
98
99 let contract_negotiation_items = use_future_with(
100 (
101 edc_connector_context,
102 props.limit,
103 props.offset,
104 props.force_refresh,
105 ),
106 |parameters| async move {
107 let (edc_connector_context, limit, offset, _) = (*parameters).clone();
108
109 let query = Query::builder()
110 .limit(limit as u32)
111 .offset(offset as u32)
112 .build();
113
114 if let Some(client) = edc_connector_context.get_client() {
115 client
116 .contract_negotiations()
117 .query(query)
118 .await
119 .unwrap_or_default()
120 .into_iter()
121 .map(ContractNegotiationItem::from)
122 .collect()
123 } else {
124 vec![]
125 }
126 },
127 )?;
128
129 let contract_negotiation_items = (*contract_negotiation_items).clone();
130
131 Ok(html!(
132 <ListContractNegotiations
133 contract_negotiation_items={contract_negotiation_items}
134 offset={props.offset}
135 limit={props.limit}
136 onoffset={props.onoffset.clone()}
137 onlimit={props.onlimit.clone()}
138 />
139 ))
140}